Resource Requests and Limits for Pods

A pod definition can include both resource requests and resource limits:

  • Resource requests

    Used for scheduling, and to indicate that a pod is not able to run with less than the specified amount of compute resources. The scheduler tries to find a node with sufficient compute resources to satisfy the pod requests.

  • Resource limits

    Used to prevent a pod from using up all compute resources from a node. The node that runs a pod configures the Linux kernel cgroups feature to enforce the resource limits for the pod.

Resource request and resource limits should be defined for each container in either a deployment or a deployment configuration resource. If requests and limits have not been defined, then you will find a resources: {} line for each container.

Modify the resources: {} line to specify the desired requests and or limits. For example:

...output omitted...
 spec:
    containers:
    - image: quay.io/redhattraining/hello-world-nginx:v1.0
      name: hello-world-nginx
      resources:
        requests:
            cpu: "10m"
            memory: 20Mi
        limits:
            cpu: "80m"
            memory: 100Mi
status: {}

If you use the oc edit command to modify a deployment or a deployment configuration, ensure you use the correct indentation. Indentation mistakes can result in the editor refusing to save changes.

To avoid indentation issues, you can use the oc set resources command to specify resource requests and limits. The following command sets the same requests and limits as the preceding example.

oc set resources deployment hello-world-nginx \
> --requests cpu=10m,memory=20Mi --limits cpu=80m,memory=100Mi

If a resource quota applies to a resource request, then the pod should define a resource request. If a resource quota applies to a resource limit, then the pod should also define a resource limit. Red Hat recommends defining resource requests and limits even if quotas are not being used.

Daftar Materi