Servicemanagement in Netzen - Leischner

Praktikumsblatt 9 - Serverless Computing (part 1) by Yasodhara Modupalli

In this internship sheet, we will learn about Serverless computing on Kubernetes using OpenFaaS.

 

Prerequisites:

  1. OpenFaaS requires a Kubernetes cluster to operate. We can use single-node cluster or multi-node cluster, whether that’s on laptop or in the cloud. Here, we use Minikube that is already installed in local or in VM.
  2. Kubectl (v1.22.3) is a Kubernetes command-line tool used to run commands against Kubernetes cluster. Use command kubectl version to verify installation.

 

Task 1 – Create account in DockerHub and Install Faas-cli

  1. The basic primitive of any OpenFaaS function is a Docker image. Create an account in DockerHub, so that the functions can be built and pushed as images into docker registry (OpenFaaS has inbuild support for DockerHub).  These images can be deployed as functions into OpenFaas using faas-cli.
  2.  We will use the faas-cli to scaffold new functions, build, deploy, and invoke functions. Find the commands to install faas-cli  (version v0.13.15) in the  link.
  3. Test the faas-cli installation. Open a Terminal or Git Bash window and type: faas-cli version .   
  4. You can find out commands available for the cli with faas-cli help.

 

Task 2 – Installation of OpenFaaS

  1. Start minikube. How do you check the status of your minikube?
  2. Openfaas can be installed using one of the three ways mentioned below:
    • Using Arkade: arkade installs OpenFaaS using its official helm chart. First you need to install arkade then use command arkade install openfaas to install OpenFaaS.
    • From Helm: We can deploy OpenFaaS from the helm chart repo faas-netes.
    • Clone faas-netes repository from github and go into the root folder of faas-netes.
      Then run the commands kubectl apply -f namespaces.yml and kubectl apply -f ./yaml/ .
  3. To verify the installation, list the namespaces in the cluster. Which command do you use? What are the new namespaces that you see?
  4. You can also list all the resources (pods, services, deployments & replicasets) in openfaas namespace. What command do you use for that?
    Hint: By default, all OpenFaaS services and functions are deployed to the openfaas and openfaas-fn namespaces in the Kubernetes cluster.

 

Task 3 - setup OpenFaaS UI

  1. To launch OpenFaaS UI, we need log into OpenFaaS gateway. For that we would need to:
    • set OPENFAAS_URL,
    • generate a random password,
    • check that OpenFaaS gateway is ready.   
  2. Set OPENFAAS_URL with command (port number is your choice): export OPENFAAS_URL=http://127.0.0.1:31112
  3. Generate password using the command and save it for login:
    PASSWORD=$(head -c 12 /dev/urandom | shasum | cut -d' ' -f1)
  4. Enable basic authentication for the gateway using the command:
    kubectl -n openfaas create secret generic basic-auth \
     --from-literal=basic-auth-user=admin \
     --from-literal=basic-auth-password="$PASSWORD"
  5. Forward the port for the Openfaas gateway using command:
    kubectl port-forward svc/gateway -n openfaas 31112:8080
    This command will open a tunnel from your Kubernetes cluster to your local computer so that you can access the OpenFaaS gateway.
  6. Check the gateway is ready using command:
    kubectl rollout status -n openfaas deploy/gateway
    What is the result of this command?
  7.  Access the OpenFaaS UI in any browser with the url: http://127.0.0.1:31112
    Use username admin and retrieve password from the command:
     echo "OpenFaaS password: $PASSWORD"
    Note:
    1. Edit ~/.bashrc or ~/.bash_profile  or ~/.zprofile and export OPENFAAS_URL and PASSWORD to store them permanently as environment variables. Create the file if it does not exist. 
    2. use ctrl+c to close the connection to gateway url.
    3. You can run export URL and port forward commands to access OpenFaaS UI when you restart minikube later.

 

Impressum | Datenschutz | leischner.inf.h-brs.de, last modification: 13.12.2021-19.54