Create Kyma Function and a Microservice via UI
- How to enter Kyma dashboard
- How to create a Kyma Function
- How to create a Kyma microservice
Prerequisites
- You have created and set up your “SAP BTP, Kyma Environment” either manually or by Quick Account Setup.
- You have enabled Kyma in your subaccount.
- You have added the Serverless module to your Kyma cluster.
- Step 1
-
In your Kyma dashboard, go to Namespaces and choose the default namespace.
-
Choose Edit, switch the sidecar injection toggle to enable Istio sidecar injection, and select Save.
If you create a Function in a namespace with Istio sidecar injection enabled, 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.
-
Go to Workloads > Functions and choose Create.
-
Fill in the form in the Create Function view using the following details and choose Create.
- Template:
Default - Name:
hello-world - Language:
JavaScript - Runtime:
node.js 20 - Function Profile:
XS
- Template:
-
Creating a Function takes a few seconds. Select the newly created hello-world Function. Scroll down, and notice that it does not have any APIRules yet, you need to create one to define the rules of accessing the Function using APIs.
-
Go to Discovery and Network > API Rules and choose Create.
-
Fill in the form in the Create API Rule view using the following details and choose Create.
- Name:
hello-world - Service Name:
hello-world - Port:
80 - Leave the pre-defined details in the Gateway section
- Host:
hello-world - Access Strategy:
No Auth
- Name:
-
The
hello-worldAPIRule is created. Scroll down to Virtual Service, copy the URL under Hosts, and paste it in your browser.
A browser window opens showing the following result:
Hello World from the Kyma Function hello-world running on nodejs20!
-
- Step 2
You already know how to deploy and expose a Function. You can do the same with a container microservice.
To deploy a microservice, you will use the orders-service example. For more information about this example, see the kyma-runtime-extension-samples repository.
This tutorial shows how to deploy a microservice using the Docker image.
-
Open Kyma dashboard, go to Namespaces, and choose default.
-
Go to Workloads > Deployments and choose Create.
-
Fill in the form in the Create Deployments view using the following details and then choose Create.
- Name:
orders-deployment - Switch the toggle to enable Istio sidecar proxy injection for the Deployment.
- Docker Image:
ghcr.io/sap-samples/kyma-runtime-extension-samples/orders-service:1.0.0 - Optionally, provide the following parameters to save resources:
Profile Value Profile Value Memory requests 10Mi Memory limits 32Mi CPU requests (m) 16m CPU limits (m) 20m - Name:
You created the orders-deployment Deployment. To confirm that the operation was successful, check if the Status field is showing 1/1 Pods running.
-
- Step 3
Once you have the Deployment ready, you can create a Kubernetes Service to allow other Kubernetes resources to communicate with your microservice.
-
Go to Discovery and Network > Services and choose Create.
-
Fill in the form in the Create Service view using the following details and then choose Create.
- Name:
orders-service - Add the following selector:
- app:
orders-deployment
- app:
- Add a port using the following parameters:
- Name:
orders-port - Protocol:
TCP - Port:
80 - Target Port:
8080(or other available) - Application Protocol:
http
- Name:
- Name:
You created a new Service, called orders-service.
-
- Step 4
You cannot access and test your new
orders-serviceyet from outside of the cluster. To expose the microservice, first, you must create an APIRule, just like you did to expose your Function.-
Go to Discovery and Network > API Rules and choose Create.
-
Fill in the form in the Create API Rule view using the following details and choose Create.
- Name:
orders-apirule - Service Name:
orders-service - Port:
80 - Leave the pre-defined details in the Gateway section
- Host:
orders-host - Methods: choose
GETandPOST - Access Strategy:
No Auth
- Name:
-
The
orders-apiruleis created. Wait for the Status to beReady. -
Scroll down to Virtual Service, copy the URL under Hosts, and paste it in your browser. A browser will open, but the link doesn’t work because the underlying Docker image has no homepage. Extend the URL by adding the /orders string.
For example:
https://orders-host.c-123456.kyma.ondemand.com/orders -
If you extend the URL correctly, you can see your orders:
[]. It is empty, as you have not created orders in this tutorial so far.
-
- Step 5