Resource Requests
(this post is part of the material I cover in my devops course)
When you specify a Pod, you can optionally specify how much of each resource a container needs.
Requests and limits
- Generally, you have these tools to control the resources that a pod will use:
- Resource Requests
- Resource Limits (which we'll demonstrate in another post)
- Resource Requests are evaluated before a pod is scheduled, and after that use weighting to make sure the pod gets its requesged CPU. Memoryy is evaluated mainly before scheduling.
- if there is an available CPU on a node, then pods share it using weights according their assigned requests.
- The CPU limit defines a hard ceiling on how much CPU time that the container can use.
Same is done for memory limit. - See more details here
Too many CPUs requested
- Here's an example of a pod definition, with a request that cannot be granted
- The pod requests 60 CPU units:
1apiVersion: v1
2kind: Pod
3metadata:
4 name: big-cpu-pod
5spec:
6 containers:
7 - name: busybox
8 image: busybox:latest
9 command:
10 - sleep
11 - "3600"
12 resources:
13 requests:
14 memory: "50M"
15 cpu: "60"
- This is what we see when we apply the definition:
1$>
2$> kubectl apply -f big-cpu-pod.yaml
3pod/big-cpu-pod created
4$> kubectl get pods
5NAME READY STATUS RESTARTS AGE
6big-cpu-pod 0/1 Pending 0 6s
7$> kubectl describe pods big-cpu-pod
8Name: big-cpu-pod
9Namespace: default
10Priority: 0
11Service Account: default
12Node: <none>
13Labels: <none>
14Annotations: <none>
15Status: Pending
16IP:
17IPs: <none>
18Containers:
19 busybox:
20 Image: busybox:latest
21 Port: <none>
22 Host Port: <none>
23 Command:
24 sleep
25 3600
26 Requests:
27 cpu: 60
28 memory: 50M
29 Environment: <none>
30 Mounts:
31 /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-rp2fd (ro)
32Conditions:
33 Type Status
34 PodScheduled False
35Volumes:
36 kube-api-access-rp2fd:
37 Type: Projected (a volume that contains injected data from multiple sources)
38 TokenExpirationSeconds: 3607
39 ConfigMapName: kube-root-ca.crt
40 ConfigMapOptional: <nil>
41 DownwardAPI: true
42QoS Class: Burstable
43Node-Selectors: <none>
44Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
45 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
46Events:
47 Type Reason Age From Message
48 ---- ------ ---- ---- -------
49 Warning FailedScheduling 21s default-scheduler 0/5 nodes are available: 5 Insufficient cpu. preemption: 0/5 nodes are available: 5 No preemption victims found for incoming pod.
50
51$>
- Note the Pending state, the 60 cpu requests and the Events section at the end/
Too much Memory requested
- Here's a simmilar experiment with memory.
- The pod definition:
1apiVersion: v1
2kind: Pod
3metadata:
4 name: big-mem-pod
5spec:
6 containers:
7 - name: busybox
8 image: busybox:latest
9 command:
10 - sleep
11 - "3600"
12 resources:
13 requests:
14 memory: "64Gi"
15 cpu: "250m"
- Note that the request is for 64 Gigibytes of memory.
- Now running it:
1$>
2$> kubectl apply -f big-mem-pod.yaml
3pod/big-mem-pod created
4$> kubectl get pods
5NAME READY STATUS RESTARTS AGE
6big-mem-pod 0/1 Pending 0 4s
7$> kubectl describe pods big-mem-pod
8Name: big-mem-pod
9Namespace: default
10Priority: 0
11Service Account: default
12Node: <none>
13Labels: <none>
14Annotations: <none>
15Status: Pending
16IP:
17IPs: <none>
18Containers:
19 busybox:
20 Image: busybox:latest
21 Port: <none>
22 Host Port: <none>
23 Command:
24 sleep
25 3600
26 Requests:
27 cpu: 250m
28 memory: 64Gi
29 Environment: <none>
30 Mounts:
31 /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-kr9jk (ro)
32Conditions:
33 Type Status
34 PodScheduled False
35Volumes:
36 kube-api-access-kr9jk:
37 Type: Projected (a volume that contains injected data from multiple sources)
38 TokenExpirationSeconds: 3607
39 ConfigMapName: kube-root-ca.crt
40 ConfigMapOptional: <nil>
41 DownwardAPI: true
42QoS Class: Burstable
43Node-Selectors: <none>
44Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
45 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
46Events:
47 Type Reason Age From Message
48 ---- ------ ---- ---- -------
49 Warning FailedScheduling 25s default-scheduler 0/5 nodes are available: 5 Insufficient memory. preemption: 0/5 nodes are available: 5 No preemption victims found for incoming pod.
50$>
51$>
- Pod is pending, with simmilar notes.
We'll cover more in further posts.