Fix GCP GKE Pod Topology Errors
When working with GCP GKE, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with pod topology and shows the exact fix.
A Common Mistake
Creating a Deployment without pod topology spread constraints, allowing all pods to be scheduled on the same node or in the same zone, creating a single point of failure.
The incorrect command:
kubectl create deployment my-app --image=nginx --replicas=3
Error output:
deployment.apps/my-app created
kubectl get pods -o wide
NAME READY NODE
my-a-xxx 1/1 gke-cluster-pool-1-abc
my-a-yyy 1/1 gke-cluster-pool-1-abc
my-a-zzz 1/1 gke-cluster-pool-1-def
Two pods are on the same node. If that node fails, 2/3 pods are lost.
The Correct Approach
The right way to configure pod topology in GCP GKE:
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
template:
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: my-app
EOF
Successful result:
deployment.apps/my-app created
kubectl get pods -o wide
NAME READY NODE
my-a-xxx 1/1 gke-cluster-pool-1-abc
my-a-yyy 1/1 gke-cluster-pool-1-def
my-a-zzz 1/1 gke-cluster-pool-2-ghi
All pods on different nodes. Node failure takes down at most 1 pod.
How to Prevent This
Use pod topology spread constraints for high availability. Spread across nodes (kubernetes.io/hostname), zones (topology.kubernetes.io/zone), or regions (topology.kubernetes.io/region). Set maxSkew to 1 for even distribution. Use whenUnsatisfiable: DoNotSchedule for critical workloads, ScheduleAnyway for best-effort.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro