DEV Community

Cover image for The Orchestration of The Ring
GilHope
GilHope

Posted on • Updated on

The Orchestration of The Ring

In the land of Mordor,

In the fires of Mount Volume...

The Dark Lord Sau..-Cron.. forged in secret a...

uh...

A container orchestration platform!!!

Is he really going to do this again?

Image description

Yes.

In this blog, i'm going to go over a little bit about the basics of Kubernetes. If you haven't seen my previous Lord of the Rings flavored post on Docker then you can also check that out HERE

Table of Contents:

What is Kubernetes?

Kubernetes is an open-source container orchestration platform and is currently the leading container orchestration tool so this is an important one to know. In essence, Kubernetes is designed to efficiently automate the deployment, scaling, and operation of containerized applications. It is also a vendor-neutral tool so it can run on all cloud providers.

Just as the One Ring has the ability to wield power and influence over other ring bearers for Sauron, Kubernetes has the power to wield and orchestrate container systems, such as Docker, for you!

Kubernetes, also known as K8s because of the number of letters between ‘K’ and ‘s’, is derived from the Greek word κυβερνήτης (kubernḗtēs), which means “pilot”. You can see this clearly illustrated in their logo design; and that is the essence of what Kubernetes does.

What are K8s key features?

  • Service Discovery: Kubernetes offers a built-in service discovery mechanism by which different services within a cluster can discover each other dynamically with the assignment of DNS names.
  • Storage Orchestration: With Kubernetes, users are provided robust storage orchestration capabilities which allow them to manage and mount regardless of whether it is local, network-attached, or cloud-specific storage.
  • Automated Rollouts and Rollbacks: With K8s, you can define the desired state of deployments while the ability to make seamless updates without downtime. And in the case of issues or failures, you can easily roll back to the previous desired state.
  • Automate Bin Packing: K8s can efficiently utilize resources by maximizing CPU utilization and optimizing resource allocation across nodes in your clusters.
  • Self-Healing: In order to maintain your desired state, K8s automatically can detect any failed containers that don't respond to health-checks and then either replace, kill, or restart them.
  • Secret and Configuration Management: K8s allows you to store secrets and configurations securely and while doing so also maintaining the ability to update them without the need to rebuild them your container images.

How is K8s architected from a bird’s eye view?

Kubernetes utilizes what is known as a ‘cluster architecture’. For K8s, this is a highly available ‘cluster’ of compute resources which can be organized to work as one single unit. Within these clusters run nodes and within the nodes are pods.

Control Plane: The cluster is captained by the cluster Control Plane, aka the Master Node, and this is responsible for maintaining the desired state of the cluster. It manages things such as the scheduling, scaling, deploying, and the applications within the cluster.

Worker Nodes: The Control Plane’s crew are the Worker Nodes, aka the Data Plane. Worker nodes are the virtual machines or physical servers that run your applications and workflows. Each worker nodes contains the the services necessary to manage and run what are known as ‘Pods’.

Pods: Pods are the smallest and simplest units within the K8s architecture. A pod encapsulates an application container(s), storage resources, a unique network IP, and the options that govern how the container should run.

Image description

Deployments: Deployments in K8s allows users to define the desired state of their applications, including the number replicas, container images, and also features, such as rolling updates, rollbacks, scaling, and self-healing. Deployments are apart of the Control Plane and specifically are managed by the Deployment Controller which monitors and manages the deployments to ensure the desired and current state actually match.

The K8s architecture in more detail.

Control Plane

The control plane is made up of a few key components, including: the API Server, Etcd, Scheduler, and Controllers.

API Server (kube-apiserver): This is the front-end for the control plane and is what the user, management devices, and command-line interfaces all communicate with.

Etcd: This provides a highly available key value store within the cluster for storing the cluster state and configuration.

Scheduler (kube-scheduler): The scheduler identifies any newly created pods without an assigned node and then selects a node for them to run on based on on resource requirements, deadlines, affinity/anti-affinity, data locality, and any constraints.

Controller Manager (kube-controller-manager): This manages the cluster controller processes which include the Node Controller, Replication Controller, Endpoints Controller, and Service Account & Token Controllers.

  • Node controller: Monitors and responds to node outages. If a nodes fails to respond then it is marked ‘unhealthy’ and no longer schedules it work.
  • Job/Cronjob controller: The job controller tracks Job objects (one-off tasks/jobs) and the cronjob controller manages jobs set to run at specific times or intervals.
  • Endpoint controller: Populates the endpoint object used for network communications between services within the cluster.
  • Service Account and Token Controller: These create default accounts and API access tokens for new namespaces.
  • Replication Controller: Ensures the desired number of pod replicas are running at any given time.
  • Deployment Controller: Manages the lifecycle of deployments.

Cloud Controller Manager (cloud-controller-manager): This manages the cloud-specific control logic which enables the communication with the underlying cloud services through their APIs.

Image description

Worker Nodes

Within the Worker Nodes are components, such as the Kubelet, Kube Proxy, and Container Runtime.

The Kubelet: Is an agent that runs on each worker node in the cluster and ensures that the containers are running within a pod. These utilize ‘PodSpecs’, a YAML or JSOn object, which describe a pod and makes sure that the described containers in those PodSpecs are running healthily.

Kube Proxy (kube-proxy): Is a network proxy that runs on each worker node and maintains network rules which allow communication to pods from inside or outside the cluster.

Container Runtime: This is the software that is responsible for running the containers. K8s supports several runtimes, such as Docker, Containerd, CRI-), and any implementation of the Kubernetes CRI.

K8s meme

Let's get started using K8s

1) Install prerequisites

We will be running through a quick tutorial for how we can work with K8s locally. Before we can get started doing anything you will need to have a few things installed.

Be sure to have the latest versions of minikube, kubectl, and docker.

2) Creating nodes with Minikube

Let's first try creating nodes using Minikube. For this, try the following command:

minikube start --nodes=2

In this command, we tell minikube to start up and to create 2 nodes with the trailing flag.

Note that if this is your first time using minikube then this process will take about 5 minutes or so to complete.

Now, lets check the status of our nodes out by running:

minikube status

Image description

You can see the control plane up top and about the worker at the bottom.

If you were to run a docker ps then you should see them running as 2 containers there as well.

We can run kubectl get nodes to view our nodes.

Image description

Try running kubectl get pods -A and we can view all pods in all namespaces.

Image description

If you notice, these pods above are what make up the control plane.

3) Deployment

To create a K8s deployment, the command syntax follows: `kubectl create deployment --image=.

We will use kubectl create deployment nginx-depl --image=nginx for this tutorial.

After you have run that then run kubectl get deployment and you should see something like the following indicating that we now have a ready deployment:

Image description

Then try running kubectl get pod and that should look similar as below:

Image description

If you would like to see if the desired state is matched with the actual current state then we can view the Replica Set with kubectl get replicaset.

Image description

Conclusion

I hope you all enjoyed this article. I had quite a bit of fun writing this article and I hope the illustration may help some of the information stick more effectively. Understanding of Kubernetes is a pretty important knowledge to have for anybody working in the Cloud and it would do you very well to get accustomed to working with it.

PS - I am actively looking for new work in the Cloud so please feel free to start a conversation if you are looking for a new addition to your team.

Check me out here:
Cloud Resume
GitHub
LinkedIn

Frodo

Top comments (0)