Getting Started with Kubernetes and Container Orchestration

Saurabh Dimri
Level Up Coding
Published in
7 min readJun 18, 2020

--

What is Kubernetes

Kubernetes or popularly known as K8s is a popular container orchestration tool, which runs over our containers ( created on any Container Engine e.g. Docker, Podman, CRI-O etc. ) and manages for automating deployment, scaling, and management of containerized applications.
Kubernetes clusters can span hosts across on-premise,public, private or hybrid clouds. For this reason, Kubernetes is an ideal platform for hosting cloud-native applications that require rapid scaling, like real-time data streaming through Apache Kafka.

Advantages of Kubernetes:

Apart from which we already saw, Kubernetes offers tons of other which make it a largely used and powerful container orchestration tool. Some of them are:

1. Service discovery and load balancing

No need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

2. Automated rollouts and rollbacks

Kubernetes progressively rolls out changes to your application or its configuration, while monitoring application health to ensure it doesn’t kill all your instances at the same time. If something goes wrong, Kubernetes will rollback the change for you. Take advantage of a growing ecosystem of deployment solutions.

3. Self-healing

Restarts containers that fail, replaces and reschedules containers when nodes die, kills containers that don’t respond to your user-defined health check, and doesn’t advertise them to clients until they are ready to serve.

4. Automatic bin packing

Automatically places containers based on their resource requirements and other constraints, while not sacrificing availability. Mix critical and best-effort workloads in order to drive up utilization and save even more resources.

5. Fault Tolerance

Kubernetes offers a high availability along with a great Fault Tolerance. It checks for the health of the Pods which holds the container launched from out Container Engine and knows when a pod is facing a downtime or is not functioning properly, manages and heal the pod or runs another with almost zero downtime.

Required Kubernetes Vocabulary:

Control plane: The collection of processes that control Kubernetes nodes. This is where all task assignments originate.

Nodes: These machines perform the requested tasks assigned by the control plane.

Pod: A group of one or more containers deployed to a single node. All containers in a pod share an IP address, IPC, hostname, and other resources. Pods abstract network and storage from the underlying container. This lets you move containers around the cluster more easily.

Replication controller: This controls how many identical copies of a pod should be running somewhere on the cluster.

Service: This decouples work definitions from the pods. Kubernetes service proxies automatically get service requests to the right pod — no matter where it moves in the cluster or even if it’s been replaced.

Kubelet: This service runs on nodes, reads the container manifests, and ensures the defined containers are started and running.

kubectl: The command line configuration tool for Kubernetes.

Let’s get under the hood…

Now as we know about the basic of kubernetes, let’s look on how the orchestration engine actually works

The Kubernetes architecture is majorly comprised of two things i.e. The Controller (control plane) and the compute machines (generally known as nodes).

Every node has its own environment and it could be either a physical machine running with bare metal OS or a Virtual Machine. Each node runs several pods, which are generally made up of a combination of containers running inside them.

The control plane is responsible for maintaining the desired state of the cluster, such as which applications are running and which container images they use. Compute machines actually run the applications and workloads.
This hand off works with a multitude of services to automatically decide which node is best suited for the task. It then allocates resources and assigns the pods in that node to fulfill the requested work.

The Desired State

The desired state of a Kubernetes cluster defines which applications or other workloads should be running, along with which images they use, which resources should be made available to them, and other such configuration details. It contains information about the administrative requirements provided by the architect for the desired number of pods running given a point of time, how many replicas are desired etc.

From an infrastructure point of view, there is little change to how you manage containers. Your control over containers just happens at a higher level, giving you better control without the need to micromanage each separate container or node.

Your work involves configuring Kubernetes and defining nodes, pods, and the containers within them. Kubernetes handles orchestrating the containers. Where you run Kubernetes is up to you. This can be on bare metal servers, virtual machines, public cloud providers, private clouds, and hybrid cloud environments. One of Kubernetes’ key advantages is it works on many different kinds of infrastructure.

Let’s Spin up some clusters ourselves…

To run a cluster there are some per-requisites. We have to install a minikube on our machines along with a kubectl program which is used to run and manage the clusters.

Install Minikube:
https://kubernetes.io/docs/tasks/tools/install-minikube/

Install Kubectl:
https://kubernetes.io/docs/tasks/tools/install-kubectl/

Starting the minikube services

Minikube is used to setup some cluster orchestration environment in our machines, as it launches an pre-configured environment in our Virtual Machine.
To Run minikube:

minikube start

minikube start command working

The command will launch a running instance of minikube in the Virtual-box (by default virtual environment used by minikube). You can see an environment named minikube running in the background in your virtual-box

minikube launched in virtual box

The Credentials…

By default the credentials for the virtual machine are set as:

Username : docker
Password : tcuser

Now we have successfully launched the minikube environment and now we can try some of the kubernetes command, we can create, manage and orchestrate container and pods using kubernetes’s kubectl command.

Launching Pods

kubectl get pods:
This command is used to get all the running pods.

kubectl create deployment <imageName> — image=container_image_location:
This command is used to deploy a new container in the pod for orchestration

nginx container launched inside mynewpod

The above command shows a successfully running pod (mynewpod) containing a container running with Nginx image.
Now as we said Kubernetes is a very smart container orchestration tool and can manage the health of the container running inside Pods, so if due to some reasons the pods may die or stop working properly it will launch another pods with the same image in fraction of seconds.

Let’s damage the launched pod and actually experience the power of Kubernetes…

As we can see the original pod was destroyed and when we check for the running pods on the background Kubernetes instantly launched another container with different the new pod with different name and hence ensuring as minimum as possible downtime. As the container engine is fast itself, hence reducing the downtime of application to seconds.

Well we saw for the Self Healing and Fault tolerance for the Kubernetes but what about Replication part of kubernetes

To check for the power of Replication Controller provided by kubernetes, let’s increase the replicas of the pod to let’s say 3 and let’s see what happens

As soon as we told our kubernetes to launch 3 replicas of the pod which we just created, it’s replication controller instantly launches the 3 containers and those containers are the part of out desire which we presented to kubernetes. The kubernetes will now manage all 3 pods and will ensure that our desire is met all the time i.e. it will ensure that at any point of time in future we must have 3 healthy running pods with nginx containers inside them

As soon as we destroyed or deletes all the pods, as mentioned in our desires kubernetes instantly launches another set of pods so that our configuration as mentioned in our desire is met always.

Hope by this we all are now more familiar with the vocabulary of kubernetes and the power it holds along with it’s importance and use cases.

NEXT Creating K8s scripts — deeper dive to K8s

………………………………………………………………………………

“Software is like entropy: It is difficult to grasp, weighs nothing, and obeys the Second Law of Thermodynamics; i.e., it always increases.”
— Norman Augustine

--

--

DevOps Enthusiast | Full Stack WebDeveloper | DevSecOps | Cloud Computing