How do I move a Kubernetes pod to a different node?

Purpose

The following steps describe how to move a non-pinned Kubernetes pod to a different node in an NSP cluster. This action may be required, for example, when you need to allocate additional node capacity to a pod that is pinned to a specific node.

Note: You can only move pods that are not pinned to a specific node using labels.

Steps
CAUTION 

CAUTION

System Degradation

The procedure includes operations that fundamentally reconfigure the NSP system.

You must contact Nokia support for guidance before you attempt to perform the procedure.

 

Log in as the root user on the NSP cluster host.


Open a console window.


Enter the following:

kubectl get pods -A -o wide ↵

The pods are listed.


Enter the following to list all nodes:

kubectl get nodes ↵


Enter the following:

kubectl describe nodes node

where node is the name of the node that has the pod to move

The node resources are listed.


Record the Memory Requests and CPU Requests values.


List the nodes to ensure that another node has sufficient capacity for the pod to move:

kubectl describe nodes ↵

The nodes are listed.


View the Allocated resources value for each node to ensure that sufficient capacity exists according to the Requests value.


Enter the following to cordon the node that the pod is currently running on in order to prevent new pods from being scheduled on the node:

kubectl cordon node

where node is the name of the node to cordon

Note: Existing pods on the node continue to run and are unaffected.


10 

Restart the pod you intend to move.

  1. Enter the following:

    kubectl get deployments -A ↵

    The pods are listed.

  2. Enter the following to stop the pod:

    kubectl scale deployment pod -n $(kubectl get pods -A | awk '/pod/ {print$1;exit}') --replicas=0 ↵

    where pod is the pod name

  3. Enter the following to start the pod:

    kubectl scale deployment pod -n $(kubectl get pods -A | awk '/pod/ {print$1;exit}') --replicas=1 ↵

The pod is scheduled on a different node.


11 

Verify that the pod is successfully moved to another node; enter the following:

kubectl get pods -A -o wide ↵

The pods are listed.


12 

Uncordon the node; enter the following:

kubectl uncordon node

where node is the node name

The node enters the Initializing state, and then moves to the "Running" state.


13 

If the pod remains in the Pending state, no other node may have sufficient resources to host the pod; enter the following:

kubectl describe pod pod_name -n $(kubectl get pods -A | awk '/<pod_name>/ {print$1;exit}') ↵

Information about why the pod remains in the Pending state is displayed:


14 

Close the console window.

End of steps