Update: see this note: https://gist.github.com/alexellis/3b285ca0952d4cef48ca5dbff7e4e288#gistcomment-3169271
You can already install the OpenFaaS control-plane multiple times to create segregated environments.
Today, we're introducing a new option - single control-plane, multiple namespaces.
There are pros/cons to both solutions and it's still on you to decide what fits best.
Test it out with these instructions:
-
Get Kubernetes with kind, k3s, k3d, or minikube
https://github.com/kubernetes-sigs/kind
https://github.com/rancher/k3d
https://kubernetes.io/docs/setup/learning-environment/minikube/
-
kubectl -n kube-system create sa tiller \ && kubectl create clusterrolebinding tiller \ --clusterrole cluster-admin \ --serviceaccount=kube-system:tiller helm init --skip-refresh --upgrade --service-account tiller
-
Install OpenFaaS with helm
echo Installing with helm 👑 helm repo add openfaas https://openfaas.github.io/faas-netes/ kubectl apply -f \ https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml # generate a random password PASSWORD=$(head -c 12 /dev/urandom | shasum| cut -d' ' -f1) kubectl -n openfaas create secret generic basic-auth \ --from-literal=basic-auth-user=admin \ --from-literal=basic-auth-password="$PASSWORD" helm upgrade openfaas --install openfaas/openfaas \ --namespace openfaas \ --set basic_auth=true \ --set functionNamespace=openfaas-fn \ --set clusterRole=true # needed for multiple namespace access
-
Create an alternative namespace
kubectl create ns fn
-
Port-forward
kubectl port-forward -n openfaas svc/prometheus 9090:9090 & kubectl port-forward -n openfaas svc/gateway 8080:8080 &
-
Get the password
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo) export AUTH=http://admin:$PASSWORD@127.0.0.1:8080 echo -n $PASSWORD | faas-cli login --username admin --password-stdin
-
Deploy two functions in two namespaces
# Create function cows in the default namespace faas-cli store deploy cows # openfaas-fn # Create a function nodeinfo in the fn namespace curl -d '{"service":"nodeinfo","namespace":"fn","image":"functions/nodeinfo:latest","labels":{"com.openfaas.scale.min":"2","com.openfaas.scale.max":"5"},"environment":{"output":"verbose","debug":"true"}}' -X POST $AUTH/system/functions
-
View functions deployed:
# View default curl -s $AUTH/system/function/cows | jq curl -s $AUTH/system/function/cows?namespace=openfaas-fn | jq # view "fn" namespace curl -s $AUTH/system/function/nodeinfo?namespace=fn | jq # View all functiions in a namespace curl -s $AUTH/system/functions?namespace=fn | jq curl -s $AUTH/system/functions?namespace=openfaas-fn | jq
-
Invoke both
curl 127.0.0.1:8080/function/cows curl 127.0.0.1:8080/function/cows.openfaas-fn curl 127.0.0.1:8080/function/nodeinfo.fn
-
Scale to zero and back
kubectl scale deploy/nodeinfo -n fn --replicas=0 curl 127.0.0.1:8080/function/nodeinfo.fn
-
Auto-scale
hey -c 5 -z 2m http://127.0.0.1:8080/function/nodeinfo.fn &
Now monitor with the OpenFaaS API:
curl -s $AUTH/system/functions | jq curl -s $AUTH/system/function/nodeinfo?namespace=fn | jq
-
View Prometheus
# View some metrics http://127.0.0.1:9090/graph?g0.range_input=1h&g0.expr=rate(gateway_function_invocation_total%5B1m%5D)&g0.tab=0 # See alerts http://127.0.0.1:9090/alerts
-
Tweet a screenshot
Share your success by tweeting to @openfaas
-
Get in touch if you'd like to help out or chat more
GitHub Issue -> openfaas/faas-netes#511
what is hey here ?
hey -c 5 -z 2m http://127.0.0.1:8080/function/nodeinfo.fn &
I can see the Prometheus from browser.
you should add one uninstall / delete everything tag
which will remove all the namespace and resources.