OpenFaaS on Rancher

I like learning about the serverless stuff and trying it out as well. I’ve came across a OSS called OpenFaaS and it looked quite interesting. An easy to learn architecture and easy to try it out as well. If you haven’t heard of it, you should take a look at this blog post. It’s cool.

OpenFaaS supports Docker Swarm and Kubernetes. As a Rancher user, I can choose both Docker Swarm and Kubernetes, but I like the UI/UX of Cattle the best. Easy to learn and easy to touch. Unfortunately, it isn’t possible to deploy OpenFaaS inside Rancher’s Cattle because OpenFaaS knows nothing about the Cattle orchestrator’s API and cannot coordinate with it. I didn’t want to give up so I started investigating how OpenFaaS’s gateway was coordinating with Kubernetes.

from faas-netes

This was what I found in the faas-netes Github repo. So, the faas-netes container was basically a reverse proxy for the k8s API. And that theoretically means I could replace the k8s API to the Rancher API equivalent.

So that’s what I made.

OpenFaas x Rancher(cattle) Diagram

A faas-rancher container. I published it in the repository below.

https://github.com/kenfdev/faas-rancher

The image is automatically built to docker hub.

https://hub.docker.com/r/kenfdev/faas-rancher/

The source code is extremely inspired by the faas-netes code (some codes are almost intact) and it seems sort of like a duplicate project but for now, it’s a good place to start FaaS with Cattle.

Trying OpenFaaS on Cattle

I’m assuming you already have a Cattle Environment ready. If not, look at my previous post on creating an Cattle Environment.

Create an Environment API Key

First of all, let’s create an Environment API Key in Rancher for the faas-rancher to use. Go to API > Keys > Advanced Options and click theAdd Environment API Key button. Don’t mistake it with Account API Keys if you’re following this post.

Name it whatever you like and Create it:

You’re going to use the Access Key and the Secret Key so keep it somewhere.

Deploying OpenFaaS via the Catalog

Go to the Catalog and findopenfaas .

You should find something like the one below:

Now click the View Details button and let’s fill in the form.

It’s going to look something like the one above. The Functions Stack Name is where the faas services will be created. You can create the stack upfront or the faas-rancher will automtically create it on deploy.

After a few minutes you should see everything green and clean like the following:

And if you click 8080/tcp you should see the UI for OpenFaaS:

Adding and Testing a Function

Now let’s create a new function. Press the CREATE NEW FUNCTION button. Let’s try the sample hubstats function. It returns the requested user’s docker hub stats.

In the UI, the Network is a required field but currently I’m not using it in faas-rancher and there aren’t any client validations moving so the request is POSTed any way (this may change in future releases). OK, let’s CREATE it!

After waiting for a while, you should see hubstats in the side bar. It takes a few moments because the container is being deployed as shown below.

Be patient until you see the service turning green.

Now you should see the function in the sidebar. Let’s try the hubstats function!

And you can confirm it is responding my docker hub stats. Pretty cool isn’t it??

What goes on from here…

How was faas-rancher ? I have so little time to move forward so any contribution and advices are welcome! I’m going to try hard to improve this project!

If you’re interested in OpenFaaS, please show support by giving a Star to the GitHub repo!