Kubernetes v1.16
documentation is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the
latest version.

Configure Default Memory Requests and Limits for a Namespace

This page shows how to configure default memory requests and limits for a namespace.
If a Container is created in a namespace that has a default memory limit, and the Container
does not specify its own memory limit, then the Container is assigned the default memory limit.
Kubernetes assigns a default memory request under certain conditions that are explained later in this topic.

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must
be configured to communicate with your cluster. If you do not already have a
cluster, you can create one by using
Minikube,
or you can use one of these Kubernetes playgrounds:

Now if a Container is created in the default-mem-example namespace, and the
Container does not specify its own values for memory request and memory limit,
the Container is given a default memory request of 256 MiB and a default
memory limit of 512 MiB.

Here’s the configuration file for a Pod that has one Container. The Container
does not specify a memory request and limit.

The output shows that the Container’s memory request is set to the value specified in the
Container’s configuration file. The Container’s memory limit is set to 512Mi, which is the
default memory limit for the namespace.

resources:
limits:
memory: 512Mi
requests:
memory: 128Mi

Motivation for default memory limits and requests

If your namespace has a resource quota,
it is helpful to have a default value in place for memory limit.
Here are two of the restrictions that a resource quota imposes on a namespace:

Every Container that runs in the namespace must have its own memory limit.

The total amount of memory used by all Containers in the namespace must not exceed a specified limit.

If a Container does not specify its own memory limit, it is given the default limit, and then
it can be allowed to run in a namespace that is restricted by a quota.