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
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.
|
|
1 |
Log in as the root or NSP admin user on the NSP cluster host.
|
2 |
Open a console window.
|
3 |
Enter the following:
# kubectl get pods -A -o wide ↵
The pods are listed.
|
4 |
Enter the following to list all nodes:
# kubectl get nodes ↵
|
5 |
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.
|
6 |
Record the Memory Requests and CPU Requests values.
|
7 |
List the nodes to ensure that another node has sufficient capacity for the pod to move:
# kubectl describe nodes ↵
The nodes are listed.
|
8 |
View the Allocated resources value for each node to ensure that sufficient capacity exists according to the Requests value.
|
9 |
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.
-
Enter the following:
# kubectl get deployments -A ↵
The pods are listed.
-
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
-
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 |