Technical Articles
Kyma for Dymmies: First Simple App in SAP Cloud Platform, Kyma runtime
Very easy first steps for beginners to get started with SAP Cloud Platform, Kyma runtime
I’m not yntelligent.
Not skylled.
Not familiar with Lynux
Not understand Kyma docu
But: I like cats
Altogether: I’m not in a good position for using Kyma
Nevertheless…. I managed a little bit
And now, I’d like to share that little bit with the small crowd of Kyma beginners who feel like me
Making the learning as easy as possible, without cool but confusing options – so easy that even a dymmie like me would be able to follow
Nevertheless, it is still a quite long journey
So what I’d like to do today:
Create a first silly app in SAP Cloud Platform, Kyma runtime
Learn how to use docker and Kyma
Not learn Linux – we use our good old windows
Overview
- Application
- Create app
- Run app locally
- Docker
- Install
- Containerize our app
- Docker Hub
- Kyma
- Dashboard
- Deploy our app
0. Unplanned
What is Kyma?
I don’t know it and don’t dare to explain, but it lets you work with Kubernetes in SAP Cloud Platform
What is Kubernetes?
Something very cool and modern and complex and it lets you create apps in the cloud.
It does many things very good and is very open and flexible and it makes your life complex.
That’s why smart people created Kyma
Which is still kind of complex for my small brain
Kubernetes is so open for anything, that it expects from us that we don’t deploy apps, but containers
What is a container?
It is like a very small computer and it contains our application including all required software like programming language and operating system
We create container with docker
What is docker?
It is very cool and popular software to work with containers.
We use it to containerize our application
What is our application?
OK, let’s go ahead
What is ahead?
It is you… getting on my nerves
0.1. Prerequisites
To follow this tutorial, you should have:
- No clue about Kubernetes, Kyma, Docker, Linux
- No expectations about great results
- No worries about wasting your time
- Instead: lot of patience
- And you should have access to the SAP Cloud Platform, trial account
1. Application
The first step of our journey is to create an application – the app which, at the end of the day, we want to see running in Kyma
1.1. Create Application
As promised, we create the most simple app that I can imagine:
It is just a command that prints stupid text to the console
Here’s the source code:
echo --- meaow ---
Ok, that’s all about our app.
For our tutorial, we also need a working directory
So let’s create a folder C:\tmp_kyma
1.2. Optional: Run Application
Now we might want to test our app.
We open a command prompt (see appendix)
Insert our app code
Press enter and see result
OK, so far we’ve created and tested our application
Next step is to containerize it
Where are we?
App -> Docker -> Kyma
2. Docker
We need docker in order to create a container and to put our application into the container.
The container is required by Kubernetes/Kyma
In this chapter we’re going to download and install docker, use docker and upload our container to the public repository
2.0. Prerequisite
OK, I have to correct myself:
There’s a little prerequisite before we start working with docker
We need to sign up at Docker Hub
I guess it can be avoided, but would require additional configuration steps and we don’t want that, we want to learn the convenient way of working with Kyma
What is Docker Hub?
Docker Hub is a repository which …. ehm…we explain later
For the moment we just sign up, to fulfill the 2.0. prerequisite
First sign up at https://hub.docker.com/signup
We choose a docker ID which is not too silly, as it will identify ourselves in public, and not too long, because we will have to type it later.
Then the usual submit – check private mail account and confirm
Optional:
We can enter our own docker hub account and have a look there: https://id.docker.com/login
2.1. Installation
We have to install docker on our laptop.
Don’t worry, I’ve done that on my Win 10 laptop and it worked without any issue
Docker help: start and instructions
First we need to download the installer .exe file (Direct link)
Then run the installer by double clicking the downloaded exe file
After installation, docker will be started in the background
How to see?
Hint: watch out for the whale…
Sorry, wrong icon…
See below the right one to search in windows taskbar
The poor whale, carrying so many heavy containers…. Although… docker is optimized for very lightweight containers – you’ll see it in a minute
To verify the installation, you can type a sophisticated command with thousand optimized options ….. or just type docker without any option.
If docker is properly installed, it will give an error …. Due to missing sophisticated options…
Like here:
Login
To enable the docker tool to interact with our docker-hub-account, we have to login from our installed docker to our account
To do so, right click on the whale-icon in the toolbar, then choose “Sign-In” from the context menu
In the dialog, we enter our Docker ID and password, as registered in the chapter 2.0.
2.2. Containerize our App
Happy that docker is running and giving error…
So what now?
Already forgot why we installed docker?
We want to containerize our application
Or, using my dummy words:
It is like having a little computer and installing our application on it.
Afterwards, we can hand over this little computer to our friends and they can just start the little computer and enjoy our app
It makes clear what’s the advantage:
Friends don’t need to install the app, including all prerequisites (they would anyways never install so stupid app), they just turn on the little computer, and the app starts running
Less work for our friends, more work for us
Same with docker.
Less work for Kubernetes, more work for us
OK, now it is time to correct myself:
The container itself is something that is active and can be run
However, a container is based on an image
No container without image
And that’s what we need to create and what we will send to Kubernetes/Kyma:
An image
Sorry, not that kind of image…
OK, now it is time to correct myself:
It is not really us who create the image: it is docker
What we do, we create a description for the image
The description is written in a file
Ok, now it is time to… start writing
Next: create description
A docker image is described in a file
The file is a normal text file and we use docker-commands (similar like Linux commands)
The file is like a script
The image which we create is based on an existing base-image.
In our example, the existing image contains an operating system
OK, now it is time to create a file.
In our working directory, we create a file with name Dockerfile
We paste the following content
FROM ubuntu
CMD echo "--- meaow ---"
Our first docker description is very small and easy to understand
We declare that we want our image to be based on an existing ubuntu image
Yes, it could have been windows, but we want a small fast operating system
The second declaration: the start command (CMD) which is executed when the docker container starts
Usually, an application is started
And that’s what we do: we declare that the “echo”-command should be executed when the container starts
BTW, see appendix for the whole content of all sample project files
Next: create image
Now that we have defined the description, we can create the image based on it
OK, it is time to correct myself: we need to use command prompt
There’s no UI
OK, I have to correct myself:
There’s a tool “Docker Desktop”, but it can be used only for viewing
But no prob, using command line command is easy
We open command prompt and jump into our working directory
cd c:\tmp_kyma
Then we execute the docker command for creating an image
The command is called build and it requires one argument and one optional parameter
The mandatory argument tells the build command in which directory to find the Dockerfile
The optional parameter –tag allows us to specify a name (and a tag, but today we don’t need a tag)
We need to specify this name in a specific way:
<existingDockerID>/<desiredImageName>
That’s why above I mentioned to choose a short docker ID
This qualified name makes our image unique.
The docker ID and the slash could be omitted, but today we need the unique name
Why?
Yes, we need
So now we can execute the build command.
Note:
Make sure to replace “kitty” with your own docker ID
docker build c:\tmp_kyma --tag kitty/kittyimage
Alternatively, we can replace the full path with a dot, if our current directory contains the Dockerfile
And we can shorten the parameter
docker build . -t kitty/kittyimage
It should look like here:
We can see that docker is very fast
OK, so now we have created an image
2.3. Optional: Run Application
— This step is not mandatory for deployment to Kyma —
The image is only an image. Like a cat image, we can look at it, but not play with it
Our new image contains our app, so to test our app we have to test the container
With docker, create and run a container is one command:
The command is called run
It takes an argument, the image name (including dockerID)
OK, now we can run the container (make sure to replace the docker ID with yours)
docker run kitty/kittyimage
While executing the command, docker creates a container, runs it and executes the start-command which we had specified in the Dockerfile
And here we can see the output:
As such, our application has been executed.
Afterwards, the container has been shut down.
Altogether, it has been really fast.
Note that our container is really silly and small, but even taking that into account, it is still fast
Recommendation:
You should go to the Appendix and have a look at a few common docker commands
Note:
We’ve created at least one docker image and container, they waste space on our laptop, we should delete them
2.4. The public repo
The public repo is called Docker Hub
It can be found here: https://hub.docker.com/
There are many many useful images (like ubuntu) already available on the public docker repo.
So now what we’re going to do: add a completely useless image to the repo
In the previous step we’ve created an image which contains our silly app
Now we upload it to the public repo and make it available for everybody
Why we do that?
Nobody needs or useless image
But we don’t do it for others, we do it for us:
Kyma/Kubernetes is optimized to download images from docker hub
Now we upload our silly image to docker hub
We use the push command followed by the qualified name of our image
(make sure to replace….)
docker push kitty/kittyimage
Why has it been possible?
Because we configured docker with our docker ID and our password
Small recap
We’ve written a Dockerfile which contains the description of an image
We’ve created an image
We’ve run a container which executed our app
We’ve uploaded our image to docker hub
Smaller recap
Dockerfile -> image -> container -> hub
Where are we?
App -> Docker -> Kyma
3. Kyma
Finally we’re going to see Kyma in action
As promised, it is easy
3.1. SAP Cloud Platform
SAP Cloud Platform, Kyma runtime is part of the platform and accessible in Trial account.
It only needs to be enabled
Enable Kyma
First step is to enable Kyma in our Trial account.
Very easy:
Log in to the Trial account and step into the subaccount
Search for the button “Enable Kyma”
Then press it
That was easy
This will provision a Kubernetes cluster – which takes time….
Much time…
…
OK, now it is time to correct myself:
Enabling Kyma is not enough
As usual, we need to have required roles before we can access the Kyma dashboard
Assign Roles
To assign roles to our user, go to subaccount, expand “Security”, press “Role Collections” and create a new Role Collection
Add the 2 Kyma-roles to the collection
In addition, assign your cloud-user to the role collection
Save the changes
That’s it.
Has been easy as well
Open Dashboard
After enabling Kyma and equipping our user with the required roles, we can go ahead and finally enter the Kyma world
To open the Kyma dashboard, we just need to press the link on the subaccount overview page
OK, I need to correct myself:
Actually, the Kyma dashboard is called “Kyma Console”
Here it is:
In my screenshot, I have an additional namespace, which is not required for our tutorial
OK, that was easy
Play with Kyma
Click here and there
OK, that was easy
Where are we?
App -> Docker -> Kyma
3.3. Deploy App
We can use the Kyma Console to deploy apps.
Of course, after passing the status Kyma-Dymmie, you’ll use the command line client to work more efficiently with Kyma/Kubernetes
Create deployment descriptor file
OK, I have to correct myself
We don’t really deploy apps
Remember? We aren’t dealing with apps, we’re dealing with containers
Cool – we use Kyma to deploy the container
Hum, I have to correct myself
We don’t move a container from our laptop to Kyma
Remember? We pushed our docker image to docker hub
Now we tell Kyma to download that image
Then Kubernetes starts the container based on that image
That’s much cooler
Yes.
There are many advantages in the Kubernetes dev paradigm, I’m Dymmie, I don’t know them
But we can feel one big advantage: Kubernetes can create containers based on the downloaded image, as many as it wants, and whenever it thinks that it is required (e.g. for disaster recovery or load balancing, or just for fun)
So if we don’t deploy any app nor any container, what do we have to do?
We have to give some metadata, e.g. which image to use
This is done in a deployment descriptor file
OK, so now we create a file called deployment.yaml in our working directory
The content of the file is written in yaml format, so be careful when copy&pasting
Note: Make sure to adapt your docker ID
apiVersion: apps/v1
kind: Deployment
metadata:
name: kittyapp
spec:
selector:
matchLabels:
templatename: kittytemplate
template:
metadata:
labels:
templatename: kittytemplate
spec:
containers:
- image: cacoco/kitty
name: mykittyapp
BTW
It is recommended to use Visual Studio Code with installed extensions for Docker and Kubernetes
Explanation
What we deploy to Kubernetes are typically resources
So we have to say what kind of resource we’re deploying. In our case, it is of kind “Deployment” descriptor
Basically, we specify that the deployment is based on an docker image with specified name
We can see that the image is used as template
Why template?
I guess because Kubernetes will use the template for creation of containers whenever it is in the mood
Deploy
In the Kyma Console, there’s a button “Deploy new resource”
Try to find it….
Once you’ve found it, press it and browse for our deployment.yaml file and press “deploy”
Note:
In case you get an error like me: “Invalid file extension”….. then you can try to circumvent like I did:
Rename the file from deployment.yaml to deployment.json, without converting the content to json
That worked for me. File extension must be json, content must be yaml – strange misunderstanding between validators….
View our app output in Dashboard
After only few seconds deployment has finished
Now we want to see the output of our application
In the Kyma Console, we go to Operation->Deployments, where we can see that our deployment is red.
We don’t like that, so we ignore and leave quickly
We go to Operation->Pods
We can see a green “Running” – the red rest we can ignore…
What is a Pod?
Let me try a silly explanation:
-> Our app is in a container,
-> container in a pod
-> pod in a node
-> node in a cluster
-> cluster in a data center
-> data center in the world
OK?
Silly, but good for dymmies
Now finally we want to see our app result
We click on the context-menu of the pod (try to find it), then “Show Logs”
There it is:
That was easy
We can see that our app is running
OK, I have to correct myself:
Our app is not running, it was running
Our docker container was built in a way that it starts, runs the echo command and exits
And that’s the reason why everything is red in our Kyma
You also must have seen that Kubernetes is wondering why our container exits –
Wondering?
Yes, because Kubernetes keeps restarting it (we can see the number of restarts)….
Isn’t it funny?
No
Not funny?
Ok, then we just delete the pod – via the context menu (the three dots . . .)
You see what happens?
We get another pod…
Ups?
Hehe, I knew that in advance and wanted to let you experience it
That was disaster-recovery in action
Cool, isn’t it?
Absolutely super cool
Where are we?
App -> Docker -> Kyma
We’re done with the tutorial
Optional: explore Kyma
OK, in this chapter you have 5 minutes for exploring…
That was easy
At the end, we delete our silly deployment:
Operation->Deployments
Choose the context menu of our deployment and press “Delete”
Wait to see if it gets re-created…?
No, not always
Check the Pods:
Our pod gets deleted as well
And after few more seconds, this tutorial will be done
Done
Now
Finally…
Summary
In this tutorial we’ve done our very first steps to work with Kyma
The goal was to see an app running in Kyma, with minimal effort
Instead of writing an app in a fancy programming language, we’ve just used a simple command, which made everything shorter and simpler
We’ve learned basic steps to deal with docker
Enough basic steps to containerize our app (more steps in the appendix)
We’ve learned basic steps in Kyma Console
Enough steps to “deploy” our app
To make things easier, we haven’t covered the Kyma command line client (lucky you: there’s an appendix)
Links
Kyma
- Intro blog post
- Native Kyma project page
- SAP Help Portal Kyma docu
- SAP Help Portal Kyma Trial
- Discovery Center Kyma
Docker
- https://www.docker.com/get-started
- https://www.docker.com/101-tutorial
- https://docs.docker.com/docker-for-windows/#where-to-go-next
- https://hub.docker.com
- https://www.docker.com/products/docker-hub
- https://docker-curriculum.com/
Conclusion
If I’ll ever have a second cat, I will call it Kyma….;-)
If you faced any issues, please don’t let me know – remember that I’m dymmie and not expert
There are many experts around – but they won’t hit this blog post
Alternatively, you may refrain from sending me feedback messages in a container uploaded to docker hub
Nice idea though
Next Step
See one more blog post which shows how to create a REST service based on Node.js and how to secure it with OAuth:
https://blogs.sap.com/2020/12/10/kyma-for-dymmies-2-first-simple-microservice-with-security/
Appendix 1: Sample Code
Dockerfile
FROM ubuntu
CMD echo "--- meaow ---"
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: kittyapp
spec:
selector:
matchLabels:
templatename: kittytemplate
template:
metadata:
labels:
templatename: kittytemplate
spec:
containers:
- image: cacoco/kittyimage
name: mykittyapp
Appendix 2: Command Prompt
How to open command prompt in windows:
Press: Windows key + S
Then type: cmd
Appendix 3: Docker Commands
To create an image:
docker build -t test1 .
To create and start a container with desired name:
docker run –name myname myimage
To list running containers, -a shows even stopped container:
docker ps -a
Run container and allow to execute commands: interactive mode
interactive: -it , specify port mapping: -p: below: 5051 on my laptop, 5050 in the container:
docker run –name -it -p 5051:5050
Run in detached mode, console doesn’t wait: -d detached:
docker run -d –name name image
View all images
docker images
View logs
docker logs <container>
open bash inside of container:
docker exec -it containerName /bin/bash
Upload image to docker hub:
docker push <your-docker-id>/<image>
To stop a running container:
docker stop <container>
To start a stopped container:
docker start <container>
To delete a container. If no name was given, view the container ID with ps
docker rm <container>
Delete an image
docker rmi <image>
Set env variables to run command:
docker run -e ‘VAR1=abc’ -e ‘VAR2=123’ …
Info
docker info
Appendix 4: Kyma Command Line Client
Download:
https://kubernetes.io/docs/tasks/tools/install-kubectl
Install:
On that website, it is described how to install
After installation verify:
Open command prompt and execute the command without arguments: kubectl
It should print the help page
Download kubeconfig:
The kubectl tool needs to be configured with the kubeconfig file
This allows the CLI to login to Kyma, as the file contains the token
The kubeconfig file has to be downloaded from the Kyma Console UI
It can be found in the user menu:
Configure kubeconfig
The kubectl tool needs to find the config file. As such, we have to set the environment variable with name KUBECONFIG
The value of the variable has to point to the path of the config file
In your windows system, open control panel, go to System Properties -> Environment Variables
Note:
The token which is in the kubeconfig file expires after 8 hours
As such, whenever the command line throws an error due to login, the file has to be downloaded again
Useful commands
Print client version:
kubectl version –client
View kubeconfig content:
kubectl config get-contexts
Get pods info for current namespace:
kubectl get po
Get pods info for dev namespace:
kubectl -n dev get po
Get deployments in dev namespace:
kubectl -n dev get deployments
Get services:
kubectl -n dev get services
Delete deployment:
kubectl -n dev delete deployment <deployment>
Describe deployment:
kubectl -n dev describe deployments <deployment>
Create deployment:
kubectl -n dev create -f deployment.yaml
Update deployment:
kubectl -n dev apply -f deployment.yaml
Logs:
kubectl -n dev logs <podname> -c <containername>
More info:
Hi Carlos, you are very humble and your little knowledge of kyma becoming a great learning series for tomorrow. I have marked this series and will follow... if I can steal a few bit of your little knowledge 😉
Thank you so much for sharing on this topic.
Hi Somnath Paul ,
you know there's a saying: one who has nothing, has nothing to lose...;-)
So you steal as much as you can - I'm not worried 🙂
Thanks so much for your comment - I'm really glad if it helps a bit !!
Cheers, Carlos 😉
Cool blog Carlos!
Small typo me thinking :
Is it right?
Hello Andrei Vishnevsky ,
thanks very much for your feedback and for your thorough reading!
True, and I've corrected the typo
The usual copy&paste error...
Thanks again for pointing out and pls keep sending feedback
Cheers, Carlos 😉
😉 I'd say it's not 'default', it's 'current' namespace. There is a 'default' namespace in Kyma. And when you switch the namespace to something else, the above command will not return pods from 'default' namespace.
super, good catch! Thanks again for pointing out!
Cheers, Carlos 😉
Thank you Carlos, very nicely explained.... thank you.
Thanks so much Former Member !
Hi, Carlos thank you for such a great blog. I faced 1 issue while creating the role collection as there are no roles related to kyma available due to which I am unable to open the kyma console. Do I need to configure them manually, If yes how?. I am using a trial account for this.