Skip to content
BIASED

Kubernetes in practice

Deploying a service in practice: ConfigMaps and Secrets, Ingress and service mesh at the idea level, Jobs/CronJobs, HPA and the desired-replicas formula, resources, network policies and limiting blast radius.

ConfigMaps and Secrets

Promote one image digest across environments; inject configuration separately. ConfigMap holds non-secret settings (feature endpoints, log level, upstream URLs) as env vars or mounted files. Secret holds credentials and TLS material the same way — but Kubernetes Secrets are base64-encoded in etcd, not encrypted by that encoding. Enable encryption at rest, tighten RBAC so only the workload's service account can read the Secret, and prefer external secret stores or sealed-secrets workflows over cleartext YAML in Git.

A common anti-pattern: baking ENV PAYMENT_URL=… into three different images for dev/staging/prod. That forces three digests and breaks "test what you ship." One digest + three ConfigMaps keeps CI honest. Mount config as files when you need atomic updates and sighup reloads; env vars are simple but require Pod restarts to change.

Rotate secrets by introducing a new version, rolling Pods, then retiring the old — the same expand/contract mindset as schema migrations. Sudden deletion of a live Secret mounts empty files and cascades into 500s.

Ingress and ingress traffic

North–south traffic usually enters through a load balancer into an Ingress (or Gateway API) object that declares host and path rules to Services. An ingress controller (nginx, Envoy-based, cloud-native) watches those objects and programs a proxy. TLS termination belongs at this edge unless you mesh mTLS everywhere — manage certificates with automation (cert-manager), not copy-pasted PEMs in tickets.

Richer routing — weighted canaries, header-based splits, retries — often means Gateway API, a service mesh, or cloud load-balancer features beyond basic Ingress. Pick one approach per platform; three overlapping layers of retries recreate the amplification problem from the resilience topic.

NetworkPolicy (with a CNI that enforces it) limits east–west traffic: deny by default, allow only the paths you intend (frontend → API → database proxy). Namespaces alone do not isolate — any Pod can often talk to any Service IP until policy says otherwise. Start with policies for the highest-value paths (data stores, metadata APIs) if a full zero-trust mesh is not yet in reach.

Jobs and HPA

Jobs run Pods to completion (batch reports, migrations); CronJobs schedule them (0 3 * * * for a nightly reconcile). Set active deadlines and backoff limits so a crashing migration does not retry forever into peak traffic. Prefer Job-backed migrations gated in CD over "kubectl exec and hope."

Horizontal Pod Autoscaler sets desired replicas from metrics:

ndesired=⌈n⋅mm∗⌉.n_{\mathrm{desired}} = \left\lceil n \cdot \frac{m}{m^*} \right\rceil.

Example: n=4n=4 replicas, current metric m=90m=90, target m∗=60m^*=60 → ⌈4⋅90/60⌉=6\lceil 4\cdot 90/60\rceil=\mathbf{6}. Scale on saturation relative to requests (CPU utilisation vs request), not vs limit or vs machine size — otherwise the signal lies. HPA reacts in minutes; it does not replace capacity planning for zone loss (still need the 3+3+3 style headroom from cloud building blocks) or for cold-start-heavy workloads where scale-up is slow.

Custom metrics (queue depth, RPS per Pod) often beat CPU for request-serving services: CPU can be low while the queue explodes on a slow dependency. Stabilisation windows prevent flapping when traffic is bursty.

Resources and QoS

Always set requests (and sensible limits). Empty resources → the scheduler packs blindly and the kubelet classifies Pods as BestEffort — first to evict under node pressure. Guaranteed (request=limit) and Burstable classes are the normal production choices. Pair with PodDisruptionBudgets so voluntary drains (node upgrades) cannot take all replicas at once, and with topology spread constraints so a Deployment does not land every replica on one zone or one node.

Probes, PDBs, requests and spread are the boring checklist that turns "we run on Kubernetes" into "Kubernetes rollouts and failures stay within the error budget." Skip them and the control plane will still reconcile — just not toward a state users enjoy.

ResourceQuota and LimitRange per namespace stop one team from scheduling the cluster into failure. Set defaults for requests so a forgotten YAML cannot land BestEffort in production namespaces. Ephemeral storage requests matter too: log-spewing containers fill node disks and trigger eviction of neighbours.

ImagePullBackOff and CrashLoopBackOff are status signals, not root causes — check digest existence, registry auth, and startup probes before widening timeouts. For Jobs that must not overlap (ledger compaction), set concurrency policy Forbid and alert on missed schedules. The practical cluster is mostly YAML discipline plus a few controllers; resist installing every operator in the catalog until each has an owner and an SLO.

When HPA and Cluster Autoscaler interact, scale-up latency is the sum of both: new Pods Pending until nodes appear. Warm pools or over-provisioning priority Pods shrink that delay for latency-critical services. Watch Pending reason metrics; "we have HPA" is not the same as "we have capacity."

Sidecars for mesh or log shipping consume requests too — budget their CPU/memory in the Pod sum or the node fills with invisible neighbours. Keep one idea of "what is the service" in dashboards: app container RED, not only Envoy's.

Next: Observability — logs, metrics and traces that tell you what the running system does, so HPA, canaries and incident command have something true to look at.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.