Use context: kubectl config use-context k8s-c2-AC
Ssh into the controlplane node with ssh cluster2-controlplane1
. Temporarily stop the kube-scheduler, this means in a way that you can start it again afterwards.
Create a single Pod named manual-schedule
of image httpd:2.4-alpine
, confirm it’s created but not scheduled on any node.
Now you’re the scheduler and have all its power, manually schedule that Pod on node cluster2-controlplane1
. Make sure it’s running.
Start the kube-scheduler again and confirm it’s running correctly by creating a second Pod named manual-schedule2
of image httpd:2.4-alpine
and check if it’s running on cluster2-node1
.
Manually Scheduling a Kubernetes Pod by Stopping the Scheduler
In this guide, we’ll explore how to manually schedule a Kubernetes Pod by temporarily stopping the Kubernetes scheduler. This exercise will give you a deeper understanding of how the scheduler works and how Pods are assigned to nodes.
Step 1: Stop the Scheduler
First, we need to identify the control plane node where the scheduler is running. Use the following command to list the nodes:
1 2 3 4 5 6 7 8 |
➜ kubectl get node NAME STATUS ROLES AGE VERSION cluster2-controlplane1 Ready control-plane 26h v1.30.1 cluster2-node1 Ready <none> 26h v1.30.1 |
Next, SSH into the control plane node and check if the scheduler is running:
1 2 3 4 5 6 7 8 |
➜ ssh cluster2-controlplane1 root@cluster2-controlplane1:~# kubectl -n kube-system get pod | grep schedule kube-scheduler-cluster2-controlplane1 1/1 Running 0 6s |
To stop the scheduler, move the scheduler’s manifest file out of the manifests directory:
1 2 3 4 5 6 |
➜ root@cluster2-controlplane1:~# cd /etc/kubernetes/manifests/ ➜ root@cluster2-controlplane1:~# mv kube-scheduler.yaml .. |
Verify that the scheduler has stopped:
1 2 3 4 5 |
➜ root@cluster2-controlplane1:~# kubectl -n kube-system get pod | grep schedule |
Step 2: Create a Pod
With the scheduler stopped, create a Pod using the following command:
1 2 3 4 5 |
kubectl run manual-schedule --image=httpd:2.4-alpine |
Check that the Pod has no node assigned:
1 2 3 4 5 6 7 |
➜ kubectl get pod manual-schedule -o wide NAME READY STATUS ... NODE NOMINATED NODE manual-schedule 0/1 Pending ... <none> <none> |
Step 3: Manually Schedule the Pod
To manually schedule the Pod, download its YAML definition and edit it to specify the node name:
1 2 3 4 5 |
kubectl get pod manual-schedule -o yaml > 9.yaml |
Edit the 9.yaml
file to include the node name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# 9.yaml apiVersion: v1 kind: Pod metadata: name: manual-schedule namespace: default spec: nodeName: cluster2-controlplane1 # add the controlplane node name containers: - image: httpd:2.4-alpine name: manual-schedule |
Since you cannot use kubectl apply
or kubectl edit
for this, you’ll need to replace the Pod:
1 2 3 4 5 |
kubectl replace -f 9.yaml --force |
Check if the Pod is now running on the control plane node:
1 2 3 4 5 6 7 |
➜ kubectl get pod manual-schedule -o wide NAME READY STATUS ... NODE manual-schedule 1/1 Running ... cluster2-controlplane1 |
Step 4: Restart the Scheduler
After manually scheduling the Pod, restart the scheduler by moving the manifest file back to its original location:
1 2 3 4 5 6 7 8 |
➜ ssh cluster2-controlplane1 root@cluster2-controlplane1:~# cd /etc/kubernetes/manifests/ root@cluster2-controlplane1:~# mv ../kube-scheduler.yaml . |
Verify that the scheduler is running again:
1 2 3 4 5 6 |
root@cluster2-controlplane1:~# kubectl -n kube-system get pod | grep schedule kube-scheduler-cluster2-controlplane1 1/1 Running 0 16s |
Step 5: Create a Second Test Pod
To confirm that the scheduler is working normally again, create another Pod:
1 2 3 4 5 |
kubectl run manual-schedule2 --image=httpd:2.4-alpine |
Check where both Pods are running:
1 2 3 4 5 6 7 |
➜ kubectl get pod -o wide | grep schedule manual-schedule 1/1 Running ... cluster2-controlplane1 manual-schedule2 1/1 Running ... cluster2-node1 |
Everything is back to normal, with the scheduler automatically assigning the second Pod to a node.
In this exercise, we manually scheduled a Kubernetes Pod by temporarily disabling the scheduler, showing how the scheduler assigns Pods to nodes and how you can intervene in this process if necessary.