Create your FREE Codefresh account and start making pipelines fast. Create Account

Deploying OpenFaaS on Kubernetes Using Codefresh

5 min read

OpenFaas is a framework for building Serverless functions on top of containers. If you want to take advantage of the new functions and programming style, but still benefit from the robustness of containers for shipping and managing your code in production, then OpenFass combines the best of these 2 worlds. OpenFass is available on GitHub: .

In this blog post, we will explore using OpenFaaS together with Codefresh. Codefresh has native integration with Kubernetes, and is the best way to continuously deploy code to Kubernetes.


Before we begin, let’s make sure you are set up with the basics:

Setup OpenFaaS on Kubernetes

Follow the documentation to install.

We can view the Kubernetes resources right in Codefresh under the Kubernetes tab on your Codefresh home page. Codefresh provides an aggregative Kubernetes dashboard that shows Kubernetes entities in a user-friendly, service-oriented way. In this view, you can see that everything is successfully created and is in a healthy state. You can see I’ve deployed using the two namespace model using Helm.


Next, let’s go the the OpenFaaS dashboard: navigate to the node where the API Gateway is deployed, and access the UI with the port defined in the service. The default port is 31112. At this point you should clone the faas-cli and deploy the sample functions, so people can at least try one function after all the investment so far.

Building with Codefresh

Next, let’s create our function. There are many ways to accomplish this, but all you need to do is create a Docker container that can respond to a REST call. For this tutorial, we created a very simple Python script that accepts a string as a payload and returns a sentence along with that string. This is then deployed in a Docker container.

There is a command line tool used by the OpenFaaS community to build functions into Docker containers. To use this tool, follow the instructions here. This is the method we used for this guide.

At this stage you should have created a GitHub repository, with a Dockerfile and function folder. The repo we will use in this guide is located here for your reference: .

Add your Function to Codefresh

Once you’ve uploaded your repository to GitHub:

  1. Go to Codefresh (, and select Create Build.
  2. Select the repository that contains your function code and continue.
  3. The repo I used for this process is called “sample-func”.
  4. Select your repository, and click “NEXT.”
  5. We already have a Dockerfile in our repo so we’ll use that Dockerfile to run our build in Codefresh.
  6. After selecting the Dockerfile-based build, Codefresh will show you the execution command it will use to build your container. For this example, we need to set the build context to the “hello-python” folder, and the image name to our sample image. Because we are using the internal Codefresh registry, our image name must use the following format: <username>/<image>:<tag>.
  7. The next step allows us to review the Dockerfile, accept that, and select “Create” to finalize your pipeline.
  8. Selecting Build will immediately build this image, you can go ahead and do so.

Deploying with Codefresh

Link Codefresh Registry

Before we get to the Codefresh deployment, there is one other link we must make between our Kubernetes cluster and our Codefresh platform. To do that, perform the following steps:

We need to give Kubernetes access to our internal Codefresh registry. We can do that by first creating access credentials from within our dashboard.

Follow the instructions here to generate an API token, then use the following kubectl command to create a docker-registry secret within your Kubernetes cluster.

kubectl create secret docker-registry regsecret \ \
--docker-username=<codefresh-user> \
--docker-password=<api-token> \

Run this command where you previously installed the kubectl binary.

Replace the codefresh-user , api-token , and codefresh-email  with your own values.

Remember what you name this secret, we’ll need it in the configuration of our deployment file.

Deployment file

The ultimate goal of this pipeline is to build and deploy a service to Kubernetes, that makes available a function in OpenFaaS.

A YAML file called deployment.yml  is contained within this repo. This file contains the Kubernetes spec needed to create the function within our cluster. I’ve posted it below.

Note: Pay close attention to the labels on the objects; they tell the OpenFaaS framework to register this service as an available function. The “imagePullSecret” is the value from the previous step. It allows any Pods created here to access our private Codefresh registry and pull the image. This image is named with the same name we gave it in the Build step in Codefresh.

kind: Deployment
apiVersion: extensions/v1beta1
metadata: null
name: hello-python
namespace: default
labels: null
faas_function: hello-python
spec: null
replicas: 1
selector: null
matchLabels: null
template: null
    name: hello-python
    containerPort: 8080
protocol: TCP
    name: fprocess
value: 'python'
imagePullPolicy: IfNotPresent
    name: regsecret
restartPolicy: Always

Deployment Step

To configure your build pipeline to deploy to your Kubernetes cluster, follow the steps below:

  1. Navigate to your repositories in Codefresh and select your function repository.
  2. Choose the first header option, Pipelines.
  3. Scroll down to the Deploy Script section, and choose Kubernetes.
  4. Select your cluster from the drop-down and fill in the required values.
  5. Select Kubernetes Deployment File in Repository, and enter the name of the deployment file to be used. In our case, it is simply deployment.yml .
  6. Scroll down, save the changes, and build.
  7. You’ll be able to see the build running on the Builds tab. Follow along if you’d like. You can walk through the steps it takes to build our container according to the Dockerfile, push to its internal repo, then deploy to the linked Kubernetes cluster using the deployment.yml  file.
  8. Once that’s finished, there’s one last step to take. We need to expose the service we’ve created in order for OpenFaaS to expose it as a function. This last step is performed by a simple kubectl  command:
kubectl expose deployment hello-python

Once that is run, take a look at the list of services in your Kubernetes cluster, you’ll see your deployed function.

If you navigate to your OpenFaaS dashboard, you should be able to see and interact with your function.


And that’s it! We learned how to easily deploy OpenFaaS on Kubernetes, and then how to deploy new functions to your OpenFaaS instance using Codefresh. Phew! Normally this would take a lot of work, but Codefresh makes this entire process very easy.

New to Codefresh? Create Your Free Account Today!

Dan Garfield

Dan is the Co-Founder and Chief Open Source Officer at Codefresh. His work in open source includes being an Argo Maintainer, and co-chair of the GitOps Working Group. As a technology leader with a background in full-stack engineering, evangelism, and communications, he led Codefresh's go-to-market strategy and now leads open source strategy. You can follow him at