Using OpenFaaS on AKS

OpenFaaS is a framework for building serverless functions through the use of containers. As an open source project, it has gained large-scale adoption within the community. This document details installing and using OpenFaas on an Azure Kubernetes Service (AKS) cluster.


In order to complete the steps within this article, you need the following.

  • Basic understanding of Kubernetes.
  • An Azure Kubernetes Service (AKS) cluster and AKS credentials configured on your development system.
  • Azure CLI installed on your development system.
  • Git command-line tools installed on your system.

Add the OpenFaaS helm chart repo

Go to to open Azure Cloud Shell in your browser.

OpenFaaS maintains its own helm charts to keep up to date with all the latest changes.

helm repo add openfaas
helm repo update

Deploy OpenFaaS

As a good practice, OpenFaaS and OpenFaaS functions should be stored in their own Kubernetes namespace.

Create a namespace for the OpenFaaS system and functions:

kubectl apply -f

Generate a password for the OpenFaaS UI Portal and REST API:

# generate a random password
PASSWORD=$(head -c 12 /dev/urandom | shasum| cut -d' ' -f1)

kubectl -n openfaas create secret generic basic-auth \
--from-literal=basic-auth-user=admin \

You can get the value of the secret with echo $PASSWORD.

The password we create here will be used by the helm chart to enable basic authentication on the OpenFaaS Gateway, which is exposed to the Internet through a cloud LoadBalancer.

A Helm chart for OpenFaaS is included in the cloned repository. Use this chart to deploy OpenFaaS into your AKS cluster.

helm upgrade openfaas --install openfaas/openfaas \
    --namespace openfaas  \
    --set basic_auth=true \
    --set functionNamespace=openfaas-fn \
    --set serviceType=LoadBalancer


NAME:   openfaas
LAST DEPLOYED: Wed Feb 28 08:26:11 2018
NAMESPACE: openfaas

==> v1/ConfigMap
NAME                 DATA  AGE
prometheus-config    2     20s
alertmanager-config  1     20s


To verify that openfaas has started, run:

kubectl --namespace=openfaas get deployments -l "release=openfaas, app=openfaas"

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 minute for the IP address to be assigned to the service.

kubectl get service -l component=gateway --namespace openfaas


NAME               TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)          AGE
gateway            ClusterIP   <none>         8080/TCP         7m
gateway-external   LoadBalancer   8080:30800/TCP   7m

To test the OpenFaaS system, browse to the external IP address on port 8080, in this example. You will be prompted to log in. The default user is admin and your password can be retrieved by using echo $PASSWORD.

OpenFaaS UI

Finally, install the OpenFaaS CLI. This example used brew, see the OpenFaaS CLI documentation for more options.

brew install faas-cli

Set $OPENFAAS_URL to the public IP found above.

Log in with the Azure CLI:

echo -n $PASSWORD | ./faas-cli login -g $OPENFAAS_URL -u admin --password-stdin

Create first function

Now that OpenFaaS is operational, create a function using the OpenFaas portal.

Click on Deploy New Function and search for Figlet. Select the Figlet function, and click Deploy.

Screenshot shows the Deploy A New Function dialog box with the text figlet on the search line.

Use curl to invoke the function. Replace the IP address in the following example with that of your OpenFaas gateway.

curl -X POST -d "Hello Azure"


 _   _      _ _            _
| | | | ___| | | ___      / \    _____   _ _ __ ___
| |_| |/ _ \ | |/ _ \    / _ \  |_  / | | | '__/ _ \
|  _  |  __/ | | (_) |  / ___ \  / /| |_| | | |  __/
|_| |_|\___|_|_|\___/  /_/   \_\/___|\__,_|_|  \___|

Create second function

Now create a second function. This example will be deployed using the OpenFaaS CLI and includes a custom container image and retrieving data from an Azure Cosmos DB instance. Several items need to be configured before creating the function.

First, create a new resource group for the Azure Cosmos DB instance.

az group create --name serverless-backing --location eastus

Deploy an Azure Cosmos DB instance of kind MongoDB. The instance needs a unique name, update openfaas-cosmos to something unique to your environment.

az cosmosdb create --resource-group serverless-backing --name openfaas-cosmos --kind MongoDB

Get the Azure Cosmos DB database connection string and store it in a variable.

Update the value for the --resource-group argument to the name of your resource group, and the --name argument to the name of your Azure Cosmos DB instance.

COSMOS=$(az cosmosdb list-connection-strings \
  --resource-group serverless-backing \
  --name openfaas-cosmos \
  --query connectionStrings[0].connectionString \
  --output tsv)

Now populate the Azure Cosmos DB with test data. Create a file named plans.json and copy in the following json.

    "name" : "two_person",
    "friendlyName" : "Two Person Plan",
    "portionSize" : "1-2 Person",
    "mealsPerWeek" : "3 Unique meals per week",
    "price" : 72,
    "description" : "Our basic plan, delivering 3 meals per week, which will feed 1-2 people.",
    "__v" : 0

Use the mongoimport tool to load the Azure Cosmos DB instance with data.

If needed, install the MongoDB tools. The following example installs these tools using brew, see the MongoDB documentation for other options.

brew install mongodb

Load the data into the database.

mongoimport --uri=$COSMOS -c plans < plans.json


2018-02-19T14:42:14.313+0000    connected to: localhost
2018-02-19T14:42:14.918+0000    imported 1 document

Run the following command to create the function. Update the value of the -g argument with your OpenFaaS gateway address.

faas-cli deploy -g --image=shanepeckham/openfaascosmos --name=cosmos-query --env=NODE_ENV=$COSMOS

Once deployed, you should see your newly created OpenFaaS endpoint for the function.

Deployed. 202 Accepted.

Test the function using curl. Update the IP address with the OpenFaaS gateway address.

curl -s


[{"ID":"","Name":"two_person","FriendlyName":"","PortionSize":"","MealsPerWeek":"","Price":72,"Description":"Our basic plan, delivering 3 meals per week, which will feed 1-2 people."}]

You can also test the function within the OpenFaaS UI.

alt text

Next Steps

You can continue to learn with the OpenFaaS workshop through a set of hands-on labs that cover topics such as how to create your own GitHub bot, consuming secrets, viewing metrics, and auto-scaling.