Serverless Apps

Develop serverless applications with Knative

Serverless applications are regular applications that “scale to zero”. This means when your application isn’t in use - no resources at all will be used. You only pay for what you use. These applications scale up elastically to meet the workload.

Once you have this feature enabled - all new apps you import or quickstarts you use by default will be serverless style (you can override as needed - see below). You don’t have to change the way you build web apps. This is currently in a preview state (but works well), and in future most web apps will work in this fashion (and this will be the default).

Enabling serverless apps

jx create addon gloo

And you are then good to go. Any new projects you create will be created in this serverless style.

Converting existing applications

If you already have a microservice and you want to convert it over to Knative Serve just import the source repository into Jenkins X and you should be all done.

If your application was imported recently into Jenkins X but before you installed and enabled Knative Serve you can use jx edit deploy to switch between the default deployment kind (using kubernetes Deployment and Service resources) and the knative kind (using Knative Service resource)

jx edit deploy

This command will modify the knativeDeploy flag in your helm charts/myapp/values.yaml file to enable / disable Knative Serve. Once you have committed that code change and merged to master your application will be released to staging using Knative Serve by the automated CI/CD pipeline in Jenkins X.

Edit your team’s deploy kind

You can edit the default deployment kind for your team which is used when’re you create a QuickStart or import a repository via the jx edit deploy command with the -t argument:

jx edit deploy -t

How it works

We use an open source project called Knative to provide the elastic scaling of your applications and functions.

Knative Serve exposes functions in any programming language over HTTP with elastic scaling from zero to many pods. This lets you build serverless applications which run on any cloud or kubernetes cluster and make an efficient use of resources.

Knative works with service mesh technologies like Istio or Gloo.

The Jenkins X builld packs create a Knative Serve resource in your helm chart at charts/myapp/templates/ksvc.yaml. This resource is only created if the knativeDeploy flag is true / otherwise the default kubernetes Service & Deployment are created.

Installing Knative Serve

Gloo is much smaller and simpler to install than Istio so in this guide we are going to use that.

We have a simple command jx create addon gloo to install Gloo and Knative Serve on Jenkins X:

jx create addon gloo

This command will install Knative Serve into the knative-serving namespace and Gloo into the gloo-system namespace. You can check it’s all installed and working via:

kubectl get pod -n knative-serving
kubectl get pod -n gloo-system

Or you can follow the Knative install guide to install it directly via istio or gloo.

Using Knative Serve

Now you have installed Knative Serve snd Gloo you can create a new quicktart or create a new spring boot application and it will default to using Knative Serve to elastically scale your microservice based on its load over HTTP.

You can check if Knative Serve is being used on your application by doing:

kubectl get ksvc -n jx-staging

Which should show all of the Knative Service resources in your Staging environment.

Demo

Here is a demo of using Knative Serve snd Gloo from the April 4th, 2019 Office Hours:


Last modified December 10, 2019: release 0.0.1335 (bebae14)