Fix GCP GKE Node Label 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 node label and shows the exact fix.
A Common Mistake
Adding a node label but expecting pods to be scheduled based on the label without setting nodeSelector or nodeAffinity, resulting in no effect on pod placement.
The incorrect command:
gcloud container node-pools create ssd-pool --cluster=my-cluster --zone=us-central1-a --machine-type=e2-standard-4 --node-labels=disk-type=ssd
Error output:
Created node pool with label disk-type=ssd.
But pods without nodeSelector schedule on any node. The label has no effect on scheduling unless pods specifically request it via nodeSelector or nodeAffinity.
The Correct Approach
The right way to configure node label in GCP GKE:
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: ssd-app
spec:
nodeSelector:
disk-type: ssd
containers:
- name: app
image: nginx
EOF
Successful result:
pod/ssd-app created
kubectl get pods -o wide
ssd-app is Running on the SSD node. The nodeSelector `disk-type: ssd` ensures the pod is scheduled only on nodes with that label.
How to Prevent This
Labels alone do not affect scheduling -- you must use nodeSelector or nodeAffinity in pods. Labels are useful for identification and grouping as well. Use kubectl get nodes --show-labels to see node labels. Use nodeAffinity for more flexible constraints (required vs preferred).
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