☸️ Kubernetes Cluster Architecture & Orchestration
1️⃣ What is Kubernetes (K8s) & Orchestration
Definition: Kubernetes (K8s) Google dwara open-source kiya gaya ek production-grade container orchestration platform hai. Yeh automated container scheduling, auto-scaling, self-healing, rolling deployments aur load-balancing manage karta hai.
| Criteria | Standalone Docker | Kubernetes Cluster |
|---|---|---|
| Host Management | Single physical server ya single VM tak limited. | Hundreds ya thousands of heterogeneous nodes ka unified cluster pool. |
| Self-Healing | Host crash hone par container restart nahi hota. | Automatic Re-scheduling: Failed node ke pods turant doosre healthy nodes par shift ho jaate hain. |
| Scaling | Manual docker run commands. |
Horizontal Pod Autoscaler (HPA): CPU/Memory spikes par automatically 3 se 30 pods scale karna. |
2️⃣ Control Plane & Worker Node Architecture
| Subsystem | Core Component | Primary Responsibility |
|---|---|---|
| Control Plane (Master Node) | kube-apiserver |
Cluster ka central entry point; saari REST API requests validate aur authenticate karta hai. |
etcd |
Highly-available distributed key-value store jo cluster ka complete state persist karta hai. | |
kube-scheduler |
Naye pods ke resource requests inspect karke unhe best worker node par assign karta hai. | |
kube-controller-manager |
Reconciliation loops run karta hai (e.g. Desired state == Current state ensure karna). | |
| Worker Node | kubelet |
Node par running agent jo API server ke orders ke mutabiq containers start aur monitor karta hai. |
kube-proxy |
Node-level network packet filtering aur service IP routing rules (iptables/IPVS) maintain karta hai. | |
CRI (Container Runtime) |
Low-level software (containerd, CRI-O) jo images pull karke containers execute karta hai. |
3️⃣ Core API Objects: Pods & Deployments
Pod: Kubernetes ka smallest deployable computing unit, jisme ek ya ek se zyada containers same network namespace (IP) aur storage share karte hain:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jobs-api-deployment
labels:
app: jobs-api
spec:
replicas: 3
selector:
matchLabels:
app: jobs-api
template:
metadata:
labels:
app: jobs-api
spec:
containers:
- name: api-server
image: fresherjobsalert/jobs-api:v1.0.0
ports:
- containerPort: 8080
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
4️⃣ Kubernetes Services: Service Discovery
Pods ephemeral hote hain (restart par IP badal jata hai). Service pods ke group ke aage ek stable virtual IP aur DNS provide karta hai:
| Service Type | Scope & Routing | Standard Use Case |
|---|---|---|
| ClusterIP (Default) | Cluster ke andar accessible internal static IP. | Internal microservices, backend databases, Redis caches. |
| NodePort | Har worker node par static port (30000-32767) expose karta hai. | Development testing, on-prem bare-metal internal access. |
| LoadBalancer | Cloud provider (AWS NLB/ALB, Azure LB, GCP) ka public IP provision karta hai. | Public customer-facing production internet traffic. |
5️⃣ Ingress Controllers & Path-Based Routing
Har service ke liye alag expensive cloud LoadBalancer khareedne ke bajay ek unified 7th-layer reverse proxy (NGINX Ingress/Traefik) use karna:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: main-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
rules:
- host: api.fresherjobsalert.com
http:
paths:
- path: /jobs
pathType: Prefix
backend:
service:
name: jobs-service
port:
number: 8080
- path: /users
pathType: Prefix
backend:
service:
name: users-service
port:
number: 3000
6️⃣ ConfigMaps, Secrets & Persistent Volumes
- ConfigMap: Plaintext configuration variables aur properties files ko container image se separate rakhna.
- Secret: Sensitive credentials (Base64 encoded) jaise database passwords aur TLS certificates inject karna.
- PV & PVC (Persistent Volumes): Pod restart hone par bhi data safe rakhne ke liye cloud block storage (AWS EBS / Azure Disk) bind karna.
7️⃣ Self-Healing & Horizontal Pod Autoscaling (HPA)
•
maxSurge: 25% (Update ke dauran maximum kitne extra pods spawn ho sakte hain).•
maxUnavailable: 0% (Update ke dauran ek bhi purana pod tab tak destroy nahi hoga jab tak naya pod readinessProbe pass na kar le).
# Horizontal Pod Autoscaler (HPA) CLI Command
kubectl autoscale deployment jobs-api-deployment --cpu-percent=75 --min=3 --max=20