Infrastructure & Scaling

Docker & Kubernetes

The Operating System of the Cloud. Understanding Containers, Pods, Services, and how to orchestrate distributed systems.

Docker: "Build Once, Run Anywhere"

A container is a standard unit of software that packages code and all its dependencies.

🖼️ Image (The Class)

A read-only template with instructions for creating a Docker container. Built from a `Dockerfile`.

📦 Container (The Object)

A runnable instance of an image. Isolated from other containers and the host system.

Kubernetes Architecture

K8s is not just about running containers; it's about Scheduling and Self-Healing.

K8s Cluster
Control Plane (Master)
API Server Scheduler etcd
Worker Node
Pod 1 (App A)
Pod 2 (App B)
Kubelet Kube-Proxy

Core K8s Objects

Object Description
Pod The smallest deployable unit. Usually 1 container per pod. Ephemeral API address.
Deployment Manages Pods. Handles Scaling and Rolling Updates. "I want 3 replicas of App A".
Service Stable networking abstraction. "Traffic to 'my-service' goes to any healthy Pod".
Ingress HTTP/HTTPS router. Exposes Services to the outside world.
Service Types
  • ClusterIP: Internal only. (Default)
  • NodePort: Open a specific port on every Node IP.
  • LoadBalancer: Provision a Cloud LB (AWS ALB/GCP LB).

Manifest Examples

Everything in K8s is declarative YAML.

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: payment-service
spec:
  replicas: 3
  selector:
    matchLabels:
      app: payment
  template:
    metadata:
      labels:
        app: payment
    spec:
      containers:
      - name: app
        image: my-payment-app:v2
        ports:
        - containerPort: 8080
---
# service.yaml
apiVersion: v1
kind: Service
metadata:
  name: payment-svc
spec:
  selector:
    app: payment
  ports:
  - port: 80
    targetPort: 8080
  type: ClusterIP

Summary

  • Abstraction: Docker abstracts the OS. Kubernetes abstracts the Data Center.
  • Pods: Treat them like cattle, not pets. They die and get replaced automatically.
  • Networking: Services provide stable IPs for unstable Pods.