Skip to main content

Let's understand Kubernetes and How it works

Β· 4 min read
Karan
Software Developer

πŸ”Ή Introduction​

Kubernetes (often abbreviated as K8s) is an open-source platform for automating deployment, scaling, and management of containerized applications. It helps developers manage their applications more efficiently and ensures they run reliably.

Think of Kubernetes as an orchestra conductor 🏒🎻. It ensures that all the containers (instruments) work together in harmony.

🌟 Why Kubernetes?​

Before Kubernetes, developers used tools like Docker to package applications into containers. But when you have hundreds or thousands of containers, managing them manually becomes a nightmare! 😡 That's where Kubernetes helps:

βœ… Automatic Scaling – Adjusts the number of containers based on demand.
βœ… Self-Healing – If a container crashes, Kubernetes restarts it automatically.
βœ… Load Balancing – Distributes traffic among containers to prevent overload.
βœ… Rolling Updates – Updates applications without downtime.
βœ… Resource Optimization – Efficiently utilizes CPU and memory.
βœ… Multi-Cloud Support – Works across AWS, GCP, Azure, and on-premises environments.

πŸ“Œ Key Concepts in Kubernetes​

1️⃣ Pods πŸ›Άβ€‹

A Pod is the smallest unit in Kubernetes. It contains one or more containers that share storage and networking. Think of a pod as a box πŸ“¦ that holds your application.

Example Pod YAML:​

apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80

2️⃣ Nodes πŸ–₯️​

A Node is a machine (physical or virtual) where Kubernetes runs your applications. A cluster consists of multiple nodes.

  • Master Node πŸ‘‘: Controls and manages the cluster.
  • Worker Nodes πŸ—οΈ: Run the applications inside containers.

Each worker node contains:

  • Kubelet – Ensures pods are running correctly.
  • Container Runtime (Docker/Containerd) – Runs the actual containers.
  • Kube Proxy – Manages networking and communication between pods.

3️⃣ Deployments πŸš€β€‹

A Deployment is used to manage multiple pods. It ensures your application is always running the desired number of instances and can handle updates smoothly.

Example Deployment YAML:​

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3 # Run 3 instances
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80

This creates a Deployment that runs 3 pods of NGINX.

4️⃣ Services πŸŒβ€‹

A Service allows communication between different components of an application (pods). It acts like a load balancer.

Example Service YAML:​

apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP

This service ensures that the pods can communicate with each other inside the cluster.

πŸ”§ How Kubernetes Works (Step-by-Step)​

1️⃣ You define your application using YAML files (Pods, Deployments, Services).
2️⃣ Kubernetes API Server schedules and manages the workloads.
3️⃣ Nodes run the containers using a container runtime like Docker or Containerd.
4️⃣ Kubelet (agent on each node) ensures that pods are running as expected.
5️⃣ Kubernetes continuously monitors and maintains the system, ensuring stability.
6️⃣ Load balancing and auto-scaling adjust resources dynamically based on demand.

πŸ—οΈ Kubernetes Architecture​

Kubernetes follows a Master-Worker architecture:

  • Master Node Components: API Server, Scheduler, Controller Manager, etcd (database).
  • Worker Node Components: Kubelet, Kube Proxy, Container Runtime.

Kubernetes Architecture

🎯 Real-World Use Cases of Kubernetes​

βœ… Running Scalable Web Applications – Deploy and manage websites with high traffic.
βœ… Microservices Architecture – Easily manage multiple small services.
βœ… CI/CD Pipelines – Automate software delivery workflows.
βœ… Hybrid and Multi-Cloud Deployments – Run workloads on any cloud (AWS, GCP, Azure).
βœ… Machine Learning & AI – Manage and deploy ML models efficiently.

πŸŽ‰ Conclusion​

Kubernetes makes it easier to deploy, scale, and manage modern applications efficiently. With features like auto-scaling, self-healing, and load balancing, it has become the standard for container orchestration. πŸš€

If you're new to Kubernetes, try deploying a small app and explore its powerful capabilities! πŸ’‘