Kubernetes: Core Concept

Usha Devasi
5 min readJul 26, 2020

--

Why this Article???

* Basic understanding of Kubernetes
* What is Kubernetes Object, how to create and manage them?
* What is Pod?
* How to configure pods and debug them?
* Hands-on knowledge along with theory.

What is Kubernetes?

  • Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem.

One liner definition would be that Kubernetes is an open system platform as service, used for Container-Orchestration.

Why we need Kubernetes?

  • Containers are a good way to bundle and run your Application. In a production environment, there is not one but many containers running that needs to be managed in order to give assure of zero downtime for your application.
    E.g. If a container goes down, another container needs to start. Wouldn’t it be easier if this behaviour was handled by a system? Think 🤔 about it, Isn’t it a good idea to get rescued by Kubernetes?

In past we have seen different ways of deployment :
1. Traditional Deployment (having physical servers)
2. Virtualized Deployment (using Hypervisor and VM’s)

But now we have :
Container Deployment (Using Docker, Kubernetes or AWS etc…)

For getting the hands-on experience you can use Kubernetes but from a learning perspective, it will be a good idea to get started with Minikube.
[Note:]
If you installed Minikube locally, run minikube start.

Kubernetes Components :

A Kubernetes cluster consists of the components that represent the control plane and a set of machines called nodes.

Command to use Kubernetes is : kubectl(people pronounce it in different ways)

Kubernetes Object:

These are persistent entities in the Kubernetes system and is used to represent the state of your cluster.

These objects can describe:
* What containerized applications are running (and on which nodes)
* The resources available to those applications
* The policies around how those applications behave, such as restart policies, upgrades, and fault-tolerance.

In spec (Specification), we write what we need Kubernetes to do but the status gives the actual status. These objects are created by us but Kubernetes is responsible to maintain and minimize the difference between Spec and the Status.
So, let’s take the same example as above that a container is down which mean there is a gap between our desire and the actual state so here Kubernetes will instantly create a replica of the container.

How To Create and Manage these Objects?

While creating a Kubernetes object, always keep in mind that there are different techniques depending on how and where you what to create these objects as shown below:

Imperative commands work on Live objects so it is fast but at the same time developer need to have detailed knowledge as there is no track/history maintained.

$ kubectl create namespace <provide namespace>
$ kubectl run <podName> --image=nginx --restart= never --namespace=<namespace>
$ kubectl edit pod/<podName> --namespace=<namespace>

By using — restart=never, it automatically understands that a pod needs to be created.

Declarative object configuration is suitable for more elaborative changes as it is opposite of the previous one, it takes .yaml file at the very first place and also maintain the log of all the transactions done in past. It enables working on directories, where different operations might be needed for different objects.

$ kubectl create -f <filename>.yaml
$ kubectl delete pod/<podName>

[Note]: You can mix these different techniques/methods but it is highly recommended not to do.

What is Pod?

The pod is the smallest executable unit in Kubernetes application. It encapsulates an application’s container (or, in some cases, multiple containers) and shared resources.
Most commonly used container is Docker but pods support others too.
When a Pod gets created (directly by you, or indirectly by a _controller_), it is scheduled to run on a Node in your cluster. The Pod remains on that node until the process is terminated, the pod object is deleted, the Pod is evicted for lack of resources, or the node fails. Pods are incapable of self-healing.
If the pod is having multiple containers than the containers communicate with each other locally inside the pod via localhost but if container wants to communicate other containers, not belonging from the same container than the communication takes place via the port.

The phase of a Pod is a simple, high-level summary of where the Pod is in its lifecycle.

Let’s see how to proceed towards our hands-on practice using the below commands:
Create an alias for kubectl ( avoid typo mistake and work faster)
$ alias k=kubectl

$ k version

Shortcuts:
$ kubectl get ns (where ns is namespaces)

$ kubectl describe pvc claim(persistent volume claims)

Delete Kubernetes Objects:
$ kubectl delete pod <podname> --grace-period=0 --force
so that you need not wait for all the process to get deleted

For Configuring Pods and debugging them is shown in the hands-on practice Video tutorial.

https://www.youtube.com/watch?v=rNc92EsfcJI&feature=youtu.be

Conclusion: Here, I tried to provide a basic understanding of the core Kubernetes concepts via theory as well as a practical overview. Hope now where will be some difference in your understanding when you started and now at the end after going through the article and video. This is the first time I made a video, So really sorry if the video quality is not that good.

Your feedback matters a lot to improve constantly and to keep motivated too.

--

--

Usha Devasi
Usha Devasi

Written by Usha Devasi

Tech Lead/ Engineering Manager, Mentor, Coach, Certified Professional Scrum Master and SomeOne who is Passionate about Learning and exploring.

Responses (1)