Learn OPENFAAS with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
1
Simple OpenFaaS Function
# openfaas/demo/function.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
hello-python:
lang: python3
handler: ./handler
topic: http
image: hello-python:latest
A simple OpenFaaS YAML configuration to deploy a Python HTTP function.
2
OpenFaaS Function with Environment Variables
# openfaas/demo/env.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
env-demo:
lang: python3
handler: ./handler
envVars:
GREETING: "Hello OpenFaaS"
image: env-demo:latest
Deploy a function with custom environment variables.
3
OpenFaaS Function with Labels
# openfaas/demo/labels.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
label-demo:
lang: python3
handler: ./handler
labels:
team: devops
env: staging
image: label-demo:latest
Add metadata labels to an OpenFaaS function.
4
OpenFaaS Function with Annotations
# openfaas/demo/annotations.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
annotation-demo:
lang: python3
handler: ./handler
annotations:
com.openfaas.scale.min: "1"
com.openfaas.scale.max: "5"
image: annotation-demo:latest
Configure OpenFaaS function annotations for monitoring or routing.
5
OpenFaaS Function with Secrets
# openfaas/demo/secrets.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
secret-demo:
lang: python3
handler: ./handler
secrets:
DB_PASSWORD
image: secret-demo:latest
Use OpenFaaS secrets in your function deployment.
6
OpenFaaS Function with Custom Constraints
# openfaas/demo/constraints.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
constraint-demo:
lang: python3
handler: ./handler
constraints:
node.role == worker
image: constraint-demo:latest
Apply deployment constraints to schedule functions on specific nodes.
7
OpenFaaS Function with Multiple Topics
# openfaas/demo/topics.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
topic-demo:
lang: python3
handler: ./handler
topic: topic1,topic2
image: topic-demo:latest
Subscribe a function to multiple topics for event-driven processing.
8
OpenFaaS Function with Resource Limits
# openfaas/demo/resources.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
resource-demo:
lang: python3
handler: ./handler
limits:
memory: "128Mi"
cpu: "500m"
image: resource-demo:latest
Specify CPU and memory limits for an OpenFaaS function.
9
OpenFaaS Function with Auto-scaling
# openfaas/demo/autoscale.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
autoscale-demo:
lang: python3
handler: ./handler
annotations:
com.openfaas.scale.min: "2"
com.openfaas.scale.max: "10"
image: autoscale-demo:latest
Enable OpenFaaS auto-scaling with min/max replicas.
10
OpenFaaS Function with Readiness and Liveness Probes
# openfaas/demo/probes.yml
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
probe-demo:
lang: python3
handler: ./handler
readinessProbe:
httpGet:
path: /health
port: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
image: probe-demo:latest
Configure readiness and liveness probes for OpenFaaS functions.