Using Serverless Framework With Knative on OpenShift
Serverless Framework depends on Knative to deploy a serverless function on OpenShift, and then all you need is to run
If you didn't already know, Serverless Framework supports Node.js, Python, Java, Go, C#, F#, Ruby, Swift, Kotlin, PHP and Scala
- Knative deployed on your Openshift Cluster Quick Guide
- Serverless CLI installed on your local machine Quicker Guide
- A project ready to be deployed
After all the prerequisites are met, let's get started.
First, we want to login to serverless, just type
serverless login in your terminal, and it'll guide you.
Then, we'll need to clone a project running the command
serverless create -u <github-link>, you can pick any of these sample projects or setup your own. I will use
npx serverless init knative-express-starter to create a sample project locally.
Serverless Framework, requires a file called
serverless.yml as you can see it exists in all the sample projects.
The one I generated looks like this:
app: knative-express-startername: knative-express-startercomponent: knativeinputs:src: ./src
Nothing needs to change here other than the app and name values.
What we need to look at next is the
Initially it looks like this:
# Learn more about about the credentials needed# to deploy your app https://github.com/serverless/components#credentials# AWS:# AWS_ACCESS_KEY_ID=<your access key># AWS_SECRET_ACCESS_KEY=<your secret access key>
And for Knative to work, it requires these environment variables, so we change it to:
KUBERNETES_ENDPOINT=https://api.openshift.sample.com # or run oc whoami --show-serverKUBERNETES_PORT=6443KUBERNETES_SERVICE_ACCOUNT_TOKEN= # run oc whoami --show-tokenKUBERNETES_SKIP_TLS_VERIFY=true
Now you can run
serverless deploy or
serverless deploy -v to display logs
You can also check the status of your deployment on serverless.com dashboard, or check your OpenShift Web Console, where your function will deploy to a newly created namespace equal to your app's name. e.g
To read more about how to set up your serverless with Knative and more advanced configs, head over to Serverless Framework's Knative Introduction Guide