Kubernetes basics
Introduction
Docker la containers create pannita โ super! But ipo imagine pannunga: 50 containers oru app ku run aagudhu. Oru container crash aana? Traffic increase aana? New version deploy pannanum na? ๐ฐ
Manually manage panna impossible. Adhukkudhaan Kubernetes (K8s) use pannrom โ containers oda autopilot maari! ๐
Indha article la Kubernetes core concepts, architecture, and hands-on basics paapom. AI apps ku K8s epdhi game-changer nu therinjukkalam!
Why Kubernetes?
Docker alone use pannum bodhu problems:
| Problem | Without K8s | With K8s |
|---|---|---|
| Container crash | Manual restart | Auto restart โป๏ธ |
| Traffic spike | Manual scaling | Auto scaling ๐ |
| New deployment | Downtime risk | Zero downtime ๐ข |
| Load balance | Manual config | Automatic โ๏ธ |
| Health check | You monitor | K8s monitors ๐ฅ |
Real-world example: Unga AI chatbot app ku suddenly 10x traffic vandhaa:
- Without K8s: Server crash, users angry ๐ค
- With K8s: Auto-scale, 10 new pods create, users happy ๐
Google daily 5 billion containers run pannum โ Kubernetes use pannithaan! Adhaan idha open-source ah release pannanga. ๐
Kubernetes Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ KUBERNETES CLUSTER โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ โโโโโโโโโโโโโโโโ Control Plane โโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โ โ โ โ โ API โ โ Schedulerโ โ Controller โ โ โ โ โ โ Server โ โ โ โ Manager โ โ โ โ โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ etcd (Database) โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโ Worker Node 1 โโโโ โโโโ Worker Node 2 โโโโ โ โ โ โโPodโโโ โโPodโโโ โ โ โโPodโโโ โโPodโโโ โ โ โ โ โ ๐ค โ โ ๐ง โ โ โ โ ๐ค โ โ ๐ โ โ โ โ โ โ API โ โModel โ โ โ โ API โ โRedis โ โ โ โ โ โโโโโโโโ โโโโโโโโ โ โ โโโโโโโโ โโโโโโโโ โ โ โ โ kubelet + proxy โ โ kubelet + proxy โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Concepts โ K8s Building Blocks
K8s la mukkiyamana concepts:
1. Pod ๐ซ
- Smallest unit in K8s
- One or more containers hold pannum
- Oru pod = oru app instance
2. Deployment ๐
- Pods manage pannum
- "3 copies of my AI API run pannu" nu sollunga
- Auto-replace crashed pods
3. Service ๐
- Pods ku stable network address kudukum
- Load balance pannum
- Types: ClusterIP, NodePort, LoadBalancer
4. Namespace ๐
- Virtual cluster โ organize resources
- dev, staging, production separate pannalam
5. ConfigMap & Secret ๐
- Configuration data store pannradhu
- Secrets = encrypted sensitive data (API keys)
6. Ingress ๐ช
- External traffic manage pannum
- Domain routing: api.myapp.com โ API pod, app.myapp.com โ Web pod
Pod Lifecycle
Pod oda lifecycle stages:
1. Pending โ Schedule aaga wait pannum
2. Running โ Container start aagiduchu โ
3. Succeeded โ Task complete (batch jobs)
4. Failed โ Container crash aagiduchu โ
5. Unknown โ Node communication lost
Important: Pods are ephemeral โ die pannum, replace aagum. Data store panna Persistent Volumes use pannunga!
Pod crashed na K8s automatically new pod create pannum โ nee tension panna vendaam! ๐ง
YAML Files โ K8s Language
K8s la ellam YAML files la define pannrom. Basic structure:
Key fields:
- replicas: Ethana pods venum
- image: Docker image
- resources: CPU/Memory limits
- labels: Pods identify panna
Essential kubectl Commands
kubectl = K8s oda CLI tool. Most used commands:
| Command | What It Does |
|---|---|
| `kubectl get pods` | All pods list pannum |
| `kubectl get services` | All services kaatum |
| `kubectl apply -f file.yaml` | Config apply pannum |
| `kubectl delete pod name` | Pod delete pannum |
| `kubectl logs pod-name` | Logs paakalam |
| `kubectl exec -it pod -- bash` | Pod inside pogalam |
| `kubectl scale deploy/app --replicas=5` | Scale pannum |
| `kubectl describe pod name` | Detailed info |
Quick start flow:
Services โ Network Access for Pods
Pods ku direct ah access panna mudiyaadhu (IP keep changing). Service oru stable endpoint kudukum.
Service Types:
1. ClusterIP (Default) ๐
- Internal access only
- Backend services ku use pannunga
- Example: AI model service โ API server mattum access pannum
2. NodePort ๐ช
- External access via node port (30000-32767)
- Development/testing ku use pannunga
3. LoadBalancer โ๏ธ
- Cloud provider load balancer create pannum
- Production ku best
- Example: User traffic AI API ku distribute pannum
Auto Scaling in K8s
K8s la 2 types of scaling irukku:
Horizontal Pod Autoscaler (HPA) ๐
- CPU/Memory usage based ah pods add/remove pannum
- "CPU 70% above pona 10 pods varaikkum scale pannu"
Vertical Pod Autoscaler (VPA) ๐
- Pod oda resource limits adjust pannum
- "Idhu ku more memory venum" nu auto-increase
AI apps ku HPA most useful โ inference requests increase aana auto-scale aagum! ๐
Local Setup with Minikube
Local la K8s try pannunga โ Minikube! ๐ป
5 minutes la unga own K8s cluster ready! ๐
Other options: kind (K8s in Docker), k3s (lightweight K8s), Docker Desktop (built-in K8s).
K8s for AI/ML Workloads
AI apps ku special K8s features:
GPU Scheduling ๐ฎ
- NVIDIA GPU Operator use pannalam
- Specific pods ku GPU allocate pannalam
Model Serving ๐ง
- KServe โ ML model serving framework
- Seldon Core โ ML deployment platform
- Auto-scaling based on inference load
Training Jobs ๐
- Kubeflow โ ML pipeline orchestration
- Distributed training across multiple GPU nodes
- Job scheduling and queue management
AI-specific tools on K8s:
| Tool | Purpose |
|---|---|
| Kubeflow | ML Pipelines |
| KServe | Model Serving |
| Argo Workflows | DAG workflows |
| MLflow | Experiment tracking |
| Ray | Distributed computing |
Try It: K8s Setup Prompt
K8s Best Practices
Production K8s ku follow pannunga:
โ Resource limits always set pannunga โ illana oru pod full node resources eat pannum
โ Health checks (readiness + liveness probes) add pannunga
โ Namespaces use pannunga โ dev/staging/prod separate
โ RBAC enable pannunga โ who can do what
โ Secrets properly manage pannunga โ never hardcode
โ Rolling updates use pannunga โ zero downtime
โ Pod Disruption Budgets set pannunga โ maintenance time safety
โ Monitoring with Prometheus + Grafana setup pannunga
Managed Kubernetes Services
Own K8s cluster manage panna headache. Cloud providers managed version kudukuraanga:
| Service | Provider | Best For |
|---|---|---|
| **EKS** | AWS | Enterprise, large scale |
| **GKE** | AI/ML workloads, autopilot | |
| **AKS** | Azure | Microsoft ecosystem |
GKE Autopilot โ Google manage everything, nee YAML apply pannunga. No node management! Best for AI apps starting out.
Pricing comparison (3 nodes, small):
- EKS: ~$73/month (cluster fee) + EC2 costs
- GKE: Free cluster + VM costs
- AKS: Free cluster + VM costs
Recommendation: GKE Autopilot la start pannunga โ easiest and AI-friendly! ๐ฏ
โ Key Takeaways
โ Kubernetes Orchestration โ Hundreds/thousands containers auto-manage. Crash recovery, scaling, deployment zero-downtime. Docker alone production scale impossible
โ Core Abstractions โ Pod (smallest unit, one+ containers), Deployment (manage pods, replicas), Service (stable network access, load balance), Namespace (virtual clusters)
โ Architecture Simple โ Control Plane (API server, scheduler, controllers), Worker Nodes (Kubelet, runtime), etcd (database). Masters manage, nodes run pods
โ Scaling Two Types โ HPA (CPU/memory threshold auto-add pods), VPA (auto-increase resources). AI apps: HPA inference load based, VPA model size optimization
โ YAML Manifests โ Everything YAML files. Deployment spec (replicas, image, resources), Service spec (selector, ports), ConfigMap (config), Secret (sensitive data)
โ AI/ML Specific โ GPU scheduling (nvidia.com/gpu limits), KServe (model serving), Kubeflow (ML pipelines), Argo (workflows). Distributed training possible
โ Kubectl Commands โ Get pods/services, apply/delete resources, logs/exec into pods, scale deployments. Learning curve initial, powerful once mastered
โ Managed Services โ GKE (best AI), EKS (AWS), AKS (Azure). Cluster creation, upgrades, security provider-managed. Focus code, not infrastructure
๐ ๐ฎ Mini Challenge
Challenge: Deploy Flask App to Kubernetes (Minikube)
Local K8s cluster setup โ Flask app deploy pannu:
Step 1: Minikube Install & Start ๐
Step 2: Docker Image Create ๐ณ
Step 3: Kubernetes Manifest Create ๐
Step 4: Deploy to Minikube ๐ฏ
Step 5: Access App ๐ป
Step 6: Scale & Monitor ๐
Completion Time: 2 hours
Tools: Minikube, kubectl, Docker, YAML
Real Kubernetes experience โญ
๐ผ Interview Questions
Q1: Kubernetes epdhi auto-scale? HPA (Horizontal Pod Autoscaler)?
A: HPA monitors metrics (CPU, memory, custom metrics). Threshold exceed โ pods automatically add. CPU 80% cross โ 2 more pods add. Perfect for variable traffic. AI inference: request count spike โ scale up, request reduce โ scale down.
Q2: Stateful vs Stateless apps โ K8s la difference?
A: Stateless: any pod serve pannalam (easy, scalable). Stateful: specific pod specific user (database, session). K8s: StatefulSets for stateful (ordered, persistent). AI apps mostly stateless (inference), but training apps stateful (persistent storage, GPU allocation).
Q3: Namespace use case โ why organize?
A: Namespace = virtual clusters. Multi-team: production, staging, dev separate. Resource quotas: team A 50% cluster la use, team B 50%. RBAC: different access levels. Isolation: one namespace crash โ others unaffected.
Q4: ConfigMap vs Secret โ Kubernetes la difference?
A: ConfigMap = non-sensitive config (database host, API endpoint). Secret = sensitive (passwords, API keys, credentials). ConfigMap: plaintext, versioning easy. Secret: base64 encoded (not encrypted by default โ additional encryption setup needed for production).
Q5: Resource requests/limits โ K8s scheduling?
A: Request = minimum guaranteed (pod guaranteed get). Limit = maximum (pod exceed pannala). Setting: CPU/memory both. Scheduler: request check โ right node find โ allocate. Over-provisioning avoid, under-provisioning prevent. AI apps: GPU requests essential, limits set to prevent resource hogging.
Frequently Asked Questions
Kubernetes la smallest deployable unit edhu?