0

Is there a way to apply a nodeSelector via command? (like kubectl apply)

It would be nice if it is applicable on running deployments or namespaces, otherwise applying to running pods is also fine.

Any tips are appreciated

Nur1
  • 418
  • 4
  • 11

1 Answers1

1

You can use the kubectl patch command, like this:

kubectl patch deployments nginx-deployment -p '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "node-2"}}}}}'

After successful patch all pods of the deployment will be restarted on a node matching the selector.

Chris
  • 5,109
  • 3
  • 19
  • 40
  • Even though I switched to the taint method to get my stuff done, this answer is correct and working. Thanks. – Nur1 Mar 22 '22 at 15:23