kubeless

module
Version: v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2017 License: Apache-2.0

README

Kubeless logo

Build Status Slack

kubeless is a Kubernetes-native serverless framework that lets you deploy small bits of code without having to worry about the underlying infrastructure plumbing. It leverages Kubernetes resources to provide auto-scaling, API routing, monitoring, troubleshooting and more.

Kubeless stands out as we use a Custom Resource Definition to be able to create functions as custom kubernetes resources. We then run an in-cluster controller that watches these custom resources and launches runtimes on-demand. The controller dynamically injects the functions code into the runtimes and make them available over HTTP or via a PubSub mechanism.

Kubeless is purely open-source and non-affiliated to any commercial organization. Chime in at anytime, we would love the help and feedback !

Screencasts

Click on the picture below to see a screencast demonstrating event based function triggers with kubeless.

screencast

Click on this next picture to see a screencast demonstrating our serverless plugin:

serverless

Tools

Installation

Download kubeless cli from the release page. Then use one of yaml manifests found in the release package to deploy kubeless. It will create a kubeless namespace and a functions Custom Resource Definition. You will see a kubeless controller, and kafka, zookeeper statefulset running.

There are several kubeless manifests being shipped for multiple k8s environments (non-rbac, rbac and openshift), please consider to pick up the correct one:

  • kubeless-$RELEASE.yaml is used for non-RBAC Kubernetes cluster.
  • kubeless-rbac-$RELEASE.yaml is used for RBAC-enabled Kubernetes cluster.
  • kubeless-openshift-$RELEASE.yaml is used to deploy Kubeless to OpenShift (1.5+).

For example, this below is a show case of deploying kubeless to a non-RBAC Kubernetes cluster.

$ export RELEASE=v0.2.2
$ kubectl create ns kubeless
$ kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yaml

$ kubectl get pods -n kubeless
NAME                                   READY     STATUS    RESTARTS   AGE
kafka-0                                1/1       Running   0          1m
kubeless-controller-3331951411-d60km   1/1       Running   0          1m
zoo-0                                  1/1       Running   0          1m

$ kubectl get deployment -n kubeless
NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kubeless-controller   1         1         1            1           1m

$ kubectl get statefulset -n kubeless
NAME      DESIRED   CURRENT   AGE
kafka     1         1         1m
zoo       1         1         1m

$ kubectl get customresourcedefinition
NAME               KIND
functions.k8s.io   CustomResourceDefinition.v1beta1.apiextensions.k8s.io

$ kubectl get functions

You are now ready to create functions.

Usage

You can use the CLI to create a function. Functions have two possible types:

  • http trigger (function will expose an HTTP endpoint)
  • pubsub trigger (function will consume event on a specific topic)
HTTP function

Here is a toy:

def foobar(context):
   print context.json
   return context.json

You create it with:

$ kubeless function deploy get-python --runtime python2.7 \
                                --from-file test.py \
                                --handler test.foobar \
                                --trigger-http

Let's dissect the command:

  • get-python: This is the name of the function we want to deploy.
  • --runtime python2.7: This is the runtime we want to use to run our function. Available runtimes are shown in the help information.
  • --from-file test.py: This is the file containing the function code.
  • --handler test.foobar: This specifies the file and the exposed function that will be used when receiving requests. In this example we are using the function foobar from the file test.py.
  • --trigger-http: This sets the function trigger. The available options are:
    • --trigger-http to trigger the function using HTTP requests.
    • --trigger-topic to trigger the function with a certain Kafka topic. See the next example.
    • --schedule to trigger the function following a certain schedule using Cron notation. F.e. --schedule "*/10 * * * *" would trigger the function every 10 minutes.

You can find the rest of options available when deploying a function executing kubeless function deploy --help

You will see the function custom resource created:

$ kubectl get functions
NAME          KIND
get-python    Function.v1.k8s.io

$ kubeless function ls
NAME        NAMESPACE   HANDLER     RUNTIME     TYPE    TOPIC
get-python  default     test.foobar python2.7   HTTP

You can then call the function with:

$ kubeless function call get-python --data '{"echo": "echo echo"}'
Connecting to function...
Forwarding from 127.0.0.1:30000 -> 8080
Forwarding from [::1]:30000 -> 8080
Handling connection for 30000
{"echo": "echo echo"}

Or you can curl directly with kubectl proxy, for example:

$ kubectl proxy -p 8080 &

$ curl --data '{"Another": "Echo"}' localhost:8080/api/v1/proxy/namespaces/default/services/get-python/ --header "Content-Type:application/json"
{"Another": "Echo"}

Kubeless also supports ingress which means you can provide your custom URL to the function. Please refer to this doc for more details.

PubSub function

A function can be as simple as:

def foobar(context):
    print context
    return context

You create it the same way than an HTTP function except that you specify a --trigger-topic.

$ kubeless function deploy test --runtime python2.7 \
                                --handler test.foobar \
                                --from-file test.py \
                                --trigger-topic test-topic

After that you can invoke them publishing messages in that topic:

$ kubeless topic publish --topic test-topic --data "Hello World!"

You can check the result in the pod logs:

$ kubectl logs test-695251588-cxwmc
Hello World!
Other commands

You can delete and list functions:

$ kubeless function ls
NAME        NAMESPACE   HANDLER     RUNTIME     TYPE    TOPIC
test        default     test.foobar python2.7   PubSub  test-topic

$ kubeless function delete test

$ kubeless function ls
NAME        NAMESPACE   HANDLER     RUNTIME     TYPE    TOPIC

You can create, list and delete PubSub topics:

$ kubeless topic create another-topic
Created topic "another-topic".

$ kubeless topic delete another-topic

$ kubeless topic ls

Examples

See the examples directory for a list of various examples. Minio, SLACK, Twitter etc ...

Also checkout the functions repository.

Documentation

More details can be found in the complete Documentation

Building

Consult the developer's guide for a complete set of instruction to build kubeless.

Comparison

There are other solutions, like fission and funktion. There is also an incubating project at the ASF: OpenWhisk. We believe however, that Kubeless is the most Kubernetes native of all.

Kubeless uses k8s primitives, there is no additional API server or API router/gateway. Kubernetes users will quickly understand how it works and be able to leverage their existing logging and monitoring setup as well as their troubleshooting skills.

Roadmap

We would love to get your help, feel free to land a hand. We are currently looking to implement the following high level features:

  • Add other runtimes, currently Python, NodeJS and Ruby are supported. We are also providing a way to use custom runtime. Please check this doc for more details.
  • Investigate other messaging bus (e.g nats.io)
  • Instrument the runtimes via Prometheus to be able to create pod autoscalers automatically (e.g use custom metrics not just CPU)
  • Optimize for functions startup time
  • Add distributed tracing (maybe using istio)
  • Break out the triggers and runtimes

Directories

Path Synopsis
cmd
kubeless
Serverless framework for Kubernetes.
Serverless framework for Kubernetes.
kubeless-controller
Kubeless controller binary.
Kubeless controller binary.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL