SUMMARY
In this content, the basic steps of how to publish a Docker image on Kubernetes, which has been open-sourced by Google, are explained. Brief information about how this image published using Kubernetes can be scaled is also provided. A Java Spring Boot application, which has a static page, is selected from the Buildpacks community on GitHub as an example used. This Spring Boot application with a static page is created to run on port 8080 inside a container. Information is provided on how to configure your own computer and install command-line tools during the time until the application is published on Kubernetes. The operations performed during publication are carried out on the Ubuntu 20.04 LTS distribution.
1. GENERAL INFORMATION
1.1. Introduction
Today, solving a problem with the microservices approach instead of developing applications in a monolithic way is considered a more acceptable solution. Google employees, influenced by the Borg system developed for the company, developed the Kubernetes tool as open-source software to address clustering problems that emerged with applications developed with the microservices approach. It is recommended to be familiar with the concepts of the Linux operating system and to have knowledge about containerized systems to understand what is described in this content. To grasp the working principle of Kubernetes, which is independent of the clustering logic of developed applications, it is explained to the reader.
2. TECHNOLOGIES
2.1. Virtualization
It is the process of abstracting computer resources from the user. This process enables the merging or sharing of computer resources. There are several types of virtualization. Container technologies also work with virtualization logic.
2.2. Docker
It is computer software that enables virtualization at the operating system level. It allows running software images called containers. There are other alternatives as well (CRI-O, rkt, containerd, etc.). It is preferred as a new virtualization technology because it is much lighter than virtual machines that were used for virtualization purposes in the past.
2.3. Kubernetes
Kubernetes is a tool that scales, manages, and automatically deploys containerized applications. The word Kubernetes comes from the Greek language and means helmsman or ship pilot. Kubernetes, widely known as "k8s (pronounced as Keyts)," is also known as "k8s (pronounced as Keyts)" for common usage. The reason for this is that there are eight characters between the "K" at the beginning and the "s" at the end. Kubernetes was largely developed by being influenced by the Google Borg system. It is being developed as an open-source container orchestration tool in Go language and is released under the Apache License version 2. Currently, almost all cloud computing service providers under CNCF support Kubernetes.
2.3.1. Why Kubernetes?
With the transition from virtual machines to container technology in virtualization, a great revolution has taken place. However, something was missing in this revolution. Containers may stop working, the system may be inadequate, containers communicating with each other may encounter various problems. Container orchestration systems were developed to solve all these problems. Docker Swarm, Kubernetes, Apache Mesos, Amazon ECS... However, Kubernetes, which is almost supported by every cloud service provider, became the only orchestration system supported. With its transfer to CNCF, a sub-organization of The Linux Foundation, it gained more trust in the eyes of service providers. The biggest factor in its preference can be seen as the support of many cloud service providers behind it.
2.3.2. Kubernetes Objects
2.3.2.1. Node
They are virtual or physical machines on which Pods run.
2.3.2.2. Cluster
It refers to all nodes managed by Kubernetes. A cluster must have at least one worker node and one master node.
2.3.2.3. Namespace
Kubernetes allows running multiple virtual clusters under a real cluster. Each virtual cluster is called a namespace.
2.3.2.4. Pod
The pod means "whale herd" literally. It is the smallest deployment unit in Kubernetes. A pod can host multiple containers. In addition, each pod in the local network created by Kubernetes has a unique IP address.
2.3.2.5. Service
It works like a layer of multi-layered applications. Services logically group pods and provide them as services to the outside world.
2.3.2.6. DaemonSet
It ensures that a pod is run on each node.
2.3.2.7. ReplicaSet
ReplicaSet ensures that the number of replicas defined when horizontal scaling is desired is kept constant.
2.3.2.8. Deployment
It is used to deploy and update the application. It uses ReplicaSet in the background.
2.3.2.9. Persistent Volume
It is the object we communicate with the cluster to store data permanently. It cannot be managed on the cluster side.
2.3.3. Node Components
2.3.3.1. Container Runtime
A container runtime software must be available on the node to run containers in pods.
2.3.3.2. kubelet
It runs on each node and monitors node statuses. It shares the information it obtains with master node(s).
2.3.3.3. kube-proxy
It creates the Kubernetes network. It assigns IP addresses to pods. It provides load balancing capability to all pods published under a service.
2.3.4. Master Node Components
2.3.4.1. etcd
It is a depot where all settings and statuses maintained on Kubernetes are kept using the key-value logic. When the value of a configuration or state changes, the old value is not deleted, the new value is added to the depot additionally.
2.3.4.2. kube-scheduler
It determines on which nodes the created pods will be kept. It provides resources to workload requests.
2.3.4.3. kube-apiserver
It provides the configuration of objects such as pods, services. It is a RESTful API service. It routes incoming requests and performs operations.
2.3.4.4. kube-controller-manager
It manages the controller objects within Kubernetes. The controller is an object that examines a state through the apiserver and ensures that it is maintained at the desired level.
3. APPLICATION
The application was implemented on the Microsoft Azure Cloud Computing Service. To perform the application, you need to have the following two command-line tools on your machine:
- docker-cli (Docker Command Line Interface)
- git-cli (Git Command Line Interface)
- pack-cli (Buildpacks Command Line Interface)
- kubectl (Kubernetes Command Line Tool)
- azure-cli (Microsoft Azure Command Line Interface)
Applications on Kubernetes are published as container images within Pods. If you already have a container image ready, you can skip the first step. In the context of the application, an example Java Spring Boot application will be turned into a Docker image and published on Kubernetes on port 80.
3.1. Installations
3.1.1. docker-cli
Docker-cli is an interface that comes automatically when you install the Docker engine. Therefore, you need to install the Docker system completely on your computer.
First, remove old versions with the following command:
Then, install the necessary packages to be able to install from the repository:
Download Docker's GPG key to your computer:
Add Docker's repository service to your repository pool:
Finally, perform the installation:
You can check if the installation was successful with the following command:
3.1.2. git-cli
You can download the Git command line interface directly to your computer using the following command:
You can check if the installation was successful with the following command:
3.1.3. pack-cli
pack-cli is an interface provided by Buildpacks for easier use of packages.
First, add the pack-cli repository service to your repository pool using the following command:
Then you can perform the installation using the following commands:
You can see if the installation was successful with the following command:
3.1.4. kubectl
kubectl is a command-line tool developed to manage your Kubernetes configurations.
First, download the latest version:
Download the checksum file to your computer and perform a comparison:
If the comparison is successful, you can install the kubectl tool on your computer with the following step:
You can check if the installation was successful with the following command:
3.1.5. azure-cli
azure-cli is a command-line interface developed to manage Azure Cloud Computing Services.
You can perform the installation with a single command using the following script:
You can check if the installation was successful with the following command:
3.2. Creating a Docker Image
You can clone the sample application from the CNCF Buildpacks GitHub account using Git with the following command:
Then, navigate into the examples directory and use the buildpacks-cli to create a Docker image:
If your image is created successfully, you will receive the following message.
You can use the following command to check your images:
If you see your spring-kube-ornek image among your images as shown in the picture, your image has been successfully created.
To upload your created image to your own docker account, you can use the following command:
We will use the docker registration system when providing the image on Kubernetes. Optionally, different registration systems can be used, but you may prefer to use the docker registration system for universality. Uploading your image to a remote server can take a long time. Therefore, you can use the image I offer publicly below.
İmaj: fatiiates/seminer-test:test
3.3. Microsoft Azure
To log in to your Azure account via the command line, you can use the following command.
After entering the command, you can log in to Azure through your default web browser.
After logging into your account, customize the following command to create a new cluster.
If the cluster is successfully created, it will return data in JSON format as output.
Then, use the following command to configure the kubectl tool installed on your local machine with Azure.
If configured successfully, along with the following command, you will be able to list the nodes you have.
3.4. Deploying Applications with Kubernetes
The easiest way to deploy an application with Kubernetes is to create a deployment as described above. Since the application we will deploy contains only a static web page, we can deploy it very easily.
First, let's create a deployment that allows us to publish our image with the kubectl tool. You can use the docker.io/fatiiates/seminar-test:test value for the image path.
The above command will create a pod for us and run the docker image we provided as a parameter inside it. Therefore, you should be able to see your pods with the following command.
Note: It may take 20-30 seconds to switch to Running status.
You can see the deployment component you created with the following command.
As seen, we have an image running on the node right now. You can now make this image publicly available through a service.
With the following command, you can create a load balancer service, allowing our image running on port 8080 to be exposed to the outside world on port 80.
After receiving the message "service successfully created", shortly after, the service will be exposed via a static IP (EXTERNAL IP). You can obtain the externally open IP address with the following command.
When you enter the IP address obtained above into your web browser, the static page will now be displayed.
Finally, let's see how easy it is to scale your application when needed.
When you see the message "deployment scaled", your application is in a scaled state. The scaling operation was completed within seconds, but make sure you have made a healthy cost calculation while performing this operation.
4. RESULTS
Thanks to Kubernetes, we have published the container image we created earlier in a cloud service provider within minutes. Kubernetes has provided a permanent solution to problems such as the collapse of applications under heavy load that have been going on for years. Nowadays, Kubernetes has become a powerful tool behind many companies, firms, funds, banks, etc. With its open-source nature and the ability for teams using it to customize it according to their needs, it has become an indispensable orchestration tool.
5. DISCUSSION
- Orchestration systems should be preferred in systems where the number of containers is high and scalability is important. For example, in areas where scalability is critical, such as web applications of E-Commerce stores, ÖSYM web applications, etc., orchestration systems should be preferred.
- Although the system that emerges is highly scalable and reliable, it puts forward a system that can easily exceed the payment for a host in a very short time from an economic point of view. Although Kubernetes is an advanced orchestration system, it will not be an ideal choice for small-scale web applications.
6. RESOURCES
- https://medium.com/devopsturkiye/openshift-nedir-188aa22934a3
- https://kubernetes.io/
- https://docs.docker.com/engine/install/ubuntu/
- https://git-scm.com/downloads
- https://buildpacks.io/docs/tools/pack/
- https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
- https://docs.microsoft.com/tr-tr/cli/azure/install-azure-cli
- https://kubernetes.io/docs/home/
- https://docs.docker.com/
- https://github.com/buildpacks/samples/tree/main/apps
- https://azure.microsoft.com/en-us/
- https://www.cncf.io/
- https://buildpacks.io/docs/
- https://discuss.kubernetes.io/t/kubernetes-slide-deck-template-revealed/2563
- https://learning.edx.org/course/course-v1:LinuxFoundationX+LFS158x+3T2020/home
- https://discuss.kubernetes.io/t/kubernetes-slide-deck-template-revealed/2563
- https://kubernetes.io/docs/reference/kubectl/cheatsheet/
- https://www.youtube.com/watch?v=fvVNWgD8HSg
- https://github.com/cncf/presentations/tree/master/kubernetes
- http://slides.eightypercent.net/kubernetes-101/#13
- https://kubernetes.io/case-studies/appdirect/
- https://www.youtube.com/watch?v=rpB7KygMaVo
- https://azure.microsoft.com/tr-tr/topic/what-is-kubernetes/#features
- https://medium.com/devopsturkiye/kubernetes-nedir-f4a6f326d036
- https://medium.com/devopsturkiye/kubernetes-nedir-eb5c5d149e69
- https://www.manning.com/books/kubernetes-in-action
- https://kubernetes.io/docs/tutorials/kubernetes-basics/
- https://www.redhat.com/en/topics/containers/what-is-kubernetes
- https://enterprisersproject.com/article/2017/10/how-explain-kubernetes-plain-english
- https://en.wikipedia.org/wiki/Kubernetes
- https://medium.com/codable/kubernetes-d090867428ca
- https://www.okd.io/
- https://www.youtube.com/watch?v=r6RvlMfH-KU
- https://www.youtube.com/watch?v=x6jje4w3ZEs
- https://kubernetes.io/docs/tasks/configure-pod-container/
- https://docs.microsoft.com/en-us/azure/aks/concepts-clusters-workloads
- https://codelabs.developers.google.com/codelabs/cloud-springboot-kubernetes#1
- https://docs.microsoft.com/tr-tr/azure/aks/kubernetes-walkthrough
Sources
DISCLAIMER
This document is translated from Turkish to English using ChatGPT. The original document is written by the in Turkish. The translation may contain errors and inaccuracies.