Ali Ilman

Ali Ilman

Resources in Kubernetes

Resources in Kubernetes

In Kubernetes, we can specify the resources a pod's containers can utilise, The resources usually specified are CPU and RAM.

There are two specifications to be familiarised with.

  1. Resource request
  2. Resource limit

Resource request is a specification that decides the minimum number of resources a container should should have, while resource limit is a specification that decides the maximum number of resources a container should have.

How do we specify resources for a container?

Here, my-container will utilise at least 1GB of RAM and 1 CPU, and limited to 2 CPU and around 2GB of RAM.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-container
      image: my-image
      resources:
        requests:
          memory: '1G'
          cpu: 1
        limits:
          memory: '2G'
          cpu: 2

In the world of Kubernetes, setting cpu to 1 is equivalent to 1 vCPU / Core for cloud providers and 1 hyper-thread on bare-metal Intel processors.

What happens if a container is using more CPU than the limit specified?

The container's CPU will be throttled so that it doesn't go beyond the limit.

What happens if a container is using more RAM than the limit specified?

The container can be terminated, though it will be restarted if allowed.

Resources

 
Share this