I am using Jenkins to deploy my Docker images to GKE by using the kubernetes plugin version 1.30.3. It works fine so far. But now I am trying to choose a defined node pool in GKE by adding a node selector but it doesn't work for me. This is the definition of the podTemplate in my Jenkins files:
podTemplate(label: '...', containers: [...],
volumes: [..],
nodeSelector: 'cloud.google.com/gke-nodepool: NAME OF THE NODE POOL'
)
Do you have any idea why this isn't working?
I already checked the resulting pod yaml
which doesn't include the defined nodeSelector
...
The nodeSelector provides a way to constrain pods with particular labels in GKE. All the node pools have labels with the following format:
cloud.google.com/gke-nodepool: POOL_NAME
. So you can use a specific node pool by using a nodeSelector and the label that you configured as aPOOL_NAME
like the following example:.́
Based on this, you will need to validate if the label was attached to your pod when it was created, you can check this by running this command:
kubectl get nodes
to get the names of your cluster's nodes, you can consult this guide to know more about how to set constraints to pods.