OpenFaaS is an open-source platform for running functions (FaaS) on top of Kubernetes. It simplifies the deployment of small code units that execute on demand or in response to events.
At its core, OpenFaaS follows the Function as a Service (FaaS) model: you write a function, package it into a Docker image, and OpenFaaS handles scaling, networking, and lifecycle management.
It offers a user-friendly web interface and a command-line tool called faas-cli
. You can write functions in popular languages such as Python, Node.js, Go, and others using pre-built templates.
The complete documentation for OpenFaaS on Kubernetes is available on the official website.
To install OpenFaaS:
ingress
section and enable it by setting enabled: true
. Also, specify your domain in the host
parameter. This will simplify access to the dashboard and allow usage of faas-cli
. If you enable ingress
, you can disable exposeServices
, which is used by default.To verify everything is running, check the status of pods in the openfaas-fn
namespace:
kubectl get pods -n openfaas-fn
Example output:
NAME READY STATUS RESTARTS AGE
alertmanager-57767d864c-hdqdn 1/1 Running 0 19h
gateway-5f9c4b5754-ksr6x 2/2 Running 1 (19h ago) 19h
nats-6ddf479847-dxr2g 1/1 Running 0 19h
prometheus-6cbd946f66-wqdf8 1/1 Running 0 19h
queue-worker-57c7479989-bw282 1/1 Running 0 19h
If all pods are in Running
status, the installation was successful.
To work with OpenFaaS from the terminal, you need the faas-cli
tool. It allows you to create functions, build and push images, deploy them to the cluster, invoke functions, and check their status.
It is available for Linux, macOS, and Windows. Use the following commands to install it:
Linux/macOS
curl -sSL https://cli.openfaas.com | sh
macOS
curl -sSL https://cli.openfaas.com | sh
Or, via Homebrew:
brew install faas-cli
Windows (PowerShell)
$version = (Invoke-WebRequest "https://api.github.com/repos/openfaas/faas-cli/releases/latest" | ConvertFrom-Json)[0].tag_name
(New-Object System.Net.WebClient).DownloadFile("https://github.com/openfaas/faas-cli/releases/download/$version/faas-cli.exe", "faas-cli.exe")
Verify the installation:
faas-cli version
In this example, we will:
Requirements:
faas-cli
and Docker.Go to the control panel and install the OpenFaaS addon. In the Configuration section, enable ingress
by setting enabled: true
and specifying your domain in the host
field. Then start the installation.
Create a loadbalancer.yaml
manifest:
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx-lb
namespace: ingress-nginx
spec:
selector:
app.kubernetes.io/name: ingress-nginx
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: 80
appProtocol: k8s.hostman.com/proto-http
- name: https
port: 443
targetPort: 443
appProtocol: k8s.hostman.com/proto-https
Apply it:
kubectl apply -f loadbalancer.yaml
Set the balancer’s IP as the A record of your domain. If you're using Hostman NS servers, just select the newly created load balancer. Otherwise, get its IP manually:
kubectl get svc --all-namespaces --field-selector spec.type=LoadBalancer
The IP will be under the EXTERNAL-IP
column.
Visit the domain you configured—a basic auth prompt will appear.
Use the login admin
and retrieve the password using:
kubectl -n openfaas-fn get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode
After logging in, the dashboard will open.
Let’s move on to using functions. We’ll install a function from the built-in OpenFaaS store.
First, log in via the CLI. This will allow you to run commands related to function management:
faas-cli login \
--gateway http://<domain> \
--username admin \
--password <password>
Where:
domain
— the address specified during OpenFaaS installation;admin
— the default username;password
— the password can be retrieved with the following command:kubectl -n openfaas-fn get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode
Now install the figlet
function, which converts text into ASCII art:
faas-cli store deploy figlet \
--gateway http://<domain>
Make sure the function has been installed:
faas-cli list \
--gateway http://<domain>
The list will now contain the figlet
function with a status of Ready
.
Invoke the function and pass a string as input:
echo "Hostman" | faas-cli invoke figlet \
--gateway http://<domain>
You’ll receive ASCII art with the given text in response.
Now let’s go over deploying a custom function. Choose a template:
faas-cli template store list
Create a new function based on the desired template—for example, python3-http
:
faas-cli new hello-k8s --lang python3-http
The following will be created:
hello-k8s/handler.py
— the function code;stack.yaml
— the function manifest.Before building, edit the stack.yaml
file and specify the path to your Docker Hub image. For example:
functions:
hello-k8s:
lang: python3-http
handler: ./hello-k8s
image: dockerhubuser/hello-k8s:latest
In the image field, specify your Docker Hub username and the image name. Note that OpenFaaS Community Edition only supports public images.
Build the image:
faas-cli build -f stack.yaml
After the image is built, push it to Docker Hub:
faas-cli push -f stack.yaml
Finally, deploy the function to your cluster:
faas-cli deploy -f stack.yaml \
--gateway http://<domain>
After running the command, you’ll get a link to access the function.
Open the link. You should see the message "Hello from OpenFaaS!".