1---2name: kubernetes-patterns3description: Kubernetes, Helm and Kustomize reference for designing and reviewing workload changes — deployments, probes, resources and autoscaling, disruption budgets, config and secrets, networking and ingress, jobs, rollout, and observability. Use when a feature's HLD or LLD changes Kubernetes-managed workloads.4allowed-tools: Read, Grep, Glob, Bash5tags: [stack:kubernetes, patterns, infra]6metadata:7 source: https://skillmd.com/skills/keyvaluesoftwaresystems/kubernetes-patterns8---910# kubernetes-patterns1112## Read the existing layout first1314- Find how workloads are packaged: Helm charts (`Chart.yaml`, `values-<env>.yaml`), Kustomize15 bases and overlays, or plain manifests per environment. Extend the chart or base the service16 already uses; per-environment differences go in values or overlays.17- Find the cluster-wide conventions already in place: ingress controller, certificate issuer,18 secret store (External Secrets, Sealed Secrets, CSI), service mesh, autoscaler (HPA, KEDA).1920## Workloads2122- **Deployment** for stateless services; **StatefulSet** only for workloads that need stable23 identity or storage (prefer a managed data store over running one in the cluster).24- **Probes**: readiness gates traffic (dependencies reachable, warm); liveness only detects a25 stuck process and must not call dependencies; a startup probe for slow starts.26- **Resources**: requests sized from measured usage, limits on memory; CPU limits only when the27 repository already uses them. Requests drive scheduling and HPA percentages.28- **Autoscaling**: HPA on CPU for compute-bound services; KEDA or custom metrics on queue depth or29 lag for workers. State min (availability), max (cost/backing-store limits) and the target, and30 check the database and downstream connection limits at max replicas.31- **Availability**: at least two replicas for user-facing services, a PodDisruptionBudget, and32 topology spread across zones when the cluster spans them.33- **Jobs and CronJobs**: idempotent, `concurrencyPolicy: Forbid` unless overlap is safe,34 `backoffLimit` and `activeDeadlineSeconds` set.35- **Graceful shutdown**: handle SIGTERM, drain in-flight work within36 `terminationGracePeriodSeconds`, and add a short preStop delay when behind a load balancer.3738## Config, secrets and networking3940- Config in ConfigMaps or chart values; secrets from the existing secret store, never in values41 files or images. Changing config should roll the pods (checksum annotation or a hashed name).42- Services are ClusterIP by default; expose through the existing ingress or gateway with TLS.43- NetworkPolicies follow the repository's default (deny-all plus explicit allows, when used).4445## Rollout and safety4647- RollingUpdate with `maxUnavailable: 0` for user-facing services; old and new versions must48 run side by side (backward-compatible APIs, expand/contract migrations).49- Database migrations run as a pre-deploy Job or init step that is safe to re-run, never inside50 every pod's start.51- Pin image tags or digests; never `latest`.5253## Observability5455- Metrics endpoint scraped by the existing stack (ServiceMonitor or annotations), structured logs56 to stdout, and alerts on the SLO the requirement states.5758## Verifying5960- `helm lint` / `helm template` or `kustomize build` for every environment, then schema validation61 (kubeconform) and the repository's policy checks when present.62- The LLD for the chart or manifests names each object added or changed and its per-environment63 values (replicas, resources, autoscaling bounds).