openfaas (Functions as a Service) is a framework for building serverless functions with Docker and Kubernetes which has first class support for metrics. Any process can be packaged as a function enabling you to consume a range of web events without repetitive boiler-plate coding.
I was impressed that I managed to get this all setup and working in less than 10 minutes (If we forget that AKS took almost 20 minutes to provision!)
In order to complete the steps within this article, you need a basic understanding of Kubernetes & the following.
- An Azure subscription
- A working installation of Kubectl (tutorial here)
- A working installation of Helm (see here)
- Install the openfaas CLI. See the openfaas CLI documentation for options.
- Azure CLI installed on your development system.
- Git command-line tools installed on your system.
Deploy the cluster with the Azure CLI
1) Install the official latest version of Azure CLI
2) Login to your subscription:
Optional: If you have multiple subscriptions linked to your account, remember to select the one on which you want to work. (az account set -s subscription-id)
3) Create the resource group in which you want to deploy the cluster (in the example ghostinthewiresk8sRG is the name of the Resource Group and westeurope is the chosen location):
az group create -l westeurope -n ghostinthewiresk8sRG
4) Finally, create your cluster. This will create a default cluster with one master and three agents (each VM is sized, by default, as a Standard_D2_v2 with 2vCPUs and 7GiB of RAM):
az acs create –orchestrator-type Kubernetes -g ghostinthewiresk8sRG -n k8sCluster -l westeurope –generate-ssh-keys
Optional: you can specify the agent-count, the agent-vm-size and a dns-prefix for your cluster:
–agent-count 2 –agent-vm-size Standard_A1_v2 –dns-prefix k8sghost
5) Get your cluster credentials ready for kubectl:
az acs kubernetes get-credentials -n k8sCluster -g ghostinthewiresk8sRG
1) Check if the kubectl configuration is ok and if your cluster is up-and-running:
Deploy OpenFaaS to the newly created AKS Cluster
Please follow the instructions as per the official docs with Helm. Please ensure you use the basic auth as outlined in the steps.
validate openfaas install
A public IP address is created for accessing the openfaas gateway. To retrieve this IP address, use the kubectl get service command. It may take a few minutes for the IP address to be assigned to the service, until then it will show as pending:
kubectl get service -l component=gateway –namespace openfaas
To test the openfaas system, browse to the external IP address on port 8080,
http://22.214.171.124:8080 in this example:
Create first function
Now that openfaas is operational, you could create a function using the OpenFaaS portal but I will show you how to do it via the CLI.
1) In order to see what Functions are available in the store type:
faas-cli store list
2) We are going to use Figlet to Generate ascii logos through the use of a binary. To install run the following:
faas-cli store deploy figlet –gateway http://126.96.36.199:8080
Use curl to invoke the function. Replace the IP address in the following example with that of your openfaas gateway:
curl -X POST http://188.8.131.52:8080/function/figlet -d “ghostinthewire5”
If you made it this far and now have a working deployment of openfaas on AKS — congratulations! Try out a bunch of functions from the store, or use the openfaas CLI Tool to build your own functions and deploy them.
Hope this was helpful!
I was amazed by how quick I managed to get this simple demo configured. I only have a little experience of Kubernetes and was able to get this working in less than 10 minutes (When you consider AKS took almost double the time to provision), which is awesome considering all the complexity this abstracts away from you.
Another big part of this demo that hasn’t been mentioned is the incredible support I received from the Founder Alex Ellis and the very active OpenFaaS community.