Deploy your OpenFAAS functions to production

January 1, 2021

This is a way to expose your gateway to your local machine to deploy cloud functions. There are much better ways to do this including GitOps, but this is the quick and simple way to get things done if you need it.

setting OPENFAAS_URL

set your production endpoint

export OPENFAAS_URL=gateway-external.openfaas.svc.cluster.local:8080

if you are doing local development, you can do this:

export OPENFAAS_URL=localhost:31112

port forward the production gateway

On a separate shell, expose the gateway:

kubectl port-forward -n openfaas svc/gateway-external 8080:8080

build your functions

faas build -f stack.prod.yml 

If you are building with tokens and private npm modules:

faas build -f stack.prod.yml --build-arg NPM_TOKEN=<redacted> 

If all goes well, push and deploy!

faas push -f stack.prod.yml 

which really just does this:

docker push docker.yourdomain.com/username/yourimage:latest

logging in

Before you deploy, make sure you have authenticated with OpenFAAS. If you have, skip to the next section.

PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)

USER=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-user}" | base64 --decode; echo)

echo -n $PASSWORD | faas-cli login --username $USER --password-stdin

deploying the functions

faas remove -f stack.prod.yml 
faas deploy -f stack.prod.yml 

testing the function

you can test the function hello-openfaas or whatever the name is by using the gateway URL:

http://gateway-external.openfaas.svc.cluster.local:8080/function/hello-openfaas

Caveat, however, you may need to update your /etc/hosts file for this to work

127.0.0.1 gateway-external.openfaas.svc.cluster.local

Profile

Written by Dan Lynch an inventor and entrepreneur who loves the web —  follow him on twitter or github