Kubernetes Basics

Kubernetes (k8s) orchestrates containers. You describe desired state in YAML; k8s reconciles reality to match.

1 credit

Core objects

7 items
Pod
Smallest deployable unit — 1+ containers sharing network/storage
Deployment
Manages ReplicaSets to roll out pod updates; what you usually create
Service
Stable virtual IP + DNS for a set of pods (ClusterIP / NodePort / LoadBalancer)
Ingress
HTTP/HTTPS routing — host/path → Service
ConfigMap / Secret
Non-sensitive / sensitive config as env vars or files
Namespace
Logical partition — dev/staging/prod in one cluster
Node
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).

Further reading