Kubernetes: From Fear to Functions in 20 Minutes
Kubernetes. I tell ya…it’s all the rage.
I’ve been super nervous to try K8s — mostly because of the unknown steps I’d have to take and the many new terms and ideas surrounding it.
TL;DR: You can view all of my steps below in a GitHub gist here.
I decided to start with the OpenFaaS documentation to see what it had to say. If you follow this guide and something doesn’t seem quite right, check the docs first.
First off, I needed a cluster.
A what? A K8s cluster is essentially one “cluster master” with multiple worker machines called nodes; the Kubernetes objects that represent your containerized applications all run on top of a cluster (info from here).
I heard recently that you can run Kubernetes with Docker for Desktop if you run the Edge version. I like to live dangerously (not really) so I decided to switch. You can download it from here (scroll down some).
After that was downloaded and installed, I was ready for step two.
I installed Helm on my MacBook with this:
$ brew install kubernetes-helm
Then I created RBAC permissions for Tiller (Tiller runs inside of your Kubernetes cluster and manages releases or installations of your charts):
$ kubectl -n kube-system create sa tiller \
&& kubectl create clusterrolebinding tiller \
--clusterrole cluster-admin \
And finally I installed the server-side Tiller component:
$ helm init --skip-refresh --upgrade --service-account tiller
Now it was time to deploy OpenFaaS via Helm!
After navigating to the OpenFaaS Helm README, I needed to create two namespaces: “one for the OpenFaaS core services and one for the functions”:
$ kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
You can view the contents of that file to see what it’s doing. Some quick Googling will help you understand the format and contents.
I added the OpenFaaS Helm chart:
$ helm repo add openfaas https://openfaas.github.io/faas-netes/
And deployed OpenFaaS from the
helm chart repo:
$ helm upgrade openfaas --install openfaas/openfaas \
--namespace openfaas \
Well, that was fun! But now what?
Having been a long-time OpenFaaS user, I knew that I needed to navigate to
http://localhost:8080/ui/ to see the beautiful web-based front-end, but that didn’t work. The OpenFaaS documentation says that the “API Gateway/UI” is located on port 31112 for Kubernetes. I typed
http://localhost:31112/ui/ into my browser and voila — the OpenFaaS UI I’m used to! Feel free to deploy some sample functions (I’m fond of the
OpenFaaS Text-to-Speech function myself ;)).