Kubeless¶
Kubeless is Kubernetes Native Serverless Framework. It allows building advanced applications with FaaS on top of Kubernetes.
Installation¶
Download the kubeless CLI from the release page <https://github.com/kubeless/kubeless/releases>. For example, for Linux or MacOs, do this:
$ curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip && \
unzip kubeless_$OS-amd64.zip && \
sudo mv bundles/kubeless_$OS-amd64/kubeless /usr/local/bin/
$ rm kubeless_$OS-amd64.zip
Example¶
You can use the CLI to create a function. Here is a toy:
def hello(event, context):
print event
return event['data']
Functions in Kubeless have the same format regardless of the language of the function or the event source. In general, every function: Receives an object event as their first parameter. This parameter includes all the information regarding the event source. In particular, the key ‘data’ should contain the body of the function request. Receives a second object context with general information about the function. Returns a string/object that will be used as response for the caller.
You can find more details about the function interface.
You create it with:
$ kubeless function deploy hello --runtime python2.7 \
--from-file test.py \
--handler test.hello
INFO[0000] Deploying function...
INFO[0000] Function hello submitted for deployment
INFO[0000] Check the deployment status executing 'kubeless function ls hello'
Let’s dissect the command:
hello: 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. It is supported to specify a zip file as far as it doesn't exceed the maximum size for an etcd entry (1 MB).
--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.
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 AGE
hello 1h
$ kubeless function ls
NAME NAMESPACE HANDLER RUNTIME DEPENDENCIES STATUS
hello default helloget.foo python2.7 1/1 READY
You can then call the function with:
$ kubeless function call hello --data 'Hello world!'
Hello world!