OpenFaaS

On this page 7

OpenFaaS is an open-source framework for running functions as a service on Kubernetes, packaging each function as a standard container image and exposing it through a central gateway. In serverless computing, it lets an organization operate its own function platform on any cloud or on premises instead of relying on a provider-managed service such as AWS Lambda or Azure Functions.

The project, originally named Functions as a Service, focuses on portability and developer simplicity. A developer writes a handler, builds it with a template into an OCI container image, and deploys it with one command; the platform then handles routing, scaling, metrics and asynchronous invocation.

How OpenFaaS runs functions on Kubernetes

OpenFaaS consists of a small set of components that sit on top of a Kubernetes cluster. The OpenFaaS gateway receives every HTTP request, the faas-netes provider translates function deployments into Kubernetes Deployments and Services, and Prometheus collects request metrics that drive scaling decisions.

Inside each function container runs the watchdog, a tiny process that acts as the container’s entry point. The classic watchdog forks a new process for every request and passes data over standard input and output, while the newer of-watchdog keeps a long-running process and proxies HTTP, which avoids per-request startup cost and allows connection pooling.

The following table summarizes the main components and their roles.

ComponentRoleNotes
GatewayRoutes calls and exposes the REST APIAlso serves the web UI
faas-netesManages functions as Kubernetes objectsfaasd replaces it on a single host
WatchdogBridges HTTP and the handler processClassic or of-watchdog mode
PrometheusStores invocation metricsFeeds alerting and autoscaling
NATS queue workerProcesses asynchronous requestsSupports retries and callbacks
faas-cliBuilds, pushes and deploys functionsUses a stack.yaml file
Core OpenFaaS components

Invocation modes, triggers and scaling

OpenFaaS supports synchronous and asynchronous invocation. A synchronous call through /function/name waits for the result, whereas a call through /async-function/name returns HTTP 202 Accepted immediately and places the request on a NATS-based queue, optionally posting the result to a callback URL.

Beyond HTTP, connectors act as function triggers by subscribing to external event sources and invoking functions mapped by annotation. Common connectors cover Kafka, cron schedules, MQTT and cloud message queues; several of them are available only in the commercial editions.

Scaling relies on replica counts adjusted by metrics. The table below compares the scaling approaches that teams typically use.

MechanismSignalTypical use
Built-in autoscalerRequests per second, capacity or CPUMost HTTP functions
Kubernetes HPACPU or memory utilizationCompute-heavy workloads
Scale to zeroIdle period without callsRarely used functions
Fixed minimum replicasConfigured floorLatency-sensitive endpoints
Scaling options for OpenFaaS functions

Scale to zero saves cluster resources but introduces a cold start when the first request arrives. Because a pod must be scheduled and the container started, that delay usually ranges from under one second to several seconds, depending on image size and node capacity.

OpenFaaS compared with other serverless platforms

OpenFaaS belongs to the group of self-hosted serverless platforms, which trade operational effort for control and portability. The comparison below places it next to managed and open-source alternatives.

PlatformHosting modelUnit of deploymentKey difference
OpenFaaSSelf-hosted on Kubernetes or faasdContainer imageSimple gateway and templates
KnativeSelf-hosted on KubernetesContainer imageRicher eventing, heavier install
AWS LambdaFully managedZip package or imageNo cluster to operate
Google Cloud RunFully managedContainer imagePay per request time
Azure FunctionsManaged or self-hostedCode package or imageDeep Azure integration
OpenFaaS and related platforms

The main advantage is avoiding vendor lock-in: the same function image runs on a laptop, in a private data center or on any managed Kubernetes service. The main cost is that the team, not a provider, operates the cluster, patches it and pays for idle nodes.

Editions, templates and practical deployment

OpenFaaS is distributed in a Community Edition for evaluation and smaller use, and in commercial Standard and Enterprise editions that add features such as advanced autoscaling, more connectors, single sign-on, multiple namespaces and support. License terms of the Community Edition have tightened over time, so teams should check the current license before production use.

Developers start from language templates for Python, Node.js, Go, Java and others, or provide any Dockerfile. The faas-cli up command builds the image, pushes it to a registry and deploys it in one step, and secrets are mounted from Kubernetes Secrets rather than environment variables.

For edge or very small installations, faasd runs OpenFaaS on a single virtual machine with containerd instead of Kubernetes. It suits low-cost appliances and labs but lacks multi-node high availability.

Limitations and common mistakes

Most problems with OpenFaaS stem from treating it as a fully managed service. The following table lists frequent issues and their remedies.

SymptomCauseRemedy
Slow first responseFunction scaled to zeroKeep one minimum replica for critical paths
Requests time out at the gatewayTimeouts not aligned across layersMatch gateway, watchdog and ingress timeout values
Large images start slowlyHeavy base imagesUse slim bases and multi-stage builds
Lost asynchronous workQueue worker restarts without retriesConfigure retries and persistent streams
High cluster costOver-provisioned nodes for idle functionsUse a cluster autoscaler
Common OpenFaaS issues

Functions should also remain stateless and idempotent. Any replica may handle any request, and the queue may deliver a retried message twice, so durable data belongs in an external database or object store rather than on the container file system.

The idea in brief

Many cloud providers let programmers upload a small piece of code, a function, and run it only when needed. OpenFaaS offers the same convenience on hardware a company controls.

It works like a reception desk for small programs. Requests arrive at the desk, which sends each one to the right function, starts more copies when traffic rises and shuts them down when it is quiet. The company keeps freedom to move between clouds, but it must also look after the building.

A practical scenario

A logistics company runs a private Kubernetes cluster in its own data center because shipment data must stay on premises. Its developers need to resize scanned delivery receipts and extract barcodes whenever a driver uploads a photo.

The team deploys two OpenFaaS functions written from the Python template. Uploads trigger asynchronous invocations through the queue, so the mobile app receives an immediate HTTP 202 response. The autoscaler grows each function from one to twelve replicas during the evening peak, when about 30 photos arrive per second, and returns to one replica overnight.

The result is processing within roughly three seconds per receipt at peak, no data leaving the company network and the option to move the same container images to a managed cloud cluster later without code changes.