Declare the desired state; let control loops keep BoxOffice there
Lab 3 scaled catalog by editing Compose. Lab 9 restarted a fallen service by hand. Who does that during the flash sale?
catalog
:80
:30080
--kubelet-insecure-tls
docker tag … boxoffice/catalog:dev
kind load docker-image
latest
ingress-nginx was retired in March 2026. Pick maintained, internet-facing components.
k8s/base/ namespace, config, db, redis, catalog, hpa, ingress k8s/overlays/local/ image tag "dev" + lab secrets
kubectl apply -k k8s/overlays/local
secretGenerator
db-credentials-<hash>
db
db-0
clusterIP: None
Production databases: managed service or an operator (backups, failover, upgrades).
Never check a shared dependency in liveness: one DB blip → every pod restarts at once.
requests
limits
OOMKilled
preStop: sleep 5
SIGTERM
server.shutdown=graceful
maxSurge: 1
maxUnavailable: 0
catalog restarted twice right after kubectl apply. Bug?
kubectl apply
depends_on
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler spec: minReplicas: 2 maxReplicas: 8 metrics: [{ type: Resource, resource: { name: cpu, target: { type: Utilization, averageUtilization: 60 } } }] behavior: scaleUp: { stabilizationWindowSeconds: 0 } # + at most 100% or 2 pods / 15 s scaleDown: { stabilizationWindowSeconds: 120 } # - 1 pod / 30 s
desired = ⌈current × utilization / target⌉ → 2 pods at 150% → ⌈2 × 150 / 60⌉ = 5.
desired = ⌈current × utilization / target⌉
localhost:80
/catalog
Ingress
ingressClassName: traefik
Gateway
HTTPRoute
LoadBalancer Service = one address per service; Ingress = one door, many services; API gateway = auth, quotas, transformations.
PEAK
preStop
scripts/watch-hpa.sh logs CPU, desired, current and ready replicas every 5 s → plot it.
scripts/watch-hpa.sh
scale-out
stress
The playground predicts the shape; your CSV of replicas over time is the evidence.
Outline: (1) why control loops; (2) kind + Traefik + metrics-server; (3) Kustomize base/overlay; (4) StatefulSet vs Deployment; (5) probes and graceful shutdown; (6) HPA; (7) Ingress and Gateway API; (8) measure.