For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt, and this page is available as Markdown at https://docs.us.ovhcloud.com/en/public-cloud/managed-kubernetes/install-openfaas.md.
  • English

How to install OpenFaaS CE on OVHcloud Managed Kubernetes using OpenFaaS

View as Markdown

The following guide details an OpenFaas installation on an OVHcloud Managed Kubernetes Service (MKS) cluster. OpenFaaS is a framework for building serverless functions on top of Kubernetes. Before installing OpenFaaS Community Edition (CE), make sure you read the end-user license agreement (EULA), to understand the limits of this version of OpenFaaS vs the Standard and Enterprise edition.

 

Before you begin

This tutorial presupposes that you already have a working OVHcloud Managed Kubernetes cluster and some basic knowledge of operating it. If you want to know more on those topics, please look at the deploying a Hello World application documentation.

You also need to have Helm installed on your workstation and your cluster, please refer to the How to install Helm on OVHcloud Managed Kubernetes Service tutorial.

 

OpenFaaS, a Kubernetes-native FaaS platform

PaaS serverless open faas - step 1

OpenFaaS is an open-source framework for building Serverless functions with Docker and Kubernetes.

More details about the OpenFaaS architecture can be found in the official documentation.

 

Instructions

Deploying OpenFaaS on OVHcloud Managed Kubernetes

The official Helm chart for OpenFaas is available on the faas-netes repository. The following section describes how to install it on your OVHcloud Manage Kubernetes cluster.

 

Load the OpenFaaS helm chart repository

The OpenFaaS Helm chart isn’t available in Helm’s standard stable repository. You need to add their repository to your Helm install:

helm repo add openfaas https://openfaas.github.io/faas-netes/ helm repo update

 

Create the required namespaces

OpenFaaS guidelines advise to create two namespaces, one for OpenFaaS core services and one for the functions:

kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

 

Generate credentials

To secure access to the OpenFaaS UI Portal and REST API, you can generate a password using the following commands:

# 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 \
--from-literal=basic-auth-password="$PASSWORD"
Info

You will need this password later in the tutorial, for example, to access the UI portal. You can see it at any moment in the terminal session by doing echo $PASSWORD.

 

Deploying the Helm chart

The Helm chart can be deployed in three modes: LoadBalancer, NodePort, and Ingress. For us the simplest way is simply using our external Load Balancer, so we will deploy it in LoadBalancer by setting the --set serviceType=LoadBalancer option.

Info

If you want to understand the difference between these three modes better, you can read our dedicated guide.

Deploy the Helm chart:

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

As suggested in the install message, you can verify that OpenFaaS has started by running:

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

If it’s working you should see the list of OpenFaaS deployment objects, marked as available:

$ kubectl --namespace=openfaas get deployments -l "release=openfaas, app=openfaas"
NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
alertmanager   1         1         1            1           33s
faas-idler     1         1         1            1           33s
gateway        1         1         1            1           33s
nats           1         1         1            1           33s
prometheus     1         1         1            1           33s
queue-worker   1         1         1            1           33s

 

Connect to the Gateway

Get the public IP of your gateway service using:

kubectl get svc -n openfaas gateway-external -o wide
Warning

NOTE: At this moment, your EXTERNAL-IP could be still PENDING.

$ kubectl get svc -n openfaas gateway-external -o wide NAME TYPE
    CLUSTER-IP EXTERNAL-IP PORT(S) AGE gateway-external LoadBalancer x.x.x.x
    PENDING 8080:30012/TCP 10s

The provisioning of the load balancer can take several minutes. Check again until the EXTERNAL-IP is filled with a public IP address.

Once the public IP address is available, you may access the OpenFaaS UI at http://PUBLIC_IP:8080.

PaaS serverless open faas - step 2

 

Connect using the CLI

Another way to interact with your new OpenFaaS platform is by installing faas-cli, the command line client for OpenFaaS (on a Linux or Mac, or in a WSL Linux terminal in Windows). Download the latest version of the CLI client from the official release page.

You can now use the CLI to log into the gateway. The CLI needs the public IP address of the OpenFaaS LoadBalancer, you can get it using the commands from the previous section:

PASSWORD=$(kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode)
echo -n $PASSWORD | ./faas-cli login -g http://EXTERNAL_IP:8080 -u admin --password-stdin

Sample output:

Calling the OpenFaaS server to validate the credentials...
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
credentials saved for admin http://EXTERNAL_IP:8080

Now you're connected to the gateway, and you can send commands to the OpenFaaS platform.

By default, there is no function installed on your OpenFaaS platform, as you can verify with the faas-cli list command.

./faas-cli list -g http://EXTERNAL_IP:8080

This section focused on how to install OpenFaaS. The next section will introduce how to import and invoke functions.

 

Deploying and invoking functions

You can easily deploy functions on your OpenFaaS platform using the web UI, or the CLI:

Some sample functions are available in the official OpenFaaS project. For example, to import figlet, a function that generates ASCII art banners from plain text:

./faas-cli deploy -g http://EXTERNAL_IP:8080 --name figlet --image ghcr.io/openfaas/figlet:latest

faas-cli list command now will show the deployed functions:

$ ./faas-cli list
Function                        Invocations     Replicas
figlet                          1               1

Let's invoke the newly imported functions:

echo 'Hello from OVH MKS' | ./faas-cli invoke -g http://EXTERNAL_IP:8080 figlet

This section detailed how to import and use existing functions. The next section will introduce how to create custom functions.

 

Writing our first function

Prerequisites

To publish and deploy a function to your MKS cluster, you will need:

  • A public container registry accessible from your MKS cluster and your workstation, such as dockerhub or GitHub registry.
Warning

NOTE: At the moment, OpenFaaS Community Edition only supports public images. Check the related documentation for private registries with OpenFaaS Pro.

 

Code the function

All available templates are available in the official template repository, or can be listed using:

./faas-cli template store list

This example will use NodeJS to create a hello world function. Let's begin by creating and scaffolding the function folder:

mkdir hello-js-project
cd hello-js-project
../faas-cli new hello-js --lang node20 -g http://EXTERNAL_IP:8080

The CLI will download a JS function template from the OpenFaaS repository, generate a function description file (hello-js.yml in our case) and a folder for the function source code (hello-js). For NodeJS, you will find a package.json (for example to declare dependencies to your function) and a handler.js (the function main code) in this folder.

In hello-js.yml, set the following parameters according to your configuration:

  • provider.gateway: the URL to your OpenFaaS gateway.
  • functions.image: the URL to your docker registry. In this example, a dockerhub repository will be used.

hello-js.yml

version: 1.0
provider:
  name: openfaas
  gateway: http://xxxxx657xx.lb.c1.gra.k8s.ovh.net:8080
functions:
  hello-js:
    lang: node
    handler: ./hello-js
    image: docker.io/openfaas/hello-js:latest # The URL to a public repository.

The function described in hello-js/handler.js is simple. It exports a function with two parameters, a context where you will receive the request data, and a callback that you will call at the end of your function and where you will pass the response data.

Now you can build the Docker image and push it to the public Docker registry:

# Build the image
../faas-cli build -f hello-js.yml
# Login at Docker Registry, needed to push the image
docker login
# Push the image to the registry
../faas-cli push -f hello-js.yml

With the image in the registry, let's deploy and invoke the function with the OpenFaaS CLI:

# Deploy the function
../faas-cli deploy -f hello-js.yml
# Invoke the function
../faas-cli -g http://EXTERNAL_IP:8080 invoke hello-js
# Enter your input, and press Ctrl+D
Hello
# Response:
{"body":"\"Hello\\n\"","content-type":"text/plain"}

Congratulations, you have written and deployed your first OpenFaaS function using Node. See the official documentation to go further.

 

Where do we go from here?

To learn more about OpenFaaS, please refer to the official OpenFaaS documentation. You can also follow the OpenFaaS workshops to learn in a more practical way.

 

Go further

Browse all the Managed Kubernetes Service (MKS) guides.

Browse the rest of the OVHcloud US documentation for guides on our other products and services.

Learn more about Managed Kubernetes on the OVHcloud US website.

If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.