OpenWhisk Actions on Managed Knative on IBM Standard Kubernetes Cluster
Doug Davis announced managed Knative on IBM Cloud Kubernetes services in February 2019. He has a blog post (Introducing Managed Knative on IBM Cloud Kubernetes Service) explaining how to enable managed Knative add-on in your Kuberentes cluster. And recently OpenWhisk community started prototyping OpenWhisk runtimes (specifically NodeJS
) so that OpenWhisk actions can be deployed/invoked on Knative. We have a blog post (How to run OpenWhisk Actions on Knative?) demonstrating how-to on Docker for Desktop and minikube. Let’s experiment with IBM Kubernetes service and see how it differs from other enviornments.
Pre-requisites:
- IBM Standard Kubernetes Cluster with version 1.12.7 in Single Zone/Multi Zone with a flavor of 4 Cores 16GB RAM and 3 Worker Nodes. Feel free to go and grab 🥘 while you create your standard cluster 😄.
- IBM Cloud CLI to download the kubeconfig files for your cluster using:
ibmcloud ks cluster-config <cluster-name>
kubectl
configured to access IBM Kubernetes Cluster, verify:
kubectl cluster-info
- Enable Knative add-on (with some ☕️):
ibmcloud ks cluster-addon-enable knative <cluster-name>
- Verify that all pods are
Running
underistio-system
,knative-build
,knative-serving
,knative-eventing
, andknative-monitoring
.
kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEistio-system cluster-local-gateway-6d8585d55d-jmmwn 1/1 Running 0 79s
...
knative-build build-controller-865d99747c-lj9sh 1/1 Running 0 109s
...
knative-eventing eventing-controller-64bf9bbf79-ccq5p 2/2 Running 0 79s
...
knative-monitoring elasticsearch-logging-0 1/1 Running 0 108s
...
knative-serving activator-58fb6bdff4-5tsjh 0/2 PodInitializing 0 78s
...
knative-sources controller-manager-0 1/1 Running 0 106s
Now, let’s follow the six steps process of building and serving OpenWhisk actions on Knative:
Step 1: Register Secrets for Your Container Registry on Knative
Knative needs access to your container registry in order to push locally built container image. I am using Docker Hub here but you can use any registry of your choice by changing the registry name under annotation
.
Save this file as docker-secret.yaml
after replacing DOCKERHUB_USERNAME_BASE64_ENCODED
and DOCKERHUB_PASSWORD_BASE64_ENCODED
with your Docker Hub username/password.
Apply the secret resource manifest for Docker Hub:
$ kubectl apply -f docker-secret.yaml
secret/dockerhub-user-pass created
Verify secret exists:
$ kubectl get secret dockerhub-user-pass
NAME TYPE DATA AGE
dockerhub-user-pass kubernetes.io/basic-auth 2 21s
Step 2: Create Service Account for our Knative Builds
Create a service account to link the build process with the registry secret created in Step 1 so that Knative build system can push container images to the registry using these credentials.
$ kubectl apply -f service-account.yaml
serviceaccount/openwhisk-runtime-builder created
Verify the service account exists:
$ kubectl get serviceaccount/openwhisk-runtime-builder
NAME SECRETS AGE
openwhisk-runtime-builder 2 3m46s
Step 3: Install the Build Template for the NodeJS Runtime
Deploy OpenWhisk Build Template:
$ kubectl apply -f https://raw.githubusercontent.com/apache/incubator-openwhisk-runtime-nodejs/master/core/nodejsActionBase/buildtemplate.yaml
buildtemplate.build.knative.dev/openwhisk-nodejs-runtime created
Verify the Build Template exists:
$ kubectl get buildtemplate openwhisk-nodejs-runtime
NAME AGE
openwhisk-nodejs-runtime 2m
Step 4: Deploy NodeJS Runtime with Hello World Action Code
Configure the build file to point to your Docker Hub repo by replacing DOCKER_USERNAME
with your username.
Deploy NodeJS runtime with action code:
$ kubectl apply -f build.yaml
build.build.knative.dev/nodejs-10-helloworld-with-params created
Verify the build pod exists:
$ kubectl get build.build.knative.dev/nodejs-10-helloworld-with-params
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
nodejs-10-helloworld-with-params True 8m
Step 5: Serve NodeJS Runtime as a Knative Service
Now that we have built the OpenWhisk NodeJS runtime image with the helloworld
function baked into it, we can deploy that image as a Knative Service.
Configure the service template to point to the Docker Hub repo where the OpenWhisk runtime (built in step 4) will be pulled from. Replace ${DOCKER_USERNAME}
and create service.yaml
:
Deploy the runtime:
$ kubectl apply -f service.yaml
service.serving.knative.dev/nodejs-helloworld-with-params created
Step 6: Run Hello World Action
This is where it differs in the way we invoke the Knative service on IBM Kubernetes vs Docker for Desktop/minikube using JSON
payload:
kubectl get ksvc nodejs-helloworld-with-params
NAME DOMAIN LATESTCREATED LATESTREADY READY REASON
nodejs-helloworld-with-params nodejs-helloworld-with-params.default.<cluster-name>.<region>.containers.appdomain.cloud nodejs-helloworld-with-params-f2w4p nodejs-helloworld-with-params-f2w4p Truecurl nodejs-helloworld-with-params.default.<cluster-name>.<region>.containers.appdomain.cloud -H "Content-Type: application/json" -d '@params.json'
{"payload":"Hello Jill from OK!"}
Hooray! 💃 We have our hello world
action running on Knative on IBM Kubernetes.
Note that I was hitting memory limitation in installing Knative on free IBM Kubernetes cluster.
Enjoy! 👊