Namespaces support

OpenFaaS has support for multiple-namespaces.

Multiple namespaces can be used for the following use-cases:

  • multi-tenancy (when combined with NetworkPolicy)
  • multiple stages or environments within a single cluster - i.e. dev/staging/prod
  • logical segregation of stacks within a single company or team

Additional configuration required

You must configure OpenFaaS to have sufficient permissions to administrate multiple namespaces, this feature will not work in a default installation.

Pre-reqs

  • Kubernetes
  • faas-netes for the faas-provider (default)

Configure OpenFaaS with additional permissions

This is only implemented for faas-netes at present, the default Kubernetes provider.

Additional RBAC permissions are required to work with namespaces, using a ClusterRole is currently supported for multiple namespaces.

  1. arkade install openfaas --clusterrole

Or via helm, set this override:

  1. --set clusterRole=true

If you cannot use a ClusterRole for any reason, then feel free to ask us about OpenFaaS PRO which includes a separate configuration suitable for enterprise companies.

Create one or more additional namespaces

Each additional function namespace must be annotated, kube-system is black-listed and not available at this time.

  1. kubectl create namespace staging-fn
  2. kubectl annotate namespace/staging-fn openfaas="1"
  3. kubectl create namespace dev
  4. kubectl annotate namespace/dev openfaas="1"

Now you can use faas-cli or the API to list namespaces:

  1. # faas-cli namespaces
  2. Namespaces:
  3. - dev
  4. - staging-fn
  5. - openfaas-fn

Deploy some functions:

  1. # faas-cli store deploy nodeinfo --namespace dev
  2. # faas-cli store deploy nodeinfo --namespace staging-fn
  3. # faas-cli store deploy figlet

The URL will be as follows: http://gateway:port/function/NAME.NAMESPACE

Use a YAML file:

stack.yml

  1. provider:
  2. name: openfaas
  3. functions:
  4. stronghash:
  5. namespace: dev
  6. skip_build: true
  7. image: functions/alpine:latest
  8. fprocess: "sha512sum"

Deploy the stack.yml and invoke the function:

  1. faas-cli deploy
  2. head -c 16 /dev/urandom | faas-cli invoke --namespace dev stronghash

Override the namespace configured in the stack.yml when deploying the function and test:

  1. faas-cli deploy --namespace staging-fn
  2. head -c 16 /dev/urandom | faas-cli invoke --namespace staging-fn stronghash