OpenFaaS and Kubernetes

Recently there has been a lot of news about OpenFaaS and I wanted to try it out. As the rest of my tests have been done on Kubernetes, I looked more closely to the FaaS-Netes.

Everything here was done on a local minikube deployment and using my test Docker registry deployed on a server in the local network.


The first deployment was really easy. Once minikube is operational, it’s only two commands to deploy everything needed : git clone and then kubectl apply -f ./faas.yml,monitoring.yml,rbac.yml.

You can check on the status of everything either through the Kubernetes dashboard (using minikube dashboard if you don’t know the IP) or using the OpenFaaS dashboard (through the port 31112).

The second part is to get the OpenFaaS-cli tools that allows easy function deployment. As I’m not a huge fan of the curl -sSL ... | sudo sh install method, I downloaded manually the executable from the release page and added it the PATH.

Use of a private Docker registry

Before this, I always deployed my stuff by hand of the Kubernetes cluster and thus had no problems with the authentication using the imagePullSecrets in the yaml deployment file. This time as OpenFaaS deploys containers as needed, I had to configure the nodes to authenticate automatically. Fortunately, it was this easy :

  • Create the secret

    $ kubectl create secret docker-registry myregistrykey \
    --docker-server=registry.local \
    --docker-username=user \
    --docker-password=pass \
    --docker-email none@registry.local
  • Modify the service account to add imagePullSecrets to every image pull

    $ kubectl patch serviceaccount default \
    -p '{"imagePullSecrets": [{"name": "myregistrykey"}]}'
  • It works.

First test

I the followed the Your first serverless Python function with OpenFaaS blog post by the creator of the system. First creating a new directory for this function and adding the basic content needed for an Hello World

$ mkdir -p ~/functions/hello-python
$ cd ~/functions
$ cat > hello-python/ <<EOF
def handle(req):  
    print("Hello! You said: " + req)
$ cat > stack.yml <<EOF
  name: faas

    lang: python
    handler: ./hello-python/
    image: registry.local/faas-hello-python:1.0

This makes the basic structure for a function. All in all, it’s really easy: One file contains the function that will be called, the other contains the description of the deployment.

The to deploy our function, three commands will do everything needed

$ faas-cli -action build -f ./stack.yml
$ faas-cli -action push -f ./stack.yml
$ faas-cli -action deploy -f ./stack.yml

And bam, everything is deployed and ready to recieve requests

curl -d test

I think that I will play for a long time with this now ..