Serverless on Kubernetes

Andrew McIver
5 min readOct 20, 2020

How to run Serverless platform Fission.io on Civo Kubernetes

Civo offers a hosted Kubernetes platform, and they are currently offering a public beta at Kube100.

Fission is “a framework for serverless functions on Kubernetes”. The Fission.io webpage explains it quite well and the documentation is great. I was pleasantly surprised to see OpenShift in the documentation sidebar.

For this guide, you’ll need a kubernetes cluster. I’ll show the quick and painless creation of one using Civo’s Kubernetes platform. You’ll need helm (version 3) and we’ll use Rancher’s Longhorn product for persistent pod storage.

  1. Create the cluster (and install Longhorn)
    We’re adding Longhorn storage at the beginning, leveraging Civo’s catalogue of applications that can be pre-installed.
# civo kubernetes create --size=g2.medium --nodes 3 --applications Longhorn --waitThe cluster polished-citadel (57563e88-4ed1-467c-99e5-51162158338a) has been created in 2 min 12 sec

and once that’s finished, you will be able to get the cluster details. Pay attention to your cluster’s DNS record. You will need that later, each cluster has its own DNS name. The summary also shows that Longhorn has been installed

# civo kubernetes show polished-citadel
ID : 57563e88-4ed1-467c-99e5-51162158338a
Name : polished-citadel
Nodes : 3
Size : g2.medium
Status : ACTIVE
Version : 1.18.6+k3s1
API Endpoint : https://91.211.154.80:6443
Master IP : 91.211.154.80
DNS A record : 57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com
Nodes:
+------------------+----+--------+-----------+-----------+------+----------+
| Name | IP | Status | Size | Cpu Cores | Ram | SSD disk |
+------------------+----+--------+-----------+-----------+------+----------+
| kube-master-c828 | | ACTIVE | g2.medium | 2 | 4096 | 50 |
| kube-node-4b9b | | ACTIVE | g2.medium | 2 | 4096 | 50 |
| kube-node-8050 | | ACTIVE | g2.medium | 2 | 4096 | 50 |
+------------------+----+--------+-----------+-----------+------+-----
Applications:
+----------------+-----------+-----------+--------------+
| Name | Version | Installed | Category |
+----------------+-----------+-----------+--------------+
| metrics-server | (default) | true | architecture |
| Traefik | (default) | true | architecture |
| Longhorn | 1.0.2 | true | storage |
+----------------+-----------+-----------+--------------+

Get and/or set your Kubeconfig information. For a Civo Kubernetes cluster this is done by downloading the Kubeconfig file from the web interface, and then exporting your environment variable for KUBECONFIG pointed at your downloaded file.

Civo Kubernetes Web Interface

or by running:

# civo kubernetes config polished-citadel --save

Once you have that you can check that everything you need is in place by getting a list of all the pods in your cluster:

# kubectl get pods --all-namespaces

The output of that command should show many pods, including Longhorn storage pods.

2. Deploy Fission

Make sure you have the DNS name of your Kubernetes cluster, or an external load-balancer IP address, then open the Fission installation docs

I installed Fission on my cluster using Helm version 3. I recommend doing that so that you can ignore the tiller stuff.

I deployed Fission as shown below. The helm command is a one-liner but it’s wrapped to make it easier to read.

$ export FISSION_NAMESPACE="fission"
$ kubectl create namespace $FISSION_NAMESPACE
$ helm install --namespace $FISSION_NAMESPACE \
--name-template fission \
https://github.com/fission/fission/releases/download/1.11.1/fission-all-1.11.1.tgz

If you were installing on a cluster without a service type of loadBalancer available, then Fission have provided documentation and an alternative Helm chart to make that easy for you as well.

Once the helm tasks have completed you should some new Fission-related namespaces:

# kubectl get namespaces
NAME STATUS AGE
default Active 95m
kube-system Active 95m
kube-public Active 95m
kube-node-lease Active 95m
longhorn-system Active 95m
fission Active 90m
fission-builder Active 89m
fission-function Active 89m

Great, so now Fission is installed on the cluster. Time to install the Fission CLi tool on your local computer. I run Ubuntu Linux, so below is the command I used. Please note: You should never blindly copy-paste curl commands without carefully checking what will be downloaded and executed on your computer. Note also that the final step includes a sudo command which means it is executing in god-mode on your computer.

# curl -Lo fission https://github.com/fission/fission/releases/download/1.11.1/fission-cli-linux \
&& chmod +x fission && sudo mv fission /usr/local/bin/

3. Create a couple of functions

Once again, the Fission documention described exactly what was needed to get a hello world function running. Below I’ll show what was needed for a python function.

Create a file hellopython.py containing this python function:

def main():
return "Hello, world!"

Then create the fission definition:

fission function create --name hellopy --env python --code hello.py

Once that completes you can test the function using the Fission cli. I’ve preceeded it with the time command, so that I can see how long it took to execute.

# time fission function test --name hellopy
Hello, world!
real 0m4.354s
user 0m0.153s
sys 0m0.112s

To make the function reachable outside the Kubernetes cluster itself, it is necessary to publish a request URL path. This is why it was necessary to have the DNS or external load-balancer information about your cluster. On my cluster this was done with either of the following:

export FISSION_ROUTER=91.211.154.80:31067

or

export FISSION_ROUTER=57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com:31067

and then the final step is:

# fission route create --method GET --url /hellopy --name hellopy --function hellopy
trigger 'hellopy' created

This can be tested via curl or by pointing your browser at the load-balancer address. In my case it was http://57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com:31067/hellopy

57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com:31067/hellopy

or

~# curl -v http://57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com:31067/hellopy
* Trying 91.211.154.80:31067...
* TCP_NODELAY set
* Connected to 57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com (91.211.154.80) port 31067 (#0)
> GET /hellopy HTTP/1.1
> Host: 57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com:31067
> User-Agent: curl/7.65.3
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 13
< Content-Type: text/html; charset=utf-8
< Date: Tue, 20 Oct 2020 08:30:02 GMT
<
* Connection #0 to host 57563e88-4ed1-467c-99e5-51162158338a.k8s.civo.com left intact
Hello, world!

Some relevant further reading or links

Below are some additional links that got me to this point, including the technologies used here. The InfoQ article about performance of serverless is worth a read, as well as similar articles documenting the benefits and drawbacks of a serverless platform.

Many thanks to Ruan Bekker for his post on sysadmins.co.za about persisting Jenkins storage on Longhorn.

Thanks to Kai Hoffman for editing assistance.

https://www.infoq.com/articles/serverless-performance-cost/
https://fission.io
https://www.civo.com/?ref=f9b482
https://rancher.com/products/longhorn
https://sysadmins.co.za/persisting-jenkins-data-on-kubernetes-with-longhorn-on-civo/

About me

I’m a Mech Warrior, the Bearded Wolverine at LSDopen.io where we use Open Source solutions to solve real business challenges.
When I’m not talking tech, I enjoy playing guitar and watching GT-class motorsport. Recently I’ve started playing Among Us, I find it helps with impostor syndrome.

--

--

Andrew McIver

I’m a Mech Warrior, the Bearded Wolverine at LSDopen.io where we use Open Source solutions to solve real business challenges.