# Limit the RAM utilization

In 
Published 2022-12-03

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:

my-first-pod-cpu.yml
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"

In order to deploy this Pod we can run the following command:

kubectl apply -f my-first-pod-ram.yml