Docs
/
Docker Kubernetes
Chapter 9

09 — Kubernetes Fundamentals

What is Kubernetes (K8s)?

Container orchestration platform — automates deployment, scaling, and management of containerized applications.

Docker: runs containers on ONE machine
Kubernetes: runs containers across MANY machines, handles failures, scales automatically

Architecture

┌─────────────────────────────────────────────────────────┐
│                   Control Plane (Master)                 │
│  ┌─────────────┐ ┌───────────┐ ┌──────────────────────┐│
│  │ API Server  │ │  etcd     │ │ Controller Manager   ││
│  │ (kube-api)  │ │ (KV store)│ │ + Scheduler          ││
│  └─────────────┘ └───────────┘ └──────────────────────┘│
└─────────────────────────┬───────────────────────────────┘
                          │
        ┌─────────────────┼─────────────────┐
        ↓                 ↓                 ↓
┌──────────────┐  ┌──────────────┐  ┌──────────────┐
│  Worker Node │  │  Worker Node │  │  Worker Node │
│  ┌────────┐  │  │  ┌────────┐  │  │  ┌────────┐  │
│  │kubelet │  │  │  │kubelet │  │  │  │kubelet │  │
│  │kube-proxy│ │  │  │kube-proxy│ │  │  │kube-proxy│ │
│  │Container │ │  │  │Container │ │  │  │Container │ │
│  │Runtime   │ │  │  │Runtime   │ │  │  │Runtime   │ │
│  └────────┘  │  │  └────────┘  │  │  └────────┘  │
│  [Pod][Pod]  │  │  [Pod][Pod]  │  │  [Pod][Pod]  │
└──────────────┘  └──────────────┘  └──────────────┘
ComponentRole
API ServerEntry point for all K8s commands (kubectl → API Server)
etcdDistributed key-value store (cluster state)
SchedulerDecides which node runs a new pod
Controller ManagerEnsures desired state matches actual state
kubeletAgent on each node — runs and monitors pods
kube-proxyNetwork proxy — handles service routing

Core Objects

ObjectPurpose
PodSmallest unit — one or more containers
DeploymentManages pods (scaling, updates, rollbacks)
ServiceStable network endpoint for pods
ConfigMapConfiguration data (non-secret)
SecretSensitive data (passwords, tokens)
NamespaceVirtual cluster for isolation

Pods

# pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  containers:
    - name: app
      image: my-app:1.0.0
      ports:
        - containerPort: 3000
      env:
        - name: NODE_ENV
          value: "production"
      resources:
        requests:
          memory: "128Mi"
          cpu: "250m"
        limits:
          memory: "256Mi"
          cpu: "500m"

> You rarely create Pods directly — use Deployments instead.


kubectl Essentials

# Cluster info
kubectl cluster-info
kubectl get nodes

# Pods
kubectl get pods                      # List pods
kubectl get pods -o wide              # With node info
kubectl describe pod <name>           # Detailed info
kubectl logs <pod>                    # View logs
kubectl logs -f <pod>                 # Follow logs
kubectl exec -it <pod> -- sh         # Shell into pod
kubectl delete pod <name>             # Delete pod

# Apply/delete from YAML
kubectl apply -f deployment.yaml      # Create/update
kubectl delete -f deployment.yaml     # Delete

# All resources
kubectl get all                       # Pods, services, deployments
kubectl get all -n my-namespace       # In specific namespace

Namespaces

kubectl create namespace staging
kubectl create namespace production

# Deploy to specific namespace
kubectl apply -f deployment.yaml -n staging

# Set default namespace
kubectl config set-context --current --namespace=staging

Local Development

# Minikube (single-node cluster)
minikube start
minikube dashboard           # Web UI

# k3s (lightweight K8s)
curl -sfL https://get.k3s.io | sh -

# Kind (Kubernetes in Docker)
kind create cluster

# Docker Desktop (built-in K8s)
# Enable in Docker Desktop settings

Key Takeaways

  • Kubernetes orchestrates containers across multiple machines
  • Control plane manages state; worker nodes run your containers
  • Pod = smallest unit (usually 1 container); Deployment manages pods
  • Service provides stable networking for pods
  • Use kubectl apply -f to deploy from YAML manifests
  • Use Minikube or Docker Desktop for local K8s development
  • Everything in K8s is declarative — you describe desired state, K8s makes it happen