×
Community Blog Serverless Engineering Practices | Build a Kubeless Platform Quickly

Serverless Engineering Practices | Build a Kubeless Platform Quickly

Abstract: This article explains how to create a Kubeless service on the Kubernetes cluster.

An Introduction to Kubeless

Kubeless is a native serverless framework based on Kubernetes that allows users to deploy a small amount of code (functions) without worrying about the underlying architecture. It is deployed on Kubernetes clusters and makes full use of Kubernetes features and resource types to clone content on AWS Lambda, Azure Functions, and Google Cloud Functions.

The main features of Kubeless are summarized below:

  • Supports Python, Node.js, Ruby, PHP, Go, NET, Ballerina languages to write and customize run time
  • Kubeless CLI meets AWS Lambda CLI
  • Event triggers use the Kafka message system and HTTP triggers.
  • By default, Prometheus monitors the calls and latency of functions.
  • The Serverless Framework plug-in is supported.

The features of Kubeless are built on top of Kubernetes. It is easy for people unfamiliar with Kubernetes to deploy Kubeless. Its main implementation is to convert user-written functions into CRDs (Custom Resource Definition, custom resources) in Kubernetes and run them in the cluster as containers.

Kubeless Deployment

Create a Kubeless service on an existing Kubernetes cluster:

export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/   latest | grep tag_name | cut -d '"' -f 4)kubectl create ns kubelesskubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/   kubeless-$RELEASE.yaml

After successful creation, the following figure is displayed:

1
Install and Configure Kubeless

View the basic information:

kubectl get pods -n kubeless

The relevant Pod information is shown in the figure below:

2
View Kubeless Relevant Pod

View the Deployment information:

kubectl get deployment -n kubeless

The relevant information is shown in the figure below:

3
View Kubeless Deployment-Relevant Information

View customresourcedefinition information:

kubectl get customresourcedefinition

Its relevant information is shown in the figure below:

4
View customresourcedefinition Information

Download the Command Line Tool

Download the Kubeless tool and decompress it:

export OS=$(uname -s| tr '[:upper:]' '[:lower:]')curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_   $OS-amd64.zipunzip kubeless_$OS-amd64.zip

After decompression, view:

./bundles/kubeless_linux-amd64/kubeless

The details are shown in the figure:

5
Use the Kubeless Command Line Tool

Experience Tests

Create a test code helloworld.py:

def hello(event, context):   print(event)   return event['data']

Deployment Project:

./bundles/kubeless_linux-amd64/kubeless function deploy hello-world --runtime   python3.6 --from-file helloworld.py --handler helloworld.hello

After the deployment is successful, view the project information below:

kubectl get functions

The list of functions is shown in the figure:

6
View the Function List

View instance functions:

./bundles/kubeless_linux-amd64/kubeless function ls

The function state is shown in the figure below:

7

Trigger function:

./bundles/kubeless_linux-amd64/kubeless function call hello-world --data 'Hello   world!'

After the trigger is completed, you will see the output below:

8

View the logs output in the instance, as shown in the figure:

9
View Logs in an Instance

So far, we have successfully created the Kubeless service on the Kubernetes cluster and experienced the Hello World implementation of Kubeless.

0 0 0
Share on

Alibaba Cloud Serverless

97 posts | 7 followers

You may also like

Comments

Alibaba Cloud Serverless

97 posts | 7 followers

Related Products

  • Container Service for Kubernetes

    Alibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.

    Learn More
  • Function Compute

    Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.

    Learn More
  • ACK One

    Provides a control plane to allow users to manage Kubernetes clusters that run based on different infrastructure resources

    Learn More
  • Elastic High Performance Computing Solution

    High Performance Computing (HPC) and AI technology helps scientific research institutions to perform viral gene sequencing, conduct new drug research and development, and shorten the research and development cycle.

    Learn More