Create Kyma Function Using Kyma CLI
In this tutorial, you will use Kyma CLI to create a Kyma Function.
Overview
You will learn
- How to install and use Kyma CLI
- How to create a Kyma Function
Prerequisites
Prerequisites
- You have created and set up your “SAP BTP, Kyma Environment” either manually or by Quick Account Setup.
- You have added the Serverless module to your Kyma environment.
- You have completed the Install the Kubernetes Command Line Tool tutorial.
Steps
Enable the Istio sidecar proxy injection in the default namespace:
bash/Powershellkubectl label namespace default istio-injection=enabled --overwriteIf you create a Function in a namespace with enabled Istio sidecar injection, an Istio sidecar proxy is automatically injected to the Function’s Pod during its creation. This makes the Function part of the Istio service mesh. To expose a workload using an APIRule custom resource, it is required to include the workload in the Istio service mesh.
In your terminal, go to your working folder, and run:
bash/Powershellkyma function initIf successful, you get the following message:
Functions files of runtime nodejs22 initialized to dir {WORKING_FOLDER_PATH}You have created 2 files in your working folder:
- handler.js
- package.json
You can check the content of the files with your editor (e.g. Visual Studio Code).
To apply your Function to your Kyma runtime, run:
bash/Powershellkyma function create hello-functionIf successful, you get the following message:
bash/Powershellresource default/hello-function appliedTo verify the Function deployment, run:
bash/Powershellkyma function get hello-functionIf successful, you get the following result:
bash/PowershellNAME CONFIGURED BUILT RUNNING RUNTIME GENERATION hello-function True True True nodejs22 1
In your working folder, create a new YAML file named
myapirule.yaml. You can do this using a text editor or by runningtouch myapirule.yamlin your terminal.Open the file in your editor and add the following APIRule definition:
YAMLapiVersion: gateway.kyma-project.io/v2 kind: APIRule metadata: name: hello-rule namespace: default spec: hosts: - hello-host service: name: hello-function port: 80 gateway: kyma-system/kyma-gateway rules: - path: /* methods: ["GET", "POST"] noAuth: trueDeploy your APIRule.
bash/Powershellkubectl apply -f "{PATH_TO_YOUR_CONFIG_FILE}"For example:
bash/Powershellkubectl apply -f "C:\tools\myapirule.yaml"
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.