Difficulty: Introduction
Estimated Time: 20 minutes

OpenFaaS on Kubernetes

(This draft tutorial is under construction. Contact me for questions: [email protected] November 2, 2018)

OpenFaaS

OpenFaaS is a framework for building serverless functions with Docker and Kubernetes which has first class support for metrics. Any process can be packaged as a function enabling you to consume a range of web events without repetitive boiler-plate coding.

You will learn how:

  • to install OpenFaaS on Kubernetes
  • functions are deployed and removed
  • functions are named, exposed, and invoked
  • functions are listed, inspected and monitored

More about the OpenFaaS architecture is described in the OpenFaaS documentation.

Conclusion

OpenFaaS is a Kubernetes...

Lessons Learned

With these scenarios you have learned how:

  • to install OpenFaaS on Kubernetes
  • functions are deployed and removed
  • functions are named, exposed, and invoked
  • functions are listed, inspected and monitored

References

Don’t stop now! The next scenario will only take about 10 minutes to complete.

OpenFaaS

Step 1 of 5

Install OpenFaaS

As you see, your Kubernetes cluster based on Minikube is started now or will be available shortly. Verify it's ready for your use:

minikube version && minikube status

Preparation

First, create two namespaces, one for the OpenFaaS core services openfaas and a second for the functions openfaas-fn.

kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

Then generate a Kubernetes secret for basic authentication for the gateway

kubectl -n openfaas create secret generic basic-auth --from-literal=basic-auth-user=user --from-literal=basic-auth-password=$(cat user-password.txt)

Install OpenFaaS Operator

Helm is a package manager for Kubernetes and is initialized and ready.

helm version

A common Helm chart is predefined for installing OpenFaaS. Normally, popular charts appear in the curated Helm chart repository and there are plans to move OpenFaaS there. For now, this repo add command will allow Helm to find the OpenFaaS chart:

helm repo add openfaas https://openfaas.github.io/faas-netes/

Install the OpenFaaS operator

helm upgrade openfaas --install openfaas/openfaas --namespace openfaas --set basic_auth=true --set functionNamespace=openfaas-fn --set operator.create=true --set rbac=false

Watch the 5 deployments for OpenFaaS become Available. The Available status column turns from 0 to 1 once each deployment has initialized.

kubectl --namespace=openfaas get deployments -l "release=openfaas, app=openfaas"

OpenFaaS CLI

Finally, install the OpenFaaS command-line interface (CLI) tool.

curl -sSL https://cli.openfaas.com | sh

Verify it is installed

faas-cli version

At this point there is a OpenFaaS gateway providing access to both the portal and REST API to manage the functions and OpenFaaS. Most of the CLI commands from this point going forward require this gateway as a parameter. (It's an inconvenience when using the CLI, but perhaps there is a security concern why this cannot be a sticky setting.). To reduce the verbosity the gateway can be stored as an environment variable. If you were running Minikube locally, the command would be

GW=$(minikube service gateway-external --namespace openfaas --url)

But on Katacoda, because of the server virtualization the gateway is here

GW=https://[[HOST_SUBDOMAIN]]-31112-[[KATACODA_HOST]].environments.katacoda.com/

With the gateway access, the first action is to login

cat user-password.txt | faas-cli login --username user --password-stdin --gateway=$GW

OpenFaaS Portal

You can also explore the OpenFaaS functions in the portal. On the right there is a tab called OpenFaaS Portal or from this link: https://[[HOST_SUBDOMAIN]]-31112-[[KATACODA_HOST]].environments.katacoda.com/

When prompted, use the same user name and password that was applied above in the secret creation (user/user). For visibility and understanding, leave this tab open for the subsequent steps.

Terminal
Kubernetes Dashboard
OpenFaaS Portal
Prometheus Portal