Kubernetes Scheduler 101

What is the Kubernetes Scheduler?

The default scheduler for Kubernetes, the kube-scheduler, runs as a part of the control plane and is an essential part of the Kubernetes platform. The Kubernetes Schedulers’ responsibility is to match a pod with an appropriate node. For every new Pod or unscheduled Pod, the scheduler monitors the object store and finds the optimal Node for the Pod to run on. The scheduler runs on master Nodes that work closely with the API server and controller.

Why Do You Need It?

The scheduler is a key part of one’s Kubernetes plan because scheduling helps fix optimization problems. For starters, the scheduler determines the optimal node to run a pod on – once they meet a set of given requirements and constraints. For specific scheduling requirements, you can configure the filtering and scoring behavior of the scheduler. You can do this by setting a scheduling policy that specifies the priorities for scoring and predicates for filtering. The other option is a scheduling profile, which allows you to configure Plugins that implement different scheduling stages. These specific requirements help with optimization as they will only check nodes that you have specified requirements for, cutting down on wasted time. You can save time by implementing the Kubernetes scheduler instead of spending time writing your own scheduling component. 

How Does The Scheduler Find The Appropriate Node For The Pod? 

The scheduler finds the appropriate node for the pod based on multiple different factors, one being available resources. Another way is users can influence the scheduler through node affinity. This is when a pod requests for a node specific characteristic. Users can also influence the scheduler through pod affinity, which is when a set of pods are placed on the same node to avoid latency.

The Kubernetes scheduler uses tolerations and taints to limit what workloads can run on nodes. A taint is assigned to a node which indicates only certain pods can be scheduled on them. The pod must have a toleration applied to it in order for it to tolerate a node’s taint. If the pod doesn’t define the appropriate toleration, then the Kubernetes scheduler can’t schedule pods on the node. In order to be scheduled, Nodes in a cluster must meet the scheduling requirements of a Pod – if they do they are referred to as feasible Nodes. The scheduler then scores the feasible Nodes and picks a Node with the highest score to run the Pod.

What You Need to Know About CronJob, The Kubernetes Job Scheduler

Kubernetes Job Scheduler, also known as a CronJob, creates Jobs on a repeating schedule. These jobs are batch or finite tasks. CronJobs are great for scheduling because they automate repetitive tasks (i.e., running backups or sending emails). As with cron jobs on other frameworks, a Kubernetes CronJob is responsible for creating Jobs that match its schedule. You can also schedule individual tasks for a specific time using a CronJob. For example, if your cluster is likely to be idle at a specific time, you can schedule a Job for that time. 

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully finish, the Job tracks the successful completions. The task is only complete once a certain number of successful completions have been reached. 

How to Schedule Pods 

Schedule Pods With Resource Requests

As mentioned above, when a Pod is created, the Kubernetes scheduler selects a node for the Pod to run on. Nodes have a max capacity for each resource type that tells them the amount of CPU and memory it can provide for Pods. For each resource type, the scheduler makes sure that the sum of the resource requests of the scheduled containers is less than the capacity of the node. 

Schedule Pods With Ephemeral-Storage Requests

Ephemeral storage has no long-term guarantee about durability, Pods typically use this storage for caching, logs and scratch space. Once a Pod is created and the Kubernetes scheduler selects a node for the Pod to run on, each node has a maximum amount of local ephemeral storage it can provide for Pods.

How to use the Kubernetes Scheduler Across Different Cloud Providers

Each of the big three cloud providers has a service to manage and deploy containers via Kubernetes container orchestration service. The Kubernetes services across the cloud providers are Amazon Elastic Kubernetes Service (EKS), Azure Kubernetes Service (AKS), and Google Kubernetes Engine (GKE)

Using EKS, you can plan, schedule, and execute your batch computing workloads across the full range of AWS compute services and features, such as Amazon EC2, Fargate, and Spot Instances.

With AKS, the Kubernetes scheduler provides features that let you control the distribution of compute resources, or limit the impact of maintenance events. The Kubernetes scheduler provides advanced features that let you control which pods can be scheduled on certain nodes, or how multi-pod applications can be appropriately distributed across the cluster. 

With GKE, when you submit a workload to run in a cluster, the scheduler then determines where to place the Pods associated with the workload. The scheduler can place a Pod on any node that satisfies the Pod’s memory, CPU, and custom resource requirements.

Another Type of “Scheduling” – to Reduce Kubernetes Costs 

While in Kubernetes, “scheduling” has a specific implication regarding pod/node matching; across many public cloud resources, “scheduling” often means to turn resources off when they’re not needed. Billions of dollars are wasted each year on idle cloud resources (among other sources of waste).

That same scheduling is available to reduce Kubernetes costs by scheduling clusters and node groups in EKS, AKS and GKE to turn off, avoiding costs incurred by idle resources. ParkMyCloud analyzes resource utilization history and creates recommended schedules for compute, database and container resources, and programmatically schedules and resizes them, saving enterprises around the world tens of millions of dollars. You can set schedules based on working hours and automatically assign those schedules with the platform’s policy engine. 

These features come with full user governance, self-service management of all projects in a single view, and flexible features such as schedule override.

Try it with a 14-day free trial today.