Kubeless is an open-source project that allows you to build a Serverless environment and implement functions running as a service in Kubernetes clusters. Thanks to this, it is possible to obtain a runtime environment similar to that provided by AWS Lambda, Google Cloud Functions and other providers of Cloud platforms.
Kubeless uses CRD Kubernetes (Custom Resource Definition) to define functions that must be installed on the cluster. All objects needed for proper operation are included in the CRD. That's why Kubeless advertises itself as truly Kubernetes Native. The framework provides its own CLI ( Command Line Interface)for managing Kubeless objects. With its help, we can implement and manage the implementation of functions in the environment. It is also possible to use the Kubernetes API and define objects in files and their deployment on a cluster in the same way as other Kubernetes objects are deployed on a cluster. Deployment yaml also allows extending and overwriting default settings for resources defined by CRD Kubeless operators, thus allowing flexible tuning of a specific function deployment to the specificity of a given service. Deployment may also contain feature source code. An example of a simple yaml deployment looks like this:
apiVersion: kubeless.io/v1beta1
kind: Function
metadata:
name: get-python
namespace: default
label:
created-by: kubeless
function: get-python
spec:
runtime: python2.7
timeout: "180"
handler: helloget.foo
deps: ""
checksum: sha256:d251999dcbfdeccec385606fd0aec385b214cfc74ede8b6c9e47af71728f6e9a
function-content-type: text
function: |
def foo(event, context):
return "hello world"
Since only the code itself is provided for defining functions, the framework must automatically prepare an environment appropriate for this code on the K8S cluster in which it will be run. Kubeless currently provides runtime environments (Runtime) for the following languages:
It is also possible to create your runtime environment (in the form of a CRD). Kubeless provides documentation on how to configure and add your runtime.
A Trigger must be created to call functions created with Kubeless. Currently, there are four types of this type of facility:
Provides function invocation via HTTP. HTTP Trigger is used to expose functionality outside the cluster. By default, the functions created are not available to the public, but other Pods can communicate with them through the service associated with the function. For proper operation, you need a configured Ingress controller on a Kubernetes cluster. HTTP Trigger supports access protection through Basic Authentication, TLS and CORS.
It is used to invoke a function according to a given schedule (cron pattern). For its operation, it uses CronJob available in Kubernetes by default. PubSub Trigger It allows you to call a function based on the data appearing on a predefined queue. The function then acts as a consumer of this queue - it is called for each new message that appears on the queue. Kafka and NATS queuing systems are currently supported. Kafka Trigger and NATS Trigger are available for them, respectively. DataStream Trigger Functions are called in response to records appearing in the data stream. Currently only AWS Kinesis (Kinesis Trigger) is supported. Custom Trigger All Triggers are based on Kubernetes CRD, so it is possible to write your custom trigger - Kubeless provides documentation on how to create it.
Kubeless provides the ability to autoscale the function, which is the number of containers to handle incoming requests. For this purpose, a mechanism provided by Kubernetes - HorizontalPodAutoscaler is used. It is possible to define scaling based on the following metrics:
Each environment automatically collects metrics about called functions and makes them available in a format supported by Prometheus. On their basis, we will learn about the frequency of calling a function, the number of errors or the time it takes to execute a function.
Kubeless provides a simple GUI (kubeless-ui). It allows you to create new and modify existing functions. It also allows you to call a given function from the GUI level.
Kubeless is relatively easy to implement and uses the framework that allows you to create a Function As a Service Serverless environment. The environment is based on the Kubernetes cluster mechanisms, and the person who implements the code does not need to know the specifics of the cluster to run it on the environment using CLI. Kubeless (as well as other serverless environments) can be a good solution when we need an environment to implement atomic functionalities that should be dynamically scaled, e.g. in the Event-Driven architecture. An example is the processing of large volumes of data in Big Data areas or in ETL processes, when the system load may be unevenly distributed over time by incoming data. Serverless can also be used in environments that implement a large number of simple and mutually independent services with a short execution time, e.g. in the area of DevOps on a Kubernetes cluster.