⎈ k8s knowledge compiler

Assign Pod-level CPU and memory resources [page]deterministic

tasks

This page shows how to specify CPU and memory resources for a Pod at pod-level in addition to container-level resource specifications. A Kubernetes node allocates resources to a pod based on the pod's resource requests. These requests can be defined at the pod level or individually for containers within the pod. When both are present, the pod-level requests take precedence.

Similarly, a pod's resource usage is restricted by limits, which can also be set at the pod-level or individually for containers within the pod. Again, pod-level limits are prioritized when both are present. This allows for flexible resource management, enabling you to control resource allocation at both the pod and container levels.

In order to specify the resources at pod-level, it is required to enable `PodLevelResources` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/).

For Pod Level Resources: * Priority: When both pod-level and container-level resources are specified, pod-level resources take precedence. * QoS: Pod-level resources take precedence in influencing the QoS class of the pod. * OOM Score: The OOM score adjustment calculation considers both pod-level and container-level resources. * Compatibility: Pod-level resources are designed to be compatible with existing features.

##

The `PodLevelResources` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) must be enabled for your control plane and for all nodes in your cluster.

## Limitations

For Kubernetes , pod-level resources have the following limitations:

* Resource Types: Only CPU, memory and hugepages resources can be specified at pod-level. * Operating System: Pod-level resources are not supported for Windows pods. * Resource Managers: The Topology Manager, Memory Manager and CPU Manager support pod-level resources when the `PodLevelResourceManagers` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled. See [Pod-level resource managers](/docs/concepts/workloads/resource-managers/#pod-level-resource-managers) for more details. Without this feature gate enabled, they do not align pods and containers based on pod-level resources. * In-Place Resize: [In-place resize](/docs/tasks/configure-pod-container/resize-container-resources/) of pod-level resources requires the `InPlacePodLevelResourcesVerticalScaling` feature gate, which is alpha in Kubernetes . For more details, see [Resize Pod CPU and Memory Resources](/docs/tasks/configure-pod-container/resize-pod-resources/).

## Create a namespace

Create a namespace so that the resources you create in this exercise are isolated from the rest of your cluster.

```shell kubectl create namespace pod-resources-example ```

## Create a pod with memory requests and limits at pod-level

To specify memory requests for a Pod at pod-level, include the `resources.requests.memory` field in the Pod spec manifest. To specify a memory limit, include `resources.limits.memory`.

In this exercise, you create a Pod that has one Container. The Pod has a memory request of 100 MiB and a memory limit of 200 MiB. Here's the configuration file for the Pod:

The `args` section in the manifest provides arguments for the container when it starts. The `"--vm-bytes", "150M"` arguments tell the Container to attempt to allocate 150 MiB of memory.

Create the Pod:

```shell kubectl apply -f https://k8s.io/examples/pods/resource/pod-level-memory-request-limit.yaml --namespace=pod-resources-example ```

Verify that the Pod is running:

```shell kubectl get pod memory-demo --namespace=pod-resources-example ```

View detailed information about the Pod:

```shell kubectl get pod memory-demo --output=yaml --namespace=pod-resources-example ```

The output shows that the Pod has a memory request of 100 MiB and a memory limit of 200 MiB.

```yaml ... spec: containers: ... resources: requests: memory: 100Mi limits: memory: 2 …(trimmed)

Sources

tasks/configure-pod-container/assign-pod-level-resources.md · docAssign Pod-level CPU and memory resources

Related (11)

part_of {{% heading "prerequisites" %}}describes conf=1
part_of Limitationsdescribes conf=1
part_of Create a namespacedescribes conf=1
part_of Clean updescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of For application developersdescribes conf=1
part_of For cluster administratorsdescribes conf=1
api_for Poddocuments API object conf=1

← all Docs