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:
- 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.
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
- 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
.
- 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.
- Test the
faas-cli
installation. Open a
Terminal or Git Bash window and type: faas-cli version
.
- You can find out commands available for the cli with
faas-cli help
.
Task 2 – Installation of OpenFaaS
- Start minikube. How do you check the status of your
minikube?
- 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/
.
- To verify the installation, list the namespaces in the
cluster. Which command do you use? What are the new
namespaces that you see?
- 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
- 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.
- Set
OPENFAAS_URL
with command
(port number is your choice): export
OPENFAAS_URL=http://127.0.0.1:31112
- Generate password using the command
and save it for login:
PASSWORD=$(head -c 12 /dev/urandom | shasum | cut -d' ' -f1)
- 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"
- 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.
- Check the gateway is ready using command:
kubectl rollout status -n openfaas deploy/gateway
What is
the result of this command?
- 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.