Skip to main content

Kubernetes

Harbor master for your containers

The Orchestra Conductor Analogy

An orchestra:

ComponentRole
MusiciansPlay instruments (containers)
ConductorCoordinates everything (Kubernetes)
Sheet musicDefines what to play (configuration)

Without a conductor: Chaos! With a conductor: Harmony.

Kubernetes conducts your containers. It decides where they run, restarts them if they crash, and scales them up or down.


Why Kubernetes?

The Container Problem

ScaleChallenge
10 containersManage manually
1000 containersVery hard without automation

With 1000+ containers you need to answer:

  • Which server has room?
  • Server crashed - restart containers?
  • Traffic spike - need more containers?
  • Container died - start replacement?
  • Version update - without downtime?

That's millions of decisions per day!

Kubernetes Solves This

You declare: "I want 5 copies of this container"

Kubernetes handles:

TaskAutomatic
Finding servers with resources
Restarting crashed containers
Scaling up/down based on load
Rolling updates without downtime
Load balancing traffic
Service discovery

Core Concepts

Cluster Architecture

┌─────────────────────────────────────────┐
│            Control Plane                │
│  (Scheduler, API, Controller Manager)   │
└────────────────┬────────────────────────┘
                 │
    ┌────────────┼────────────┐
    │            │            │
 ┌──▼──┐     ┌──▼──┐     ┌──▼──┐
 │Node1│     │Node2│     │Node3│
 │     │     │     │     │     │
 └─────┘     └─────┘     └─────┘

Control Plane: Brain (makes decisions)
Nodes: Workers (run containers)

Pods

AspectDescription
DefinitionSmallest deployable unit
ContentsOne or more containers
NetworkingContainers share localhost
StorageContainers can share volumes
SchedulingContainers scheduled together

Think of a pod as a "logical host" for related containers.

Deployments

AspectDescription
Purpose"Run N copies of this pod"
DefinesContainer image, replicas, resources
ManagesCreates/updates pods automatically
UpdatesRolling updates, rollbacks

Services

ProblemSolution
Pods come and goService provides stable address
Pods get new IPsService stays the same
Multiple podsService load balances
Client → Service → Pod 1
                → Pod 2
                → Pod 3

How Kubernetes Works

Declarative Model

You SayKubernetes Does
"I want 3 replicas"Creates/maintains 3 pods
"I want my app v2"Rolling update to app v2
"I want 50% CPU max"Scales up if CPU exceeds 50%

State is defined in YAML files. Kubernetes constantly compares desired state vs actual state.

Self-Healing

EventResponse
Pod crashesKubernetes detects and starts replacement
Node diesPods rescheduled to healthy nodes
Container fails health checkPod restarted or replaced

All automatic!

Scaling

TypeHow It Works
Manualkubectl scale --replicas=10
HPAAuto-scale based on CPU/memory
KEDAAuto-scale based on events/metrics

Key Resources

ResourcePurpose
PodOne or more containers
DeploymentManages Pod replicas
ServiceNetwork endpoint
ConfigMapConfiguration data
SecretSensitive data (base64)
IngressExternal HTTP routing
PersistentVolumeStorage
NamespaceResource isolation

How They Connect

                   Internet
                      │
                   Ingress
                      │
                   Service
                      │
             ┌────────┼────────┐
             │        │        │
           Pod 1    Pod 2    Pod 3
             │        │        │
          ConfigMap  Secret  Volume

Basic Commands

Viewing Resources

CommandPurpose
kubectl get podsList pods
kubectl get servicesList services
kubectl get allList everything
kubectl describe pod [name]Pod details

Deploying

CommandPurpose
kubectl apply -f deployment.yamlApply config
kubectl delete -f deployment.yamlDelete resources
kubectl scale deployment/app --replicas=5Scale

Debugging

CommandPurpose
kubectl logs [pod]View logs
kubectl exec -it [pod] -- /bin/shShell access
kubectl port-forward [pod] 8080:80Local access

Namespaces

Namespaces are "folders" for resources.

NamespaceContents
defaultYour workloads
kube-systemSystem components
productionProd resources
stagingStaging resources

Benefits: Resource quotas, network policies, RBAC per namespace.


Kubernetes vs Docker

DockerKubernetes
"Run this container""Run 100 containers across 20 machines"
Single machine focusCluster-wide orchestration
Building containersRunning containers at scale

Docker = building containers. Kubernetes = running them at scale.


Common Mistakes

1. No Resource Limits

❌ Without limits✅ With limits
Pod can consume entire nodeDefined CPU/memory caps
Resources unpredictableFair scheduling

Set resource requests, and add limits when you want a hard cap.

2. No Health Checks

ProbePurpose
readinessProbe"Ready for traffic?"
livenessProbe"Still alive?"

Without probes, Kubernetes can't know if your app is healthy.

3. Using "latest" Tag

❌ Bad✅ Good
image: my-app:latestimage: my-app:v2
Unknown versionPredictable, traceable

4. No Pod Disruption Budget

Without PDB, maintenance can kill all pods at once. Define minimum available pods.


FAQ

Q: Kubernetes vs Docker Swarm?

Kubernetes: more features, industry standard Swarm: simpler, Docker-native

Kubernetes became the dominant choice in many environments.

Q: Do I need Kubernetes?

ScaleRecommendation
Small appsProbably not (adds complexity)
Large scaleLikely yes (worth the complexity)

Q: Managed vs self-hosted?

TypeTrade-off
Managed (EKS, GKE, AKS)Easier, less control
Self-hostedFull control, more work

Most teams use managed.


Summary

Kubernetes orchestrates containers at scale, handling deployment, scaling, and operations automatically.

Key Takeaways:

  • Cluster = control plane + worker nodes
  • Pods run containers
  • Deployments manage pod replicas
  • Services provide stable network endpoints
  • Declarative: describe desired state
  • Self-healing: automatic recovery
  • Set resource requests/limits and health checks

Kubernetes is the operating system for containers!

Leave a Comment

Comments (0)

Be the first to comment on this concept.

Comments are approved automatically.