Kubernetes apply nodeSelector via command

1.3k views Asked by At

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

1

There are 1 answers

1
Chris On BEST ANSWER

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.