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.
I’ll briefly explain all the terms we are using in this article.
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 is an open-source container orchestration engine for automating deployment, scaling, and management of containerized applications.
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.
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 container Push the image to docker hub Push 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.
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.
After installation verify your kubectl is configured. At the command line, type the following:
Now you are working with Kubernetes! You can see the node by typing:
kubectl get nodes
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.
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!