Edvin Cekani
Edvin Cekani
Software Developer
Edvin Cekani

Blog

Kubernetes Resource Requirements

Kubernetes Resource Requirements

Let's look at an exaple with three nodes Kubernetes cluster. Each node has a set of cpu, memory and disk resources available.

Every POD consumes a setof resources, lets say 2 cpu, 1 memory and some disk space. Whenever a pod is placed on a node it consumes resources available to that node.

It is the Kubernetes Scheduler that decides which node a pod goes to. The Scheduler taks into consideration the amount of resources required by a pod and these available on the node.

In this case the sceduler, schedules a ned pod on node 2. If the node has no sufficient resources, the scheduler avoids placing the pod on that node, instead places the pod on where are sufficient resources available.If there is no sufficient resources available on any of the three nodes, Kubernetes hosld back scheduling the pod. In his case the pod will be in a pending state.

By default Kubernetes assumes that a pod or a container within a pod requires 0,5 cpu , 256 mib memory. Resource request is the minimum amount of cpu or memory requested by the container.

When the scheduler tries to place the pod on a node, it uses these numbers to identify a node which has sufficient amount of resources available.

If you know that your application will need more than these, you can modify these values by specifying them in your pod or deployment definitnion file.

[pod-definition.yaml]

apiVersion: v1

kind: pod

medatata:

    name: test-webapp

   labels:

      name: test-webapp

spec:

  containers:

     - name: test-webapp

      image: test-webapp

      ports:

        - containerPort: 8080

     resources:

        request:

           memory: "1Gi"

           cpu: 1


1 amount of cpu is equal to 1vCPU

That 1 vCPU is 1 AWS vCPU, 1GCP Core, 1 Azure Core, 1 Hyperthread.

In a docker world, a docker container has no limits to the resources it can consume on a node. Lets suppose that a container starts with one vCpu on a node, it can go up and consume as much resource as requires, sofocating the native resources on a node or other containers. However you can set a limit of the resource usage on the pods by adding a limit section under the resources section in your pod definition file.

limits:

   memory : "2Gi"

   cpu: 2

When a pod is created, Kubernetes sets a new limit for the container. The limits and request are set for each container within the POD.

What happens when a POD tries to exceed resources beyond its specified limits?

In case of cpu, Kubernetes throttles the cpu so that it does not go beyon the specified limit. A container cannot use more cpu resources than its limit. However this rule does not apply, a container ca use more memory resources than its limit. If a pod tries to consime more memory than its limit constantyl, the pod will be terminated.

Free Web Hosting