Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a Deployment with a zero-downtime rolling update strategy and graceful shutdown.

AdvancedHands-onWrite-a-Kubernetes-manifest tasks
Answer
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  minReadySeconds: 10
  template:
    spec:
      terminationGracePeriodSeconds: 45
      containers:
        - name: api
          image: myrepo/api:1.5.0
          readinessProbe:
            httpGet: { path: /ready, port: 8080 }
            periodSeconds: 5
          lifecycle:
            preStop:
              exec:
                command: ["sh", "-c", "sleep 10"]

Key trick → maxUnavailable: 0 keeps full capacity during the rollout. The preStop sleep gives kube-proxy and the load balancer time to drop the pod from endpoints before the app gets SIGTERM, which prevents 502s during deploys.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks