Setting up OpenFaaS on Linux with KinD

Avishka Shamendra
3 min readSep 5, 2022

--

For the past few days I was searching for a good guide on how to set up and work with OpenFaaS on Linux. I could not find any complete guide and I thought of writing this to help the community.

This is a step by step guide on how to set up OpenFaaS on Linux.

Prerequisite

You should have DOCKER installed on your machine. That’s it.

We can start now!

arkade Installation

“arkade” is a tool to install and deploy apps and services to Kubernetes. One can think of this as a package manager like “npm”.

To install “arkade” run:

$ curl -sLS https://dl.get-arkade.dev | sudo sh

kubectl Installation

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters.

$ arkade get kubectl

Follow the instructions given in the terminal to complete the installation.

The aim is to deploy our serverless functions on a local Kubernetes cluster so let’s set that up. We will be using a tool called KinD(Kubernetes in Docker) for this.

KinD Installation

To install KinD run:

$ curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.15.0/kind-linux-amd64
$ chmod +x ./kind
$ sudo mv ./kind /usr/local/bin/kind

KinD provides a shell script to create a Kubernetes cluster along with local Docker registry enabled. Save the following shell script on your device as kind-with-registry.sh

Then we have to make the file an executable

$ chmod +x kind-with-registry.sh

Now let’s run the executable

$ ./kind-with-registry.sh

Let’s make sure the kubectl context is set to the newly created cluster; run:

$ kubectl config current-context

If the result is not “kind-kind” then run:

$ kubectl config use kind-kind

Check whether your cluster and Docker registry is up and running

$ kubectl cluster-info
$ docker logs -f kind-registry

Deploying OpenFaaS to KinD cluster

Let’s use arkade to install OpenFaaS

$ arkade install openfaas

After 2,3 minutes check whether OpenFaaS is deployed.

$ kubectl get pods -n openfaas

To install the faas-cli run:

$ curl -SLsf https://cli.openfaas.com | sudo sh

To forward the FaaS gateway to your machine

$ kubectl rollout status -n openfaas deploy/gateway
$ kubectl port-forward -n openfaas svc/gateway 8080:8080 &

Let’s now setup the basic auth so you can log into your gateway

$ PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)
$ echo -n $PASSWORD | faas-cli login --username admin --password-stdin

The output of the following command is your gateway password.Save it in a secure place

$ echo $PASSWORD

Let’s deploy a dummy function and see if every thing works fine

$ faas-cli store deploy figlet
$ faas-cli list

You should see that “figlet” is now deployed.

Also, now you should be able to go to the OpenFaaS portal from your browser. (http://localhost:8080/ui/).

Username : admin | Password : {saved password}

That’s it. In the next article let’s see how we can write and deploy functions. Make sure you clap if you liked it.

References

[1] OpenFaaS documentation (https://docs.openfaas.com/cli/install/)

[2] Deploy your Serverless Python function locally with OpenFaas in Kubernetes (https://yankee.dev/serverless-function-openfaas-kubernetes-locally)

[3] KinD Quick Start Guide (https://kind.sigs.k8s.io/docs/user/quick-start/#installation)

--

--

Avishka Shamendra
Avishka Shamendra

Written by Avishka Shamendra

Computer Science and Engineering Graduate from University of Moratuwa, Sri Lanka