Set nodeSelector/toleration to the running pods

Hi all,

I would like to set the nodeSelector/toleration to pod which is running. How can I do this?

Thank you.

Hello hlngai,

You have to set them in the POD definition YAML file then delete the running POD and recreate It.

Hello hlngai,

Kindly check the following steps:

  1. Kubectl get pod pod-name -o yaml> new.yml

  2. Kubectl delete -f new.yml

  3. Add nodeSelector/toleration.
    check the links:
    https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
    https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
    For example:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd
  1. kubectl apply -f new.yml

Hope this helps!

hi,

Thx so much for your input.

Does it mean nodeSelector/nodeAffinity can’t be added for running pods?

Since I am testing Kubeflow which the pods of Kubeflow component(a lot of pods) are deployed using kustomize.
And my purpose would like to restrict those pods (Kubeflow components) to specified nodes.

Thanks for you help