A serverless plugin for Kubeless

Tu Nguyen
Bitnami Perspectives
4 min readMay 30, 2017

Serverless.com ﹣a company based in San Francisco− has been developing the so-called Serverless Framework, to help users build serverless architecture on AWS Lambda, Microsoft Azure and more. The framework is provided as a CLI tool that allows users to build and deploy functions. The currently supported serverless cloud services include AWS Lambda, Microsoft Azure, IBM OpenWhisk and Google Cloud Platform. In this post, we announce the availability of a serverless plugin for Kubeless, the Kubernetes native serverless framework led by Bitnami.

At Bitnami, we are developing a Kubernetes-native serverless framework called Kubeless. The reason we believe Kubeless is the native serverless solution for Kubernetes among a dozen serverless frameworks out there is because we are leveraging a lot of Kubernetes concepts to deploy and manage function. In particular, we use Third Party Resource to define function, and a custom Controller to manage function, deploy it as Kubernetes deployment and expose it via Kubernetes service. Function code is injected to the Kubernetes deployment via Config Map, and in order to load function’s dependencies, we use Init Container. In order to help Serverless users to easily build and deploy functions to Kubernetes infrastructure, we have created a Kubeless-Serverless plugin. The associated project is open-sourced and it is available on GitHub. The plugin supports is still in alpha development and currently only provides the deploy and remove functionalities. In this blog, I am giving you a first look at this plugin by taking a sample function and deploying it to Kubernetes (Minikube) using the Serverless CLI.

To get started you need to have a Kubernetes endpoint available via Minikube and you need to install the Serverless CLI and Kubeless.

Installing Pre-requisites

Install Serverless CLI. Remember to have node and npm installed before.

$ npm install serverless -g
$ serverless help

Get the latest version of Kubeless, for example on OSX:

$ curl -L https://github.com/kubeless/kubeless/releases/download/0.0.13/kubeless_darwin-amd64.zip > ./kubeless.zip

Uncompress and use the Kubeless CLI to install everything:

$ kubeless install
$ kubeless function ls

In the Kubeless repository, we are providing some sample functions in `/examples` folder. There are two kinds of function supported: http triggered and event triggered. You can try to deploy one of them in order to make sure that you have Kubeless ready.

$ kubeless function deploy get-python --trigger-http \
--runtime python27 \
--handler helloget.foo \
--from-file python/helloget.py
$ kubectl proxy -p 8080
$ curl localhost:8080/api/v1/proxy/namespaces/default/services/get-python/

Serverless Plugin

Once you have Serverless CLI and Kubeless, let’s jump to try the plugin. First you need to clone the plugin code, install the dependencies and set an environment variable that points to your Kubernetes endpoint:

$ git clone https://github.com/kubeless/serverless-plugin
$ cd serverless-plugin
$ npm install
$ export K8SAPISERVER=https://<apiserver_ip>:<apiserver_port>

Then you can use the example provided. Take a look into the `examples` folder. There is `serverless.yml` file which contains all metadata of the function. Note that this YAML file is typical of the serverless framework, it is not a Kubeless format.

$ cat serverless.yml
service: hello
provider:
name: google
runtime: python2.7
plugins:
— kubeless-serverless
functions:
hello:
handler: handler.hello
  • service: A service is like a project.
  • provider: Specify the cloud provider on which you wanna deploy the function. For this plugin, we temporarily use `google`. The only `runtime` supported at this moment is python.
  • plugins: A plugin is custom JS code to extend functionalities within the Serverless framework. We use `kubeless-serverless` plugin for this. The plugin has been published at https://www.npmjs.com/package/kubeless-serverless
  • functions: List out the function you wanna deploy. The `handler` property points to the file and module containing the code you want to run in your function

Deploying the Function

Now if you run `$ serverless help` again inside the examples folder, you will notice that a few more items have been added to the main program via the `kubeless-serverless` plugin including KubelessDeploy, KubelessIndex, KubelessProvider and KubelessRemove.

You are now ready to deploy the function by running the following:

$ serverless deploy

The function will be deployed to the Kubernetes as a deployment and exposed via a service thanks to Kubeless. You can check that everything is running properly:

$ kubectl get po,deploy,svcNAME                             READY     STATUS             RESTARTS   AGEpo/hello-2899647726-xv4d4        1/1       Running            0          40sNAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGEdeploy/hello         1         1         1            1           40sNAME                  CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGEsvc/hello             10.0.0.77    <nodes>       8080:31600/TCP   40s
svc/kubernetes 10.0.0.1 <none> 443/TCP 1d

Hurray… Your function is on air.

To remove it, just run:

$ serverless remove

There is still more to do with this plugin, like adding the ability to update a function, so don’t hesitate to jump on GitHub to file some issues or help us with a pull request. Kubeless is also evolving very quickly and we welcome any suggestions, feedback or contribution.

We believe serverless is going to be the next application architecture and building on top of Kubernetes makes total sense to us. If you agree, join us on the fun at https://github.com/kubeless

--

--

Tu Nguyen
Bitnami Perspectives

@theASF committer (@CloudStack) / @gsoc student/ @kubernetesio member /@tomochain blockchain lead engineer