Chapter 5. Scheduler

One of the primary jobs of the Kubernetes API is to schedule containers to worker nodes in the cluster of machines. This task is accomplished by a dedicated binary in the Kubernetes cluster called the Kubernetes scheduler. This chapter describes how the scheduler operates, how it can be extended, and how it can even be replaced or augmented by additional schedulers. Kubernetes can handle a wide variety of workloads, from stateless web serving to stateful applications, big data batch jobs, or machine learning on GPUs. The key to ensuring that all of these very different applications can operate in harmony on the same cluster lies in the application of job scheduling, which ensures that each container is placed onto the worker node best suited to it.

An Overview of Scheduling

When a Pod is first created, it generally doesn’t have a nodeName field. The nodeName indicates the node on which the Pod should execute. The Kubernetes scheduler is constantly scanning the API server (via a watch request) for Pods that don’t have a nodeName; these are Pods that are eligible for scheduling. The scheduler then selects an appropriate node for the Pod and updates the Pod definition with the nodeName that the scheduler selected. After the nodeName is set, the kubelet running on that node is notified about the Pod’s existence (again, via a watch request) and it begins to actually execute that Pod on that node.

Note

If you want to skip the scheduler, you can always set the ...

Get Managing Kubernetes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.