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] │
└──────────────┘ └──────────────┘ └──────────────┘
| Component | Role |
|---|---|
| API Server | Entry point for all K8s commands (kubectl → API Server) |
| etcd | Distributed key-value store (cluster state) |
| Scheduler | Decides which node runs a new pod |
| Controller Manager | Ensures desired state matches actual state |
| kubelet | Agent on each node — runs and monitors pods |
| kube-proxy | Network proxy — handles service routing |
Core Objects
| Object | Purpose |
|---|---|
| Pod | Smallest unit — one or more containers |
| Deployment | Manages pods (scaling, updates, rollbacks) |
| Service | Stable network endpoint for pods |
| ConfigMap | Configuration data (non-secret) |
| Secret | Sensitive data (passwords, tokens) |
| Namespace | Virtual 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 -fto 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