Move Kubernetes statefulset pod to another node

6/17/2020

My k8s cluster initially have 2node and 1master and I deployed statefulset with 3pods, so 3pods with PVC are running on 2 nodes. Now I increased nodes from 2 to 3. So now k8s is 3nodes and 1master. I would like to move one of the statefulset pod to newly added node without deleting PVC so that 3 pods will spread on 3nodes each. I tried deleting pod but it creates on same node and not on new node(which is expected). Can anyone please let me know if it is possible to move one pod to another node with out deleting PVC? is this achievable? or any alternate solution as I do not want to delete PVC.

-- Ram
kubernetes
kubernetes-pod
kubernetes-pvc
kubernetes-statefulset

3 Answers

7/16/2021

You can force a pod to be started on a different node by cordoning the node that the pod is running on and then redeploying the pod. That way kubernetes has to place it onto a different node. You can uncordon the node afterwards.

-- Moritur
Source: StackOverflow

6/17/2020

It's not recommended to delete pods of a statefulset. You can scale-down the statefulset to 2 replicas and then scale it up to 3.

kubectl get statefulsets <stateful-set-name>

kubectl scale statefulsets <stateful-set-name> --replicas=<new-replicas>
-- Arghya Sadhu
Source: StackOverflow

6/17/2020

You will need affinity

And restart all statefulsets

kubectl rollout restart statefulset <stateful-set-name>
-- RammusXu
Source: StackOverflow