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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate