# Kubernetes Explained: What Is Kubernetes and Why Do We Need It?

As applications grow, managing infrastructure becomes increasingly challenging. An application running perfectly on a single server might crash when thousands of users start accessing it.

Adding more servers solves the capacity problem, but managing multiple servers and hundreds of containers introduces another challenge.

This is where Kubernetes comes into the picture.

In this article, we'll understand what Kubernetes is, why we need it, how it works, and its core architecture.

## Why Do We Need Kubernetes?

Imagine you have a web application running on a single server.

![](https://images.openai.com/static-rsc-4/RnzscWyblvOJvbw8YK0og59iqsCUFnxcm1dBc3z2_JMYcdEkYg3sjsN1ePIwaAy4meLR6QEeeLGCqJQTIZW8fSXVfmCER-IEpFAXEi5RtbJfiEVBb2J6jbb_s4Wp73S4Yk6DLhxJCefW6AJV0LUj40JrSHOhP3XPOLcI8edmy0I?purpose=inline align="center")

Initially, everything works perfectly. But as users increase, CPU and memory utilization also increase.

Eventually, your server reaches its capacity and your application crashes.

Restarting the server doesn't solve the problem because traffic keeps increasing.

### Horizontal Scaling

One solution is to add more servers and distribute incoming traffic using a Load Balancer.

![](https://images.openai.com/static-rsc-4/hVMTTe1Y0uIoiKfK7UfIaiL-F543lFbPNYzR0duyH0KvBvWoo5Wu6pU9gnzdcnZLbPM9Xv31Q5vkzBcdTC5DS0oohTV2nNsnKEOxkIl2E0gloObkkYozSRl4CCGFSZxxXlIeFWJBxzfFap-2P1z5Hj81c2LevIaAVRdAfwL2jhU?purpose=inline align="center")

This solves the single-server bottleneck, but introduces new challenges:

- Managing multiple servers.
- Maintaining consistent application versions.
- Managing dependencies and runtime environments.
- Monitoring server health.

To solve dependency-related issues, we introduce Containerization.

## Containerization and Its Limitations

![](https://cdn.hashnode.com/uploads/covers/65def9438b970336d9eb270d/767d3a4c-985b-4539-b4fa-65e03eec9792.png align="center")

Containerization packages an application along with its runtime dependencies and libraries into a container image.

This ensures that the application runs consistently across different environments.

However, containers can also crash.

Imagine running 18 containers across three servers. You now need to monitor them, restart failed containers, deploy updates, and manage scaling.

Doing everything manually becomes difficult.

We need a system that automatically manages our containers. This is called Container Orchestration.

## What Is Kubernetes?

![](https://images.openai.com/static-rsc-4/QynYNsT4ecE29FFPMtKL3V4hb6Afw3sC5Monm4TVs15fpW7miFHWY_HDPlYvInlFft2sjXGENOeJk0NJfuYlL4SLZXgMDeh7wrvhvR_w46_FrteD0GdQ11-OY_vx-i8SvL6PQ7pH6StsbjRQNuXqbPVnIVacFCeHOGOxmhiXVaY?purpose=inline align="center")

Google initially developed an internal container orchestration system called Borg to manage workloads at scale.

In 2014, Google introduced Kubernetes as an open-source container orchestration platform.

Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications.

It helps us:

- Monitor containers.
- Restart failed containers.
- Schedule workloads across servers.
- Scale applications.
- Manage application deployments.

In simple words, Kubernetes manages your containers automatically.

## Kubernetes Architecture

A Kubernetes environment is called a Cluster, which consists of two major components:

1. Control Plane
2. Worker Nodes

![](https://images.openai.com/static-rsc-4/2vDFHqyK4Ad75qM6I0kvMzisyI8KXCe4CDNovVnj7h7ApF4WO5TFPnuIl19pZQdgtU9Ov4Lft6WFBmPw5P4WIKIoAr96je-FqmzhU0VBEJVQcofJwR9XP_0M3LDrRNiAuBIPZ2-stdAm_H46XxRLyIrAi4y0B_tMvgSs4tCe5f0?purpose=inline align="center")

### Control Plane

The Control Plane is the brain of Kubernetes. It manages the cluster and makes decisions about application workloads.

Its major components are:

| Component | Responsibility |
| --- | --- |
| API Server | Main entry point for Kubernetes API requests. |
| etcd | Stores cluster state and configuration. |
| Scheduler | Decides which Node should run a Pod. |
| Controller Manager | Maintains the desired state of the cluster. |
| Cloud Controller Manager | Integrates Kubernetes with cloud providers (optional). |

### Worker Nodes

Worker Nodes are physical or virtual machines where application workloads actually run.

Each Worker Node has three major components:

| Component | Responsibility |
| --- | --- |
| Kubelet | Manages Pods assigned to its Node. |
| Container Runtime | Pulls images and runs containers. |
| Kube-proxy | Implements Service networking rules. |

## What Is a Pod?

![](https://images.openai.com/static-rsc-4/yh_91i8fngLzM8xXwDGdpxN_ebLF8vqFeWK8B4t7iNp1TDPZe41q8aHFt5wvZKP5MowwvhfLGnx_QlspLdoIYWWCLmcm3Bav3Us_VHFAJl_0ZnxQI-4XtGKxvpjXdCBhLuPvjHuSdcqoGzBJAvbRgYn6JSNb7w_1GNr7hBKoHTY?purpose=inline align="center")

A Pod is the smallest deployable unit in Kubernetes.

It contains one or more containers that share resources such as networking and storage.

In most common applications, one Pod contains one application container.

A Pod generally goes through these lifecycle phases:

- Pending: Waiting for scheduling or container setup.
- Running: Containers are running or starting.
- Succeeded: All containers completed successfully.
- Failed: At least one container terminated unsuccessfully.

## How Kubernetes Works

Let's say you want to deploy an application with three replicas.

First, you define your desired configuration using a YAML file.

```plaintext
apiVersion: apps/v1
kind: Deployment

metadata:
  name: my-web-app

spec:
  replicas: 3

  selector:
    matchLabels:
      app: web

  template:
    metadata:
      labels:
        app: web

    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80
```

Now apply the configuration:

```plaintext
kubectl apply -f deployment.yaml
```

![](https://images.openai.com/static-rsc-4/hmLidiKiPX8RL7t_0Gwf8TZVfOI4PHrlRaPt32gHp5b7V8NvYh5vkEcrMC2tkcjZlaGLdKkq6RCpyEff4mSY7Spni1V7Qxn5-0ntfDW6CRkOUNve4kPmtgbHTkvZhujBDDc2jR6F1Kx-PpE_6uWIjwG78DniuFTXwnl642-32R0?purpose=inline align="center")

Execution Flow:

1. `kubectl` sends the configuration to the API Server.
2. API Server validates and stores the desired state in etcd.
3. Scheduler selects suitable Worker Nodes for the Pods.
4. Kubelet receives the Pod assignments.
5. Container Runtime pulls images and starts containers.

That's how Kubernetes deploys an application.

## Self-Healing and Scaling

One of Kubernetes' most powerful features is maintaining the desired state automatically.

### Self-Healing

Suppose you deployed three replicas, but one Pod crashes.

Kubernetes detects that only two replicas are available and works to create a replacement.

![](https://images.openai.com/static-rsc-4/90cFqTXSboeGcGZThxzVl-3fLuJZVsUALDUWNUeRwNlcEjmS68InrGPfTSeHrrm--bQtwgvKpfxcxkKqTuSYrEjhHXypyN93Mf9a8SqGBfLz9EdG4dimNWimnBqjQZcUsEdpVg2Wb24w8b_aarLlQefKJHQsViuw3p081vTRe9c?purpose=inline align="center")

### Scaling

When traffic increases, you can increase replicas:

```plaintext
kubectl scale deployment my-web-app --replicas=6
```

When traffic decreases:

```plaintext
kubectl scale deployment my-web-app --replicas=3
```

Kubernetes also provides Horizontal Pod Autoscaler (HPA) to automatically adjust Pod replicas based on configured metrics.

## Kubernetes: Quick Revision

| Concept | Meaning |
| --- | --- |
| Cluster | Collection of Control Plane and Worker Nodes. |
| Node | Physical or virtual machine. |
| Pod | Smallest deployable unit. |
| Deployment | Manages application rollout and replicas. |
| ReplicaSet | Maintains the desired number of Pods. |
| Kubelet | Manages Pods on a Node. |
| etcd | Cluster state database. |
| Scheduler | Assigns Pods to Nodes. |
| kubectl | Kubernetes command-line tool. |
| HPA | Automatically scales Pod replicas. |

## Conclusion

Kubernetes solves the complexity of managing containerized applications at scale.

We started with a single server, introduced horizontal scaling, understood containerization, and eventually reached container orchestration.

Kubernetes automates deployment, scheduling, scaling, and recovery of containerized applications.

The key takeaway: You manage your desired application state, and Kubernetes continuously works to make the actual state match it.

That's Kubernetes explained from scratch!

Based on the supplied video transcription, with concise technical clarifications. Architecture illustrations are included at the relevant sections.
