Recently serverless computing gets more and more attention and popularity. Thanks to this concept you can increase your productivity because it let you focus almost exclusively on implementing business logic and getting, at the same time, all the enterprise-ready scalability and availability. OpenFaaS is a very interesting player here, as it can be easily deployed on execution environments of ANY size, and ANY flavor.
When our customers, those more IT educated, ask us if we could develop for them something serverless-like, our answer is: yes we can, and we can do this in a way not letting you cry when you get billings from your cloud service providers.
Currently, each and every big cloud service provider offers serverless computing services. AWS offers their Lambda and Fargate, Microsoft offers Functions and Container Instances, and Google offers Cloud Functions and Cloud Run. Each of them tempts with unique options, interesting offers, and easy integration with the rest of their monitoring, security, and repositories ecosystem. Let’s not forget, however, that there are no free lunches and that we will have to pay for everything – sooner or later. Once we find out how much all these costs, some will decide to take the path of unlocking-in from the given cloud provider. So you better read this article BEFORE you make decisions.
OpenFaaS is a solution that has been gaining popularity for some time, mainly due to the ease of implementation and the constantly growing support of the community. Today we will show you how easy it can be deployed for testing purposes, even on a single computing node. Of course, it will be on our beloved Ubuntu 😉
First, let us set up a minimal but production-ready Kubernetes implementation – k3s!
curl -sfL https://get.k3s.io | sh -
Let’s check if k3s services are up and running.
sudo systemctl status k3s
In response, you should get something like that:
Now, to be able to interact with our FaaS component, we have to install faas-cli:
curl -sL https://cli.openfaas.com | sudo sh
The easiest option to install OpenFaaS is to use the light K8S package manager – Arkade:
curl -sLS https://dl.get-arkade.dev | sudo sh
Since on my Ubuntu I got the following error:
[Warning] unable to create secret basic-auth, may already exist ... unable to read /etc/rancher/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions ... error loading config file "/etc/rancher/k3s/k3s.yaml" open /etc/rancher/k3s/k3s.yaml: permission denied
… I changed the permission for /etc/rancher/k3s/ks3.yaml to 744 🙂
Then I’ve hit the next problem:
Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version?timeout=32s": dial tcp [::1]:8080: connect: connection refused
.. and found a solution on github:
kubectl config view --raw > ~/.kube/config
Then, you can repeat the installation of OpenFaaS using arkade
again and this time it should be hopefully successful, but the output includes important information which we need to get started with faas-cli
and OpenFaaS
. As we have already install faas-cli
, we will now need to forward the gateway to the machine.
First, we will check the rollout status of the gateway
by issuing the below command:
kubectl rollout status -n openfaas deploy/gateway
After that, we can forward the gateway to the machine:
kubectl port-forward -n openfaas svc/gateway 8080:8080 &
Now, the last step is to discover the password for OpenFaaS UI which we will use to manage OpenFaaS. To do that execute the below command:
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
You can read and store the password securly:
echo $PASSWORD
Now, it is time to open your web browser and type in the address bar: http://localhost:31112
Username
is set to admin
by default and the password is the one which you saved in the above step.
Now by pressing the button “Deploy New Function” you open the gate to the world of experimentation and magic 🙂
You can start safely with the figlet function!