0% found this document useful (0 votes)
537 views

Lab14 - Kubernetes Scheduler

The document describes a lab on configuring the Kubernetes scheduler. It discusses scheduling pods manually by specifying the nodeName, using node selectors to schedule pods to nodes with certain labels, and allowing the default scheduler to distribute pods across nodes without selectors. It provides steps to create pods with different scheduling configurations, view pod scheduling, and add/remove node labels. Finally, it cleans up the created pods and configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
537 views

Lab14 - Kubernetes Scheduler

The document describes a lab on configuring the Kubernetes scheduler. It discusses scheduling pods manually by specifying the nodeName, using node selectors to schedule pods to nodes with certain labels, and allowing the default scheduler to distribute pods across nodes without selectors. It provides steps to create pods with different scheduling configurations, view pod scheduling, and add/remove node labels. Finally, it cleans up the created pods and configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lab: Kubernetes Scheduler

Introduction
Scheduler watches for newly created Pods that have no Node assigned. For every Pod that the
scheduler discovers, the scheduler becomes responsible for finding the best Node for that Pod
to run on. The scheduler reaches this placement decision taking into account the scheduling
principles described below.
kube-scheduler is the default scheduler for Kubernetes and runs as part of the control plane.
kube-scheduler is designed so that, if you want and need to, you can write your own scheduling
component and use that instead.
In this Lab, you will learn below items:

Objective:

• Schedule Pods with NodeName


• Schedule Pods with NodeSelector
• Schedule Pods with NodeSelector and Label
• Clean up

Note: Ensure you have running cluster deployed.


1 Ensure that you have logged-in as root user with password as linux on kube-master node.

1.1 Let us clone the git repository which contains manifests required for this exercise, by executing the
below command.

# git clone https://github.com/EyesOnCloud/k8s-scheduler.git

Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
1.2 Let us list the nodes of our cluster, by executing the below command.

# kubectl get nodes


Output:

1.3 Let us view the manifest for pod which can assign pod to the node manually, by executing the below
command.

# cat -n ~/k8s-scheduler/manual-pod.yaml
Output:

1.4 Let us create the pod, by executing the below command.

# kubectl apply -f ~/k8s-scheduler/manual-pod.yaml


Output:

1.5 Let us list the pod, by executing the below command.


# kubectl get pods
Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
# kubectl get pods -o wide
Output:

Specifying the field nodeName, we can direct Kubernetes where to deploy the Pod, bypassing the kube-
scheduler

1.6 Let us delete this pod, by executing the below command.

# kubectl delete -f ~/k8s-scheduler/manual-pod.yaml


Output:

1.7 Let us edit the manifest to run the pod on kube-node2, by executing the below command.

# sed -i 's/node1/node2/g' ~/k8s-scheduler/manual-pod.yaml

1.8 Let us view the manifest for pod, by executing the below command.

# cat -n ~/k8s-scheduler/manual-pod.yaml
Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
1.9 Let us recreate the pod, by executing the below command.

# kubectl apply -f ~/k8s-scheduler/manual-pod.yaml


Output:

1.10 Let us list the pod, by executing the below command.

# kubectl get pod -o wide


Output:

Note: The pod is scheduled on kube-node2 as mentioned in the manifest.

2 Let us view the labels of the nodes in our cluster, by executing the below command.

# kubectl get nodes --show-labels


Output:

2.1 Let us add a label to the kube-node1, by executing the below command.

# kubectl label node kube-node1 disktype=ssd


Output:

2.2 Let us verify the node label, by executing below command.

# kubectl get nodes --show-labels


Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
2.3 Let us view the node details, by executing the below command.

# kubectl describe node kube-node1


Output:

Let us schedule the pods using the nodeselector-disktype.

2.4 Let us view the manifest for pod, by executing the below command.

# cat -n ~/k8s-scheduler/manual-pod-disktype.yaml
Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
2.5 Let us create the pod, by executing the below command.

# kubectl apply -f ~/k8s-scheduler/manual-pod-disktype.yaml


Output:

2.6 Let us verify the pod details, by executing the below command.

# kubectl get pods manual-pod-disktype -o wide


Output:

Note: Pod will get scheduled on the node that you attached the label

2.7 Let us remove labels from the node, by executing the below command.

# kubectl label node kube-node1 disktype-


Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3 Run PODs on any Node

In this section let us see, how the PODs are distributed among the nodes when no nodeSelector is set
on the PODs. We expect a more or less even distribution of the PODs among the nodes.

3.1 Let us view the manifest of the pod, by executing the below command.

# cat -n ~/k8s-scheduler/default-scheduler.yaml
Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3.2 Let us create the pod, by executing the below command.

# kubectl apply -f ~/k8s-scheduler/default-scheduler.yaml


Output:

3.3 Let us verify the details of the pods, by executing the below command.

# kubectl get pods -o wide


Output:

3.4 Let us delete the pods, by executing the below command.

# kubectl delete -f ~/k8s-scheduler/default-scheduler.yaml


Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3.5 Let us create PODs with add NodeSelector with unmatched nodes. Let us view the mainfest of the
pod, by executing the below command.

# cat -n ~/k8s-scheduler/node-selector.yaml
Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3.6 Let us create the pods, by executing the below command.

# kubectl apply -f ~/k8s-scheduler/node-selector.yaml


Output

3.7 Let us view the details of the pods, by executing the below command.

# kubectl get pods


Output:

3.8 We can see that the PODs are in pending status since the scheduler has not yet found any matching
node. Let us look more closely:

# kubectl describe pod pod-1


Output:

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3.9 Let us label the kube-master node to match the Node Selector of the PODs

# kubectl label nodes kube-master vip=maybe --overwrite


Output:

3.10 Let us verify the status of the pods, by executing the below command.

# kubectl get pods -o wide


Output:

3.11 Let us now remove the Label from the kube-master node, by executing the below command.

# kubectl label nodes kube-master vip-

Output:

3.12 After removing the lable for master let us verify the pod details, by executing the below
command.

# kubectl get pods -o wide


Output:

Note: We see that the nodeSelector is applied during Scheduling only: running PODs are still running on
the node, even if the label is removed from the node, it will not affect the already running pods.

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/
3.13 Let us delete and recreate the pod and check if the pod gets scheduled.

# kubectl delete pod pod-1

Output:

3.14 Let us view the manifest file.

# cat -n ~/k8s-scheduler/node-selector-vip.yaml
Output:

3.15 Let us re-create the pod, by executing the below command.

# kubectl create -f ~/k8s-scheduler/node-selector-vip.yaml


3.16 Let us verify the pod details, by executing the below command.

# kubectl get pods -o wide


Output:

Note: As expected, the Pod is in pending state.

4 Let us clean up, by executing the below command.

# kubectl delete -f ~/k8s-scheduler/

Student Material – Do Not Re-distribute. For any queries contact:


[email protected] or https://www.linkedin.com/in/naushadpasha/

You might also like