Kubernetes

Understanding Kubernetes, its architecture and pod lifecycle.

Anushka S
Myntra Engineering
5 min readApr 10, 2023

--

Introduction: Evolution of Cloud Technologies

Cloud technologies have evolved significantly over the years, starting with physical machines and moving on to VMs, containers, Docker Swarm, and finally, Kubernetes (K8s).

In comparing VMs, Docker Swarm, and Kubernetes, we can see that while they share some similarities in terms of flexibility and scalability, they are fundamentally different.

Comparing evolution in cloud technologies

Kubernetes, also known as K8s, is a popular open-source platform that is widely used for container orchestration. K8s also provides advanced features such as service discovery, load balancing, and automated scaling, making it easier to manage containerized applications at scale.

Introduction

In this article, we’ll explore the basics of Kubernetes, its architecture, and the pod lifecycle in Kubernetes.

Kubernetes Demystified: An Introduction for Developers

A Container is a lightweight and portable way to package and run an application or a service. It’s like a virtual environment that contains everything your application needs to run, such as the code, libraries, dependencies, and even the operating system.

Kubernetes is a container orchestration platform that automates the deployment, scaling, and management of containerized applications. It was originally developed by Google, but is now maintained by the Cloud Native Computing Foundation (CNCF).

Browser to Ingress interaction

The core components of Kubernetes include:

  1. Pods

The smallest and most basic unit of Kubernetes is a pod. A pod is a logical host for one or more containers, and it represents the smallest unit of deployment in Kubernetes. A pod can run a single main application, and it can have one or more containers running at the same time. Every pod has its own internal IP address with which it interacts with other pods. When a pod dies, a new pod is created with a new assigned IP address.

2. Services

Services in Kubernetes are used to provide a permanent IP address for efficient communication between pods. The lifecycle of a pod and a service are unrelated, so communication is possible even when a pod dies and a new pod emerges. A service also acts as a load balancer between nodes.

3.Ingress

In order for the browser to access our application, we have external and internal services. An external call is made to the ingress first, and then our service is invoked to prevent data leakage from a DB pod to an external browser.

4. ConfigMap and Secret

ConfigMap is an external configuration for our application. For example, a database URL can be saved as a config map. On the other hand, Secret is used to store secret data such as usernames, passwords, and API keys. Secret uses base 64 encoding to save data.

5. Deployments

Deployments are essential components where the blueprint of pods is decided. Users create deployments, not pods. Deployments help to manage the lifecycle of pods, including creating new pods, scaling up or down, and rolling out updates. Users can also roll back updates to a previous version.

6. StatefulSet

StatefulSet is similar to deployments, but it is used to replicate database pods in order to avoid data inconsistencies. StatefulSets ensure consistent data reads and writes.

Exploring the Architecture of K8s

Architecture

Kubernetes architecture is based on a master-slave model, with the master node controlling the entire cluster and the worker nodes responsible for running the actual workloads.
Master node: This is the control plane of the Kubernetes cluster, which manages the overall state of the cluster and makes global decisions about the deployment of applications. The worker machine that runs the containers, and is responsible for running the application workloads.

Components of master and worker nodes

The master node is made up of several components, including:

  1. Etcd: This is a distributed key-value store that stores the entire state of the Kubernetes cluster.
  2. Kube-apiserver: This component provides a REST API endpoint that the kubectl command-line tool and other Kubernetes components use to communicate with the Kubernetes cluster.
  3. Kube-scheduler: This component is responsible for scheduling pods on worker nodes based on their resource requirements.
  4. Kube-controller-manager: This component is responsible for managing different types of controllers, including replication controllers, endpoints controllers, and service account controllers.

The worker node is made up of several components, including:

  1. Kubelet: This is the primary agent that runs on the worker node, and is responsible for managing the containers and reporting the status of the containers to the master node.
  2. Kube-proxy: This component runs on each worker node and is responsible for routing network traffic to the appropriate container.
  3. Container runtime: Kubernetes supports several container runtimes, including Docker, containers, and CRI-O.

Understanding the pod Lifecycle in Kubernetes

Pods are the smallest deployable units in Kubernetes, and they have a well-defined lifecycle that consists of several phases:

  1. Pending: In this phase, the pod has been created, but the container images have not yet been downloaded and the container has not yet started.
  2. Running: In this phase, the container is running and is executing the commands specified in the pod’s configuration.
  3. Succeeded: In this phase, the container has completed its task successfully and has terminated.
  4. Failed: In this phase, the container has terminated, but it did not complete its task successfully.
  5. Unknown: In this phase, the state of the container is unknown, which could be due to a communication failure between the pod and the master node.

Pods can also be in several other states, including Running with errors, Terminating, and Unknown.

Conclusion

Kubernetes is a powerful container orchestration tool that provides a range of features for managing containerized workloads. Its modular architecture and flexible design make it suitable for deployment in a wide range of environments, from small-scale deployments to large, complex systems. In this article, we explored the basics of Kubernetes, its architecture, and the pod lifecycle in Kubernetes.

Understanding the core concepts of Kubernetes, such as nodes, pods, and services, is essential for getting started with the platform. Additionally, having an understanding of the Kubernetes architecture and pod lifecycle can help you to design and manage your applications more effectively.

As with any technology, there is a learning curve associated with Kubernetes, but the benefits it provides in terms of automation, scalability, and reliability make it a valuable tool for modern application development and deployment.

--

--