OpenWhisk Actions on Knative — Actions with JSON in / JSON out Interface

Priti Desai
Apache OpenWhisk
Published in
2 min readMay 3, 2019

This is a follow up blog post of How to run OpenWhisk actions on Knative?

Here in this blog post, we are going to experiment with Hello World NodeJS action with input parameters.

Pre-requisites:

  • Secret exists on Knative, check with:
$ kubectl get secret dockerhub-user-pass
  • Service Account exists on Knative, check with:
$ kubectl get serviceaccount openwhisk-runtime-builder
  • Build Template exists on Knative, check with:
$ kubectl get buildtemplate openwhisk-nodejs-runtime

If any of the secret/service account/build template does not exist on your Knative installation, please go back to the How to run OpenWhisk actions on Knative? blog post and run Step 1 through Step 3 depending on what’s missing.

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.

build.yaml

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 1m

Serve NodeJS Runtime as a Knative Service

Configure the service template to point to the Docker Hub repo where the OpenWhisk runtime (built in previous step) will be pulled from. Replace ${DOCKER_USERNAME} and create service.yaml:

service.yaml

Run Hello World Action

Depending on your Knative installation, determine how to access your knative gateway. Copy the JSON payload and run:

helloworld-with-params.json

Note that JSON payload under activation is reserved for OpenWhisk controller/invoker and can be ignored.

curl -H "Host: nodejs-helloworld-with-params.default.example.com" -d '@helloworld-with-params.json' -H "Content-Type: application/json" http://<IP_ADDRESS>:<PORT>
{"payload":"Hello Jill from OK!"}

Enjoy! 👍

--

--

Priti Desai
Apache OpenWhisk

Developer Lead @IBM. Tekton maintainer. Co-founder of License Scanner @Cyclonedx