Deploying SAP on Kubernetes: A Practical Guide
Last updated
Last updated
Kubernetes Gardener is SAP’s open source managed Kubernetes service. It abstracts environment specifics to deliver a Kubernetes-native experience and enables you to easily create and manage several Kubernetes clusters.
Gardener provides a fully-validated extensibility framework that you can adjust to various programmatic cloud and infrastructure providers. It works by implementing Kubernetes’s automated management and operation for clusters as a service.
Gardener exposes its Cluster API to create homogeneous clusters on the supported infrastructure. While the SIG Cluster Lifecycle’s Cluster API only harmonizes how to get to clusters, Gardener’s Cluster API also harmonizes the make-up of the clusters. Gardener’s API achieves homogeneous clusters with the same configuration, behavior, and bill of material on all supported infrastructure.
The easiest way to set up Gardner is using the official Helm file (get it here). Read this blog post to learn more about Kubernetes Helm.
The following procedure requires a cluster managed by SAP Gardener and that SAP BTP Service Operator be installed in the cluster. It also requires Docker, a Docker repository with public access, and a Spring Boot application that uses the SAP Cloud SDK. Code examples are adapted from the official Gardener documentation.
To ship the application in a container with Docker:
Create a Dockerfile in the project’s root folder with the following contents:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=application/demo-target/demo-*.jar
COPY ${JAR_FILE} demoApp.jar
ENTRYPOINT ["java","-jar","/demoApp.jar"]
EXPOSE 9000
If required, make the JAR_FILE point to the .jar file.
Use the following commands to compile and push the image:
docker build -t demo-repo/demo-image-name .
docker push demo-repo/demo-image-name
To create the required Kubernetes deployment for the application:
Make a new YAML file and put the following configuration inside it:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-deployment
spec:
replicas: 1
selector:
matchLabels:
app: demo-app
template:
metadata:
labels:
app: demo-app
spec:
containers:
- image: demo-repo/demo-image-name
name: demo-app
imagePullPolicy: Always
resources:
requests:
memory: '1Gi'
cpu: '500m'
limits:
memory: '1.5Gi'
cpu: '750m'
volumeMounts:
imagePullSecrets:
- name: <docker-login-secret>
---
apiVersion: v1
kind: Service
metadata:
labels:
app: demo-app
name: demo-app
namespace: default
spec:
type: NodePort
ports:
- port: 9000
selector:
app: demo-app
Use the following command to install the configuration:
kubectl apply -f demo-deployment.yml
Use the following command to monitor the deployment’s status:
kubectl get deployment demo-app
To create an Ingress that makes the application available from outside the cluster:
Create a new YAML file and put the following Ingress configuration inside:
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-ingress
namespace: default
annotations:
spec:
tls:
- hosts:
# - "<demo-cluster-host>"
# - "*.ingress.<demo-cluster-host>"
# secretName: secret-tls
rules:
- host: 'demo-app.ingress.<demo-cluster-host>'
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: demo-app
port:
number: 9000
Use the following commands to install the configuration and verify Ingress is functional:
kubectl apply -f ingress.yml
kubectl describe ingress demo-ingress
Visit the host provided in the Ingress specification through a browser or a tool like Postman to check its access.
This tutorial will add access to the application for the Destination Service.
To attach SAP BTP services to the application:
Create a new YAML file and put in the following configuration:
---
apiVersion: services.cloud.sap.com/v1alpha1
kind: ServiceInstance
metadata:
name: demo-destination-service
spec:
serviceOfferingName: destination
servicePlanName: lite
externalName: default-destination-service
---
apiVersion: services.cloud.sap.com/v1alpha1
kind: ServiceBinding
metadata:
name: demo-destination-service-binding
spec:
serviceInstanceName: demo-destination-service
secretName: demo-destination-service-secret
secretRootKey: demo-destination-service-key
Use the following command to install the configuration:
kubectl apply -f destination-service.yml
Use the following command to monitor the installation status:
kubectl describe ServiceInstance destination-service
Add the following at the end of the deployment.yml file:
- name: demo-destination-service-binding-volume
secret:
secretName: demo-destination-service-secret
the container section of deployment.yml, add the following in the empty lists of volumeMounts:
- name: demo-destination-service-binding-volume
mountPath: '/etc/secrets/sapcp/destination/demo-destination-service'
readOnly: true
Use the following command to update the configuration:
kubectl apply -f deployment.yml
SAP's Kubernetes Gardener provides a seamless Kubernetes-native experience that abstracts complexities and enables effortless creation and management of Kubernetes clusters across diverse infrastructures.
By deploying SAP on Kubernetes using Gardener, developers and administrators gain an extensible, uniform, and efficient solution for orchestrating their workloads. This guide has offered a detailed walkthrough on setting up Gardener, developing an application for Kubernetes with SAP Gardener, and leveraging SAP BTP services within a Kubernetes environment. By following these steps, users can fully capitalize on the strengths of Kubernetes while also harnessing the power of SAP's robust cloud offerings.
As cloud-native practices continue to dominate the industry, such integrations provide businesses with a solid foundation to evolve and adapt in a rapidly changing technological landscape.