Scheduler
- Kubernetes schedulers looks at the resource requirements of the pods and then schedules them on the node where the resources are available
- If all the nodes are exhausted then the scheduler will not schedule the pod
- In this case the pod remains on PENDING status.
- This can be seen in the pod events
- By default a kubernetes assumes that a container within the pod requires (min) 0.5 CPU, 256Mi resources
- If the pod requires more than this, then it can be set in the pod or the deployment definition file
- CPU can be set as 0.5, 0.4 or 0.1 or 1 CPU count. 0.1 can also be mentioned as 100m
- 1 CPU count means, 1 AWS vCPU, 1 GCP Core, 1 Azure Core, 1 Hyperthread
- 1 Mi (pronounced as 1 Mebi byte = 1024 * 1024 bytes = 1024 Ki (Kibi byte)
- Resources are configured at the container level, not pod level. But since a pod is a deployment unit, the total resources required by the containers of a pod is highlighted using requests and limits
Specify | Description |
---|---|
Requests | The requests specification is used at pod placement time: Kubernetes will look for a node that has both enough CPU and memory according to the requests configuration. |
Limits | This is enforced at runtime. If a container exceeds the limits, Kubernetes will try to stop it. For CPU, it will simply curb the usage so a container typically can't exceed its limit capacity ; it won't be killed, just won't be able to use more CPU. If a container exceeds its memory limits, it could be terminated. |
1 G (Gigabyte) = 1,000,000,000 bytes
1 M (Megabyte) = 1,000,000 bytes
1 K (Kilobyte) = 1,000 bytes
1 Gi (Gibibyte) = 1,073,741,824 bytes
1 Mi (Mebibyte) = 1,048,576 bytes
1 Ki (Kibibyte) = 1,024 bytes
- Default values for the pods are picked up from the default values set in the namespace using LimitRange object
- This is helpful when you want to specify a fixed amount of resources for the namespaces
- Total value of the resources of all the pods cannot be more than what is set at the namespace level.
- In a docker world, there is no limit on the resources for the container.
- So a container can start with 1vCPU and quickly consume all the CPUs suffocating the node
- But in Kubernetes, if not specified then a Pod is limited (max) to 1 vCPU and memory to 512Mi. This can be overwritten in the pod or deployment definition file.
- In the pod definition file below, (overwriting the default values)
- spec.resources.requests specify the minimum resources assigned to the container and
- spec.resources.limits specify the maximum resources assigned to the container
- If a container tries to use more CPU than what is set in the limits, kubernetes will THROTTLE the container
- But this is not the case with memory, kubernetes will allow to use more memory than what is set in limits, but if this is constantly done then the container is terminated
pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: nginx-container
image: nginx
resources:
requests:
memory: "1Gi"
cpu: 1
limits:
memory: "2Gi"
cpu: 2
apiVersion: v1
kind: LimitRange
metadata:
name: mem-limit-range
spec:
limits:
- default:
memory: 512Mi
defaultRequest:
memory: 256Mi
type: Container
---
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-limit-range
spec:
limits:
- default:
cpu: 1
defaultRequest:
cpu: 0.5
type: Container
Comments
Post a Comment