Kubernetes - Container orchestration
Introduction
Kubernetes (or K8s) is an open-source system used for container orchestration. Indeed, it complements container applications such as Docker. It permits the consistent deployment and management of containers. Kubernetes was developed by Google and later donated to the Cloud Native Computing Foundation. The first version was released in July 2015.
Compatibility
At the beginning, Kubernetes was only compatible with Docker. Over time, Kubernetes became able to work with other container applications such as rkt. To accomplish this, they introduced an interface called the Container Runtime Interface (CRI). It allows any application to work with any container application as long as they adhere to the Open Container Initiative (OCI) standards.
The Open Container Initiative (OCI) consists of an imagespec and a runtimespec :
- imagespec : It defines the specifications on how an image should be built.
- runtimespec : It defines the standards for how any container runtime should be developed.
However, Docker is not compatible with Container Runetime Interface because he has been developed before the Open Container Initative standars. So, Kubernetes had to adapted their application for the CRI and Docker as well. To be able to support, they have set up dockershim.
A few years later, after an update, Kubernetes stopped support dockershim, and Docker was not supported anymore by Kubernetes for the runtime, but only for the imagespec because it followed the standard of OCI.
Architecture
The first thing we find in the architecture of container orchestration is the Node (prevously named Minions). A Node can be a physical or virtual machine where containers are run by Kubernetes.
You should have multiple Nodes to use Kubernetes properly. Indeed, if one Node fails, the others are still available to take over and keep the application running. This setup is called a cluster.
The Master Node should be set up to move the workload. The Master Node watches over the Nodes in the Cluster and is responsible for container orchestration.
Components
Kubernetes is composed of multiple components that are automatically installed when you set up it on your system :
- API Server : This acts as the front end for Kubernetes, managing and interacting with Nodes in the cluster ;
- Scheduler : It is responsible for distributing the workload and containers across the multiple Nodes in the cluster. When a new container is created, it automatically assigns it to a Node.
- Controller : It acts as the brain of this orchestration. Indeed, it notices and responds when Nodes or containers go down. It makes decisions about when new containers need to be brought up.
- etcd : It is a key-value store that holds all the information about the Nodes and Masters in the cluster ;
- Container Runtime : This is the software used to run containers (Docker in our case).
- Kubelet : It is the agent running on each node in the cluster. It ensures that the containers are running as expected on the Node.
In this setup, the Node having the kube-apiserver is designated as the cluster Master. Other Nodes, with the Kubelet agent, communicate with the master to share data and execute tasks upon request. Furthermore, components like etcd and the Scheduler are also present in the Master setup.
Configuration and Management Tools
To set up a cluster on Kubernetes, several important tools must be installed to ensure proper configuration and management of your cluster:
- Kubelet : As already explained above, Kubelet is an agent running on each Node in the cluster. It ensures that the containers are running as expected in the Node.
- Kubectl : Kubectl is the command-line interface used to interact with a Kubernetes cluster. It allows users to create, modify, retrieve information about, or delete resources.
- Kubeadm : Kubeadm is a tool designed to simplify the installation and configuration of a Kubernetes cluster. It allows you to designate which machines will function as the Master and which will serve as Nodes.
- Minikube : similar to Kubeadm but is intended for small-scale configurations. For example, if you want to run both the master and the node on the same machine, Minikube is the appropriate tool to use.
Debugging Containers Tool (circtl)
Kubernetes has its own command line tool named crictl, which is used to interact with container runtimes.
It is not used for deploying or managing but more for debugging container runtimes. Indeed, it works across different runtimes that are CRI compatible. The commands are quite similar to Docker.
- To pull an image, run the following command :
marijan$ crictl pull [IMAGE]
- To list existing images, execute :
marijan$ crictl images
- To get existing containers, run :
marijan$ crictl ps -a
- To execute a command inside a container, run :
marijan$ crictl exec -i -t [CONTAINER ID] [CMD]
- To view the logs :
marijan$ crictl logs [CONTAINER ID]
- To list pods :
marijan$ crictl pods
- To get low-level information on a container, image, or task, you can run the following command:
marijan$ crictl inspect [CONTAINER ID]
- To display a live stream of containers resource usage statistics, run:
marijan$ crictl stats [CONTAINER ID]
- To show the runtime version information :
marijan$ crictl version
Cluster Deployment (Linux)
In this section, I'll detail the deployment of my Kubernetes Cluster, including all the information regarding the tools and resources employed.
Prerequisites
Before proceeding with the installation of a Kubernetes cluster, it's essential to pre-configure at least two virtual machines and ensure they can communicate with each other.
In my setup, I've established two virtual machines running Debian 11 on a server equipped with VMWare ESXi. To manage networking, I've implemented a firewall configured to facilitate communication and provide access to these machines.
Installation
To set up Kubernetes on a Linux system, follow the instructions below:
1. Download the latest release using curl and the following information:
marijan$ curl -LO https://dl.k8s.io/release/$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl
2. Make the kubectl binary executable by running the executing :
marijan$ chmod +x ./kubectl
3. Move the binary to a specific path :
marijan$ mv ./kubectl /usr/local/bin/kubectl
4. Finally, check if you have installed the latest version :
marijan$ kubectl version --client Client Version: v1.30.0
Pods
When you deploy an application in a container, Kubernetes automatically creates a Pod, and the application is encapsulated inside it.
If you need to set up multiple instances of an application due to an increase in the number of users, you typically don't encapsulate the application in the same Pod, even if it's the same application running. Instead, you should create a new Pod with a new instance of the application.
However, you can have multiple containers in the same Pod if they are different types but complement each other.
For example, you might associate Nginx and MySQL containers within the same Pod. The Pod handles network connectivity, shared volumes, monitoring of application states, and more. Without these applications in your Pod, you would need to establish all these parameters manually.
Another benefit of using a Pod is that if you need to delete, for example, the web server, the associated database will be deleted as well.
With the kubectl command, you can list all of the Pods existing on the nodes, along with information such as their status, names, and more :
marijan$ kubectl get pods


