Cloud & GCP Engineer Guide: Production Kubernetes (GKE / EKS), Helm & Graceful Shutdown

Deploying containers to Google Kubernetes Engine (GKE) or Amazon EKS without properly tuned readiness probes, `preStop` lifecycle hooks, and `PodDisruptionBudget` manifests causes brief `502 Bad Gateway` errors on every rolling deployment. Why? Because when a pod is marked `Terminating`, the Kubernetes `kube-proxy` and Ingress controller update endpoint slices asynchronously—so new requests still arrive at the pod for 2–5 seconds after `SIGTERM` is sent! As a Senior Cloud Engineer and Google Certified Professional Cloud Architect, here is how I configure zero-dropped-request Kubernetes workloads.

1. Eliminating Rolling-Update `502` Errors with `preStop` & `PodDisruptionBudget`

Adding a short `preStop` sleep hook gives the cloud load balancer (GKE Container-Native Load Balancing `NEG` or AWS ALB Target Group) time to stop routing new connections to the pod before Gunicorn/Uvicorn/Go begins draining active requests:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: core-api
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    spec:
      terminationGracePeriodSeconds: 45
      containers:
        - name: api
          image: us-east1-docker.pkg.dev/prod-proj/apps/core-api@sha256:9f86d08...
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /healthz/ready
              port: 8080
            periodSeconds: 5
            failureThreshold: 2
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "sleep 10"]
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: core-api-pdb
spec:
  minAvailable: "75%"
  selector:
    matchLabels:
      app: core-api

2. Workload Identity & Non-Root Distroless Containers

Every pod runs with `runAsNonRoot: true`, `readOnlyRootFilesystem: true`, and binds to Google Cloud IAM or AWS IAM Roles for Service Accounts (IRSA) via Workload Identity—eliminating mounted JSON key files across the cluster.

3. Hire a Senior GCP & AWS Kubernetes Cloud Engineer

Hardening a GKE or EKS cluster or migrating workloads to Cloud Run / Kubernetes? Explore my Cloud Engineer Pillar Guide, review my GCP Engineer Pillar Guide, or book a 1-Day Kubernetes Architecture Sprint.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs