SAP Kyma is a cloud-native platform designed to empower developers to build, extend, and run microservices and serverless functions seamlessly within the SAP ecosystem. Its foundation on Kubernetes combined with native integration capabilities makes Kyma an ideal environment for developing scalable, event-driven microservices that can interact with SAP systems and other cloud services.
This article will guide you step-by-step through creating and deploying your first microservice in SAP Kyma, helping you get started on your cloud-native development journey.
A microservice in Kyma is a small, independently deployable service that performs a specific business function. Built typically as a containerized application, microservices in Kyma communicate via APIs or events and can be scaled or updated without impacting other parts of the system.
Before you start, ensure you have:
For simplicity, let’s create a simple Node.js Express microservice that exposes a REST API endpoint.
mkdir kyma-microservice
cd kyma-microservice
npm init -y
npm install express
index.js file with the following code:const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/hello', (req, res) => {
res.send('Hello from SAP Kyma microservice!');
});
app.listen(port, () => {
console.log(`Service listening on port ${port}`);
});
Dockerfile to containerize your app:FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
docker build -t <your-dockerhub-username>/kyma-microservice:latest .
docker login
docker push <your-dockerhub-username>/kyma-microservice:latest
Alternatively, use a private container registry if preferred.
deployment.yaml:apiVersion: apps/v1
kind: Deployment
metadata:
name: kyma-microservice
labels:
app: kyma-microservice
spec:
replicas: 1
selector:
matchLabels:
app: kyma-microservice
template:
metadata:
labels:
app: kyma-microservice
spec:
containers:
- name: kyma-microservice
image: <your-dockerhub-username>/kyma-microservice:latest
ports:
- containerPort: 3000
service.yaml to expose your microservice internally:apiVersion: v1
kind: Service
metadata:
name: kyma-microservice
spec:
selector:
app: kyma-microservice
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: ClusterIP
api-rule.yaml) in Kyma:apiVersion: gateway.kyma-project.io/v1alpha1
kind: APIRule
metadata:
name: kyma-microservice
spec:
gateway: kyma-gateway.kyma-system.svc.cluster.local
service:
name: kyma-microservice
port: 80
rules:
- path: /.*
methods: ["GET"]
accessStrategies:
- handler: noop
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f api-rule.yaml
kubectl get apirule kyma-microservice -o jsonpath='{.status.rules[0].host}'
curl https://<host-from-above>/hello
You should receive the response:
Hello from SAP Kyma microservice!
Congratulations! You have successfully created and deployed your first microservice on SAP Kyma. This foundational experience opens up many possibilities for building event-driven, scalable applications integrated within the SAP ecosystem.
From here, you can explore adding event subscriptions, integrating with SAP services, and implementing serverless functions to extend your application’s capabilities.