do-kubernetes
When to use
You need to write a Deployment/Service/Ingress set, debug a CrashLoopBackOff or pending pod, add autoscaling, or make a rollout safe and reversible.
Not for: building the container image (use do-dockerfile), provisioning the cluster or cloud resources (use do-terraform), or defining alerts and SLOs on the workload (use do-observability).
Method
- Pick the workload shape. Decision: stateless -> Deployment; needs stable identity/storage -> StatefulSet; run-to-completion -> Job/CronJob. Set replicas and a RollingUpdate strategy with maxUnavailable/maxSurge tuned to spare capacity.
- Configure the three probes distinctly: startup (covers slow boot), readiness (gates traffic), liveness (restarts a wedged pod). Decision: if a slow start triggers restarts, raise the startup probe budget — do not loosen liveness.
- Set requests and limits on every container. Requests drive scheduling and HPA; limits prevent noisy neighbors. Decision: omit CPU limits on latency-sensitive services to avoid throttling; keep memory limits to prevent OOM of neighbors.
- Add an HPA (or KEDA) keyed on CPU/memory or a custom metric, with sane min/max and a stabilization window.
- Externalize config via ConfigMap/Secret, mount rather than bake, and set a securityContext (non-root, drop capabilities, readOnlyRootFilesystem).
- To debug:
kubectl describe for events, logs --previous for crashes; check probe failures, image-pull errors, and resource pressure before editing.
Example
spec:
containers:
- name: api
image: registry/api@sha256:...
resources:
requests: { cpu: 100m, memory: 128Mi } # scheduling + HPA
limits: { memory: 256Mi } # no CPU limit: avoid throttle
startupProbe: # slow boot gets 30x5s = 150s
httpGet: { path: /healthz, port: 8080 }
failureThreshold: 30
periodSeconds: 5
readinessProbe: # gate traffic
httpGet: { path: /ready, port: 8080 }
livenessProbe: # restart if wedged
httpGet: { path: /healthz, port: 8080 }
periodSeconds: 10
Pitfalls
- One endpoint reused for liveness and readiness, so a dependency blip restarts healthy pods instead of just draining traffic.
- No resource requests — the scheduler bin-packs blindly and the HPA has no baseline to scale against.
- A liveness probe that fires during slow startup, producing a CrashLoopBackOff that looks like an app bug.
- CPU limits on a latency-sensitive service, causing throttling that reads as intermittent slowness.
Output format
Manifests: Deployment, Service, HPA, Ingress (as needed), valid YAML.
Probe/resource table per container:
| container | startup | readiness | liveness | cpu req | mem req/limit |
Rollout: kubectl rollout status deploy/<name>
Rollback: kubectl rollout undo deploy/<name>
Debug findings: likely root cause + evidence (event, log line).
1---2name: do-kubernetes3version: 1.0.04description: Author or debug Kubernetes manifests with distinct probes, right-sized resources, autoscaling, and safe reversible rollouts.5author: matrixx00706tags: [kubernetes, k8s, devops, orchestration, scaling, probes]7capabilities: []8metadata:9 source: https://skillmd.com/skills/matrixx0070/do-kubernetes10---1112# do-kubernetes1314## When to use1516You need to write a Deployment/Service/Ingress set, debug a CrashLoopBackOff or pending pod, add autoscaling, or make a rollout safe and reversible.1718**Not for:** building the container image (use do-dockerfile), provisioning the cluster or cloud resources (use do-terraform), or defining alerts and SLOs on the workload (use do-observability).1920## Method21221. Pick the workload shape. Decision: stateless -> Deployment; needs stable identity/storage -> StatefulSet; run-to-completion -> Job/CronJob. Set replicas and a RollingUpdate strategy with maxUnavailable/maxSurge tuned to spare capacity.232. Configure the three probes distinctly: startup (covers slow boot), readiness (gates traffic), liveness (restarts a wedged pod). Decision: if a slow start triggers restarts, raise the startup probe budget — do not loosen liveness.243. Set requests and limits on every container. Requests drive scheduling and HPA; limits prevent noisy neighbors. Decision: omit CPU limits on latency-sensitive services to avoid throttling; keep memory limits to prevent OOM of neighbors.254. Add an HPA (or KEDA) keyed on CPU/memory or a custom metric, with sane min/max and a stabilization window.265. Externalize config via ConfigMap/Secret, mount rather than bake, and set a securityContext (non-root, drop capabilities, readOnlyRootFilesystem).276. To debug: `kubectl describe` for events, `logs --previous` for crashes; check probe failures, image-pull errors, and resource pressure before editing.2829## Example3031```yaml32spec:33 containers:34 - name: api35 image: registry/api@sha256:...36 resources:37 requests: { cpu: 100m, memory: 128Mi } # scheduling + HPA38 limits: { memory: 256Mi } # no CPU limit: avoid throttle39 startupProbe: # slow boot gets 30x5s = 150s40 httpGet: { path: /healthz, port: 8080 }41 failureThreshold: 3042 periodSeconds: 543 readinessProbe: # gate traffic44 httpGet: { path: /ready, port: 8080 }45 livenessProbe: # restart if wedged46 httpGet: { path: /healthz, port: 8080 }47 periodSeconds: 1048```4950## Pitfalls5152- One endpoint reused for liveness and readiness, so a dependency blip restarts healthy pods instead of just draining traffic.53- No resource requests — the scheduler bin-packs blindly and the HPA has no baseline to scale against.54- A liveness probe that fires during slow startup, producing a CrashLoopBackOff that looks like an app bug.55- CPU limits on a latency-sensitive service, causing throttling that reads as intermittent slowness.5657## Output format5859```60Manifests: Deployment, Service, HPA, Ingress (as needed), valid YAML.6162Probe/resource table per container:63| container | startup | readiness | liveness | cpu req | mem req/limit |6465Rollout: kubectl rollout status deploy/<name>66Rollback: kubectl rollout undo deploy/<name>67Debug findings: likely root cause + evidence (event, log line).68```