#
Limit the RAM utilization
This tutorial explains how we can limit the RAM utilization by the containers in Kubernetes.
Kubernetes provides a shared pool of resources that it allocates based on how we configure our containerized applications.
By default, a pod in Kubernetes will run with no limits on CPU and RAM in a default namespace. This can create problems related to contention for resources.
You can provide more information for the scheduler using two parameters that specify RAM utilization:
Request
: sets the minimum amount of RAM required for the container. Kubernetes aggregates all container requests into a single pod request. This information is used by the Scheduler to take a decision regarding where Kubernetes could deploy a pod.Limit
: sets a maximum amount of allows RAM utilization by specifying a limit on the container.
Here we have an example of Pod definition using RAM limits in my-first-pod-ram.yml file:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-ram
labels:
zone: prod
version: v1
spec:
containers:
- name: nginx-c
image: nginx:1.14.2
ports:
- containerPort: 8080
resources:
requests:
memory: "64M"
limits:
memory: "128M"
Info
Limits and requests for memory are measured in bytes. You can express memory as a plain integer or as a fixed-point number using one of these quantity suffixes: E, P, T, G, M, k. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki.
For example, the following represent roughly the same value: 128974848, 129e6, 129M, 128974848000m, 123Mi.
"128M" = 128 megabytes.
In order to deploy this Pod we can run the following command:
kubectl apply -f my-first-pod-ram.yml