Kubernetes Basics
Kubernetes (k8s) orchestrates containers. You describe desired state in YAML; k8s reconciles reality to match.
1 credit
Core objects
7 itemsPod
Smallest deployable unit — 1+ containers sharing network/storageDeployment
Manages ReplicaSets to roll out pod updates; what you usually createService
Stable virtual IP + DNS for a set of pods (ClusterIP / NodePort / LoadBalancer)Ingress
HTTP/HTTPS routing — host/path → ServiceConfigMap / Secret
Non-sensitive / sensitive config as env vars or filesNamespace
Logical partition — dev/staging/prod in one clusterNode
A worker machine (VM or bare metal)Minimal Deployment + Service
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector: { matchLabels: { app: web } }
template:
metadata: { labels: { app: web } }
spec:
containers:
- name: web
image: myrepo/web:1.4.2
ports: [{ containerPort: 8080 }]
---
apiVersion: v1
kind: Service
metadata: { name: web }
spec:
selector: { app: web }
ports: [{ port: 80, targetPort: 8080 }]When to reach for k8s
- Multiple services that need to scale independently.
- Zero-downtime deploys and automatic restart on crash.
- Team big enough that "which VM is it on?" is a real question.
- Not for: a single-container project. A VM with Docker Compose or a PaaS is simpler.
Gotchas
- Resource requests/limits are critical — pods without requests get scheduled randomly; no limits = one pod can starve the node.
- `latest` image tags cause drift and roll-forward bugs; pin versions.
- HTTPS is not automatic — use cert-manager + an Ingress controller.
- Logs disappear with pods. Ship to external aggregator (Loki/CloudWatch/ELK).