Ram
Ram

Reputation: 197

Move Kubernetes statefulset pod to another node

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.

Upvotes: 8

Views: 9987

Answers (4)

Azar
Azar

Reputation: 101

Neither rollout nor updating replica's will work when it comes to statefulsets as it is mainly based on PVC configuration.

So to move the statefulset pod to different nodes you will have to reconfigure or update the PVC first and then redeploy statefulset. By doing so old PVC will get killed and a new one will be created on the new node.

Upvotes: 1

Moritur
Moritur

Reputation: 1748

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.

Upvotes: 3

RammusXu
RammusXu

Reputation: 1260

You will need affinity

And restart all statefulsets

kubectl rollout restart statefulset <stateful-set-name>

Upvotes: 1

Arghya Sadhu
Arghya Sadhu

Reputation: 44579

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>

Upvotes: 1

Related Questions