Container Resource Requirements
Kubernetes allows you to specify the CPU and memory requirements for a container. As part of the Pod
spec you can specify CPU and memory requests
and limits
.
-
requests
- the CPU and memory resources required to run a container
- used by Kubernetes to decide what worker
Node
aPod
should be deployed to. This ensures there are sufficient resources on theNode
to run thePod
.
-
limits
- an upper limit for the resource usage of a container
- if a container exceeds these limits it will likely be destroyed.
- stops individual containers monopolising resources on a
Node
.
requests
and limits
are defined beneath resources
in the Pod
spec.
apiVersion: v1 kind: Pod metadata: name: container-resources-pod-demo spec: containers: - name: container-resources-pod-demo image: busybox command: [ "sh", "-c", "echo hello pod security & sleep 3600" ] resources: requests: memory: "32Mi" cpu: "400m" limits: memory: "64Mi" cpu: "600m"
Requested memory is 32Mi
(32 Mebibytes) which is approximately 32 megabytes. Allowed memory is capped at 64Mi
.
CPU is measured in cores. The requested CPU is 400m
which represents 400 milliCPUs or 0.4 CPU cores. The upper CPU limit is capped at 600m
or 600 milliCPUs.
After running the above Pod
you can use kubectl describe
to see the resource requirements in the running container.
The sample code for these notes is available here.
Leave A Comment