Technical implementation details of lambda function created on kyma, a cloud native platform

Time:2022-5-27

After enterprise level development and application entered the era of cloud native development, the word serverless architecture also frequently appeared in major technical media.

The literal meaning of serverless is easy to understandThe server is no longer neededMisunderstandings.

From the perspective of the whole enterprise, the SiCf development mode of ABAP NetWeaver has almost no connection with the serverless architecture. There are great differences between the two: one is to write function code on the local server deployed in the enterprise, and the other is to write code directly on the platform provided by the cloud service provider.

However, from the perspective of individual programmers who only need to concentrate on moving bricks, the two also have some similarities: programmers do not need to pay attention to how their code is stored on the server, nor do they need to worry about when these functions are called.

Of course, the technology is always moving forward. Compared with the SiCf service running on the ABAP NetWeaver server, the function running on the serverless architecture platform of modern cloud service providers is like a rich second generation born with a golden key. It naturally has some basic characteristics of cloud native applications, such as high availability, elastic scalability, on-demand loading, dynamic billing and so on.

In recent years, sap has made great continuous investment in the field of cloud native development. Naturally, solutions based on serverless architecture are indispensable. A typical example is lambda function on SAP kyma

The implementation of SAP kyma serverless is based on kubeless, a serverless framework natively supported by kubernetes, which realizes the functions of automatic scaling of resources running on kubernetes, API routing, monitoring and troubleshooting.

Technical implementation details of lambda function created on kyma, a cloud native platform

With the command line interface provided by kubeless, we can create and deploy lambda function with serverless feature on kyma

CRUD operations provided by kubeless command line interface:

Technical implementation details of lambda function created on kyma, a cloud native platform

Of course, you can also create it in the browser console provided by kyma.

As shown in the figure below, I created a hello world level lambda function. The logic is to simply add a suffix to the end of the incoming string, and the function is implemented based on nodejs8.

Technical implementation details of lambda function created on kyma, a cloud native platform

Let’s try to trigger this lambda function through HTTPS protocol

Technical implementation details of lambda function created on kyma, a cloud native platform

This HTTPS endpoint is the URL where we will call this lambda function in the future

Technical implementation details of lambda function created on kyma, a cloud native platform

The authentication of this lambda function is completed by DEX, an open source authentication framework based on openid.

Technical implementation details of lambda function created on kyma, a cloud native platform

In the function test console provided by kyma, send a request and get the suffix added string, which is easy to understand.

Technical implementation details of lambda function created on kyma, a cloud native platform

What happens when we create a lambda function? Although the name is serverless, these functions must physically run in a container on the server. This container is the pod of kubernetes. Jerry previously stressed that SAP kubernetes is based on kubernetes, so the commands supported by kubernetes are also fully supported by SAP kyma.

View the function just created from the command line:

kubeless function list -n ctu-demo

Technical implementation details of lambda function created on kyma, a cloud native platform

Use the command line to view the details of this function:

kubectl describe function zjerry-lambda -n ctu-demo
Deployment and replicationset:

Technical implementation details of lambda function created on kyma, a cloud native platform

Realization of horizontal automatic scaling:

Technical implementation details of lambda function created on kyma, a cloud native platform

The concept of lambda function is a user-defined resource created by SAP kyma based on kubernetes’ custom resource definitions (CRD) mechanism, and these function attributes shown in the figure above are the native attributes supported by kubernetes resources.

In kyma’s console, you can find the corresponding resources automatically generated in kyma’s background after the creation of lambda function:

Technical implementation details of lambda function created on kyma, a cloud native platform

Pod, the running environment of lambda function code:

Technical implementation details of lambda function created on kyma, a cloud native platform

Similarly, use the kubectl describe pod command to view the details of this pod and find the docker ID and docker image ID contained therein

Technical implementation details of lambda function created on kyma, a cloud native platform

As mentioned earlier, the lambda function of SAP kyma adopts DEX for authentication. If you want to call it explicitly in the programming language, you need to provide the corresponding token

Get the token in kyma’s console,

Technical implementation details of lambda function created on kyma, a cloud native platform

Send it to the authorization header field of postman to get the desired response.

Here’s how to extend the new UI in kyma console

The method is to create a new resource of type clustermicrofrontend
Use the command line kubectl get clustermicrofrontend to view these UI extensions:

Technical implementation details of lambda function created on kyma, a cloud native platform
Technical implementation details of lambda function created on kyma, a cloud native platform

Finally, the customized UI appears in the location of kyma console:

Technical implementation details of lambda function created on kyma, a cloud native platform

Next, we will analyze the technical implementation details of kyma lambda function in detail.

I created a function named zjerry lambda on kyma, based on nodejs8:

Technical implementation details of lambda function created on kyma, a cloud native platform

You can call this lambda function directly in kyma’s test console:

Technical implementation details of lambda function created on kyma, a cloud native platform

Isn’t the literal meaning of serverless implying that we don’t have a server? So where does this function code run?

Because SAP kyma is based on kubernetes, we can still explore some clues about the operation principle of lambda function on SAP kyma through some tools provided by kubernetes.

First, find the corresponding generated pod after the zjerry lambda function is created, and copy down the name: zjerry lambda-86668f75d4-pfbk6

Technical implementation details of lambda function created on kyma, a cloud native platform

Use the interactive parameter Ti of kubectl to enter the inside of this Pod:

kubectl exec -ti zjerry-lambda-86668f75d4-pfbk6 -n ctu-demo -- /bin/sh

Technical implementation details of lambda function created on kyma, a cloud native platform

After entering, he checked the process list and found the node kubeless process. Jerry suddenly felt a little confused:

Technical implementation details of lambda function created on kyma, a cloud native platform

It seems that the lambda function of SAP kyma is executed through a node process. Check the files in this Pod:

Technical implementation details of lambda function created on kyma, a cloud native platform

Open kubeless JS look at the contents:

Technical implementation details of lambda function created on kyma, a cloud native platform

If you are a nodejs developer, you will see the red content highlighted by Jerry above. The lambda function of SAP kyma actually runs on the express application framework launched in the corresponding kubernetes pod.
The dependency of express is defined in the package. In pod JSON:

Technical implementation details of lambda function created on kyma, a cloud native platform

The lambda function logic to be executed is through the environment variable func_ Handler to inject. In Jerry’s example, the function body name is main:

Technical implementation details of lambda function created on kyma, a cloud native platform
Technical implementation details of lambda function created on kyma, a cloud native platform

In the framework of server.kuless JS, you will find the lambda function written by the application developer from the kubeless folder inside the pod, load and run it.
As you can see, Jerry highlighted the handler inside the pod in red JS, whose content is the function body written in the kyma console.

Technical implementation details of lambda function created on kyma, a cloud native platform

So far, the implementation of SAP kyma’s lambda function has no mystery in Jerry’s eyes. Returning to the term serverless itself does not mean that the participation of the server is no longer needed in the whole scenario, but that the focus of the server has been hidden from the perspective of application developers under the serverless architecture.

summary

This paper first introduces the detailed steps of creating lambda function on the cloud native platform kyma, and then deeply analyzes the implementation principle of kyma lambda function, hoping to be helpful to cloud native developers who want to understand the behind the scenes implementation details of lambda function.

Recommended Today

Front end plug-in 1: jQuery multi select plug-in

project This project is a set of interactive and friendly components that replace the standard < Select > (select tag with multiple attribute). characteristic Free (based on wtfpl license) Support keyboard operation Provide some callback functions CSS fully customized Rely on jQuery version 1.8 or above The total size is about 8KB Simple use HTML […]