This post introduces Kubernetes scheduler from a newbie’s narrative.
K8s uses namespace to divide a physical cluster to multiple virtual clusters. Together with Resource Quota
, k8s can divide cluster resources between multiple users.
ResourceQuota
object provides constraints that limit aggregated resource consumption per namespace
. It supports
Compute Resource Quota
, e.g memory/cpu/gpu etcStorage Resource Quota
, e.g volume claims, persistent volume claims etcObject Count Quota
, this allows user to set limits for various of object counts, such as number of services, deployment/relicaset apps etc.Scope
, available scope includs Terminating
, NotTerminating
, BestEffort
, NotBestEffort
.ResourceQuota
can be created per PriorityClass
Limitations
Here is an example of Resource quota
// mem-cpu-quota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-demo
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
Create the ResourceQuota
kubectl create -f mem-cpu-quota.yaml --namespace=quota-mem-cpu-example
When a pod cannot be scheduled, k8s scheduler can preempt (evict) lower priority pods to make room for the pending pods.
Detail: When Pods are created, they go to a queue and wait to be scheduled. The scheduler picks a Pod from the queue and tries to schedule it on a Node. If no Node is found that satisfies all the specified requirements of the Pod, preemption logic is triggered for the pending Pod. Let’s call the pending Pod P. Preemption logic tries to find a Node where removal of one or more Pods with lower priority than P would enable P to be scheduled on that Node. If such a Node is found, one or more lower priority Pods get deleted from the Node. After the Pods are gone, P can be scheduled on the Node.
Limitations: