Installation is made of three steps:
- Download the
kubeless
CLI from the release page. - Create a
kubeless
namespace (used by default) - Then use one of the YAML manifests found in the release page to deploy kubeless. It will create a functions Custom Resource Definition and launch a controller.
There are several kubeless manifests being shipped for multiple k8s environments (non-rbac, rbac and openshift), pick the one that corresponds to your environment:
kubeless-$RELEASE.yaml
is used for RBAC Kubernetes cluster.kubeless-non-rbac-$RELEASE.yaml
is used for non-RBAC 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 Kubernetes cluster (with RBAC available).
$ export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d '"' -f 4)
$ 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
kubeless-controller-manager-567dcb6c48-ssx8x 1/1 Running 0 1h
$ kubectl get deployment -n kubeless
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
kubeless-controller-manager 1 1 1 1 1h
$ kubectl get customresourcedefinition
NAME AGE
cronjobtriggers.kubeless.io 1h
functions.kubeless.io 1h
httptriggers.kubeless.io 1h
Details on installing kubeless in a different namespace can be found here.
For installing kubeless
CLI using execute:
export OS=$(uname -s| tr '[:upper:]' '[:lower:]')
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/
Binaries for x86 architectures can be found as well in the releases page.
- Download the latest release from the releases page.
- Extract the content and add the
kubeless
binary to the system PATH.
You are now ready to create functions.
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 here
You create it with:
$ kubeless function deploy hello --runtime python3.8 \
--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 python3.8
: This is the runtime we want to use to run our function. Available runtimes can be found executingkubeless get-server-config
.--from-file test.py
: This is the file containing the function code. Specifying a zip file or a gzip/bzip2/xz compressed tar file (see list of supported suffixes for compressed tar files) is supported as long as it doesn't exceed the maximum size for an etcd entry (1 MB).--handler test.hello
: This specifies the file and the exposed function that will be used when receiving requests. In this example we are using the functionhello
from the filetest.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 python3.8 1/1 READY
You can then call the function with:
$ kubeless function call hello --data 'Hello world!'
Hello world!
Or you can curl directly with kubectl proxy
using an apiserver proxy URL.
For example:
$ kubectl proxy -p 8080 &
$ curl -L --data '{"Another": "Echo"}' \
--header "Content-Type:application/json" \
localhost:8080/api/v1/namespaces/default/services/hello:http-function-port/proxy/
{"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.
You can delete the function and uninstall Kubeless:
$ kubeless function delete hello
$ kubeless function ls
NAME NAMESPACE HANDLER RUNTIME DEPENDENCIES STATUS
$ kubectl delete -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yaml
See the examples directory for a list of simple examples in all the languages supported. NodeJS, Python, Golang etc ...
Also checkout the functions repository, where we're building a library of ready to use kubeless examples, including an incubator to encourage contributions from the community - your PR is welcome ! :)