System Design Cases
Kubernetes Patterns
Kubernetes production usage patterns from "Kubernetes Patterns" (Ibryam, Huss): Sidecar (Istio Envoy mTLS), Ambassador (proxy для external services), Init container (iptables setup, db migrate), Adapter (translate /stats -> /metrics), Operator pattern (CRD + reconcile loop with Postgres operator example, Leader election для HA), Self-healing (probes), Predictable demands (resources/limits) и Elastic Scale (HPA reactive scaling). Three scenarios: sidecar mTLS via Istio Envoy, Postgres operator reconciles cluster state with failover, HPA scales deployment on traffic spike. ADRs cover sidecar vs library vs node-agent trade-offs and operator vs Helm vs raw manifests for stateful workloads.
Kubernetes controllers, Jobs, probes and autoscaling
Kubernetes is a collection of reconciling controllers around an API. A Deployment, Job, HPA, scheduler and kubelet have different responsibilities; their combined result is eventually converged workload state, not a single atomic deployment transaction.
Database migration rule
Do not place a shared schema migration in every Deployment Pod's init container. Init containers run per Pod and may retry, so a rollout or scale-out can execute the migration concurrently. Use a distinct, versioned Job ordered before the workload, plus:
- backward-compatible expand/migrate/contract changes;
- an idempotent migration ledger;
- a database advisory lock or equally strong fence;
- bounded retries and an explicit ambiguous-outcome check.
A Job can recreate Pods and therefore is not, by itself, exactly-once.
HPA and probes
The base HPA calculation is:
desiredReplicas = ceil(currentReplicas * currentMetric / desiredMetric)
Kubernetes then handles unready Pods, missing metrics, tolerance, min/max bounds, scaling rate and stabilization. New Pods can remain Pending if node capacity or scheduling constraints do not fit.
Readiness controls traffic. Liveness controls restart. A liveness probe that fails whenever a shared database is slow can restart every Pod and amplify the incident; use a startup probe for slow initialization and make liveness test local progress.