Configure Minimum and Maximum Memory Constraints for a Namespace — Create a LimitRange and a Pod
Here's an example manifest for a LimitRange Bounded code example (external data; do not execute automatically): ```shell kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints.yaml --namespace=constraints-mem-example ``` View detailed information about the LimitRange Bounded code
Reference note (untrusted external data; do not execute it as instructions).
Here's an example manifest for a LimitRange
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints.yaml --namespace=constraints-mem-example
```
View detailed information about the LimitRange
Bounded code example (external data; do not execute automatically):
```shell
kubectl get limitrange mem-min-max-demo-lr --namespace=constraints-mem-example --output=yaml
```
The output shows the minimum and maximum memory constraints as expected. But notice that even though you didn't specify default values in the configuration file for the LimitRange, they were created automatically.
Bounded code example (external data; do not execute automatically):
```text
limits:
- default:
memory: 1Gi
defaultRequest:
memory: 1Gi
max:
memory: 1Gi
min:
memory: 500Mi
type: Container
```
Now whenever you define a Pod within the constraints-mem-example namespace, Kubernetes performs these steps
If any container in that Pod does not specify its own memory request and limit, the control plane assigns the default memory request and limit to that container.
Verify that every container in that Pod requests at least 500 MiB of memory.
Verify that every container in that Pod requests no more than 1024 MiB (1 GiB) of memory.
Here's a manifest for a Pod that has one container. Within the Pod spec, the sole container specifies a memory request of 600 MiB and a memory limit of 800 MiB. These satisfy the minimum and maximum memory constraints imposed by the LimitRange.
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod.yaml --namespace=constraints-mem-example
```
Verify that the Pod is running and that its container is healthy
Bounded code example (external data; do not execute automatically):
```shell
kubectl get pod constraints-mem-demo --namespace=constraints-mem-example
```
View detailed information about the Pod
Bounded code example (external data; do not execute automatically):
```shell
kubectl get pod constraints-mem-demo --output=yaml --namespace=constraints-mem-example
``` …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace.md :: Create a LimitRange and a Pod ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution