Technical Articles
Manage your First Container using Kubernetes in SAP Cloud Platform, Kyma Runtime
Before I start explaining, how to manage your first container on SAP Cloud Platform, Kyma runtime. I hope you are already aware of the Docker container and deployed your container on the SAP Cloud Platform. If not, then first read the following article and perform all the steps, we’ll use the same container for Kyma runtime.
Deploy Python Application on SAP Cloud Platform using Docker Container
I’ll briefly explain all the terms we are using in this article.
Docker
Docker is the containerization platform that packages your application and all its dependencies together in the form of containers, which make your application works seamlessly in any environment.
Kubernetes
Kubernetes is an open-source container orchestration engine for automating deployment, scaling, and management of containerized applications.
Kyma Runtime
Kyma is an open-source project built on top of Kubernetes, Kyma Runtime is a fully managed Kubernetes-based runtime that allows partners and customers to build extensions by using both microservice and serverless functions.
Steps:
We’ll follow this 6 steps approach to run our container on Kyma Runtime.
- Follow all the steps from our previous article.
Create the python source code (helloworld.py)Create a Dockerfile file (Dockerfile)Build the docker image (hello-world-python)Run the image in a containerPush the image to docker hubPush the docker image from docker hub to SAP Cloud Platform
- Install Kubernetes command-line tool, kubectl and enable Kubernetes in Docker Desktop
- Create a deployment.yaml file.
- Deploy on Kubernetes installed locally (Optional Step )
- Deploy on SAP Cloud Platform, Kyma Runtime using Kyma Console
- Create APIrule and test our application.
Installation
Docker Desktop is already installed ( assuming you completed the previous article).
Enable Kubernetes in Docker Desktop.
Goto Docker Application installed on the machine and enable it.
Install kubectl (Kubernetes Command Line Interface), I found it here.
https://storage.googleapis.com/kubernetes-release/release/v1.20.0/bin/windows/amd64/kubectl.exe
After installation verify your kubectl is configured. At the command line, type the following:
kubectl version
Now you are working with Kubernetes! You can see the node by typing:
kubectl get nodes
Deployment.yaml
Now let’s begin the action. Create a file named deployment.yaml and add the following contents to it and then save it:
apiVersion: v1
kind: Service
metadata:
name: helloworld
labels:
app: helloworld
spec:
ports:
- name: http
port: 3333
selector:
app: helloworld
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld
spec:
selector:
matchLabels:
app: helloworld
replicas: 4
template:
metadata:
labels:
app: helloworld
spec:
containers:
- image: ravimittal/hello-world-python-image
name: helloworld
ports:
- containerPort: 3333
This YAML file is the instructions to Kubernetes for what you want running. It is telling Kubernetes the following:
- You want a load-balanced service exposing port 3333
- You want four instances of the helloworld container running
Deploy Locally ( Optional Step )
Use kubectl to send the YAML file to Kubernetes by running the following command:
kubectl apply -f deployment.yaml
You can see the pods are running if you execute the following command:
kubectl get pods
Deploy on Kyma Runtime
Now it’s time to run the container on SAP Cloud Platform, Kyma Runtime.
Go to SAP Cloud Platform Cockpit, and use Console URL to open Kyma Console ( Under Kyma Runtime Tab )
Follow the article on Developers.sap.com to Enable SAP Cloud Platform, Kyma Runtime, and create Dev namespace.
https://developers.sap.com/tutorials/cp-kyma-getting-started.html
Within next few seconds after deployment, you will see 4 Pods are running. Hope you remember in the Deployment.yaml file we instructed runtime for 4 instances.
Click on Pods to see our container details.
On the right side of the above screen, click on three dots, you will get the option to Delete the POD.
Delete it, you will see that runtime automatically creates a new POD.
That’s it! We got our containers running on SAP Cloud Platform, Kyma runtime.
But something is missing unless we see some output/result from our container/application.
Here we can create another YAML file or we can use the Kyma console to create APIRule to access our container app.
Enter any Name and Hostname and Create API Rule. You will get the URL under Host on the next screen.
Click on this URL, or copy/paste in any browser, and you will see our application running. 🙂
Now that’s the end of our article. Try yourself and share your queries and feedback.
Thanks for reading!
Hello
Thank you for post.
Do you have any example with docker hub private repository deployment to kyma ?
Thank you
Thanks, Sinan As of now I don't have any such example ready.
But I'll get back to you if I found one.
Hello Ravi
I could deploy with kubectl commands docker hub private registry i will share blog.
Thank you
Thanks, Sinan. It would be very helpful.
Amazingly simple and step by step explanation, very well done!
quick question: The image registry always refers to the docker hub by default? Is it possible to host the image in a different registry and refer in the deployment.yaml file ?
Thanks for the post. It's simple and easy to implement.
Thanks Ravi Mittal. Great post!
Hi Ravi
Both your blogs simple and great
I succeeded
Try my Kyma curry in SAP BTP
https://ojnc.c-2c130b3.kyma.ondemand.com/
One suggestions - please include a step where MINIKUBE on own PC/Linux/Mac used; this gives good view of Kubernetes and usage of kukectl
before attempting BTP KYMA
PC needs Windows 10 PRO and I find it easier to try Linux (my opinion)
I think Kyma is a fast moving target
I arrived at main link and got lost
https://dashboard.kyma.cloud.sap/cluster/shoot--kyma--c-2c130b3/overview
Until I noticed namespace selection on the top right
Then I saw promised land!
After that I got "Hello World!"
Your write up was simple and great!
Regards
Jayanta