Welcome back to our on-going series about hands-on with serverless, hope you are enjoying it! For our post today we will explore another interesting FaaS runtime engine: Kubeless.

So let’s get started!

Same as with other FaaS engines first you will need to install its own CLI. For example with OSX:

export OS=$(uname -s| tr '[:upper:]' '[:lower:]')
curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip && \
unzip kubeless_$OS-amd64.zip && \
sudo mv bundles/kubeless_$OS-amd64/kubeless /usr/local/bin/

Now you need to create a new namespace that will be used specifically for Kubeless:

kubectl create ns kubeless

And finally deploy the latest Kubeless release in the new namespace:

export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d '"' -f 4)
kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yaml

Check the deployment is 0k with:

$ kubectl get deployment -n kubeless
kubeless-controller-manager 1/1 1 1 4m51s

Kubeless is now fully deployed in your k8s cluster… that was easy!

Let’s now create our first function, for example using python. Create a file called test.py and include this simple content:

def hello(event, context):
print event
return event['data']

As you can see it is a very simple program that returns the same data it receives.

Let’s deploy a new function running that code with the following command:

kubeless function deploy hello --runtime python2.7 \
--from-file test.py \
--handler test.hello

Wait until it shows up as READY:

$ kubeless function ls hello
hello default test.hello python2.7 1/1 READY

Your function is now deployed on Kubeless!

You can see the pod running in the default namespace:

$ kubectl get pods
hello-55f6478db6-d72fz 1/1 Running 0 4m49s

One big difference with Kubeless is that during the installation process it creates a new Custom Resource Definition (CRD) native to k8s, so that functions can be managed like standard k8s objects:

$ kubectl get functions
hello 9m25s

OK, let’s see if our new function works, running:

$ kubeless function call hello --data 'Hello world'
Hello world

Nice, it works fine!

For our Kubeless deployment we did not configure any externally accessible IP address via a LoadBalancer service, so we will test HTTP access using kubectl proxy from our workstation:

kubectl proxy -p 8080 &
curl -L --data 'Hi there!' \

Fantastic, our function is now readily available for everyone to access it. Well done!

See you in my next post to continue exploring other serverless engines you can run on kubernetes, stay tuned!

Any questions or comments please let me know in the comments section below, Twitter or LinkedIn.

Related resources:

We’d love to hear what you think. Ask a question or leave a comment below.
And stay connected with Cisco DevNet on social!

Twitter @CiscoDevNet | Facebook | LinkedIn

Visit the new Developer Video Channel