Allocating Insufficient Resource than the Actual Usage

Explore what happens when we allocate insufficient resources than the actual usage of an application.

Allocating insufficient memory#

Let’s take a look at a slightly modified version of the go-demo-2 definition as go-demo-2-insuf-mem.yml. When compared with the previous definition, the difference is only in resources of the db container in the go-demo-2-db Deployment.

Definition as `go-demo-2-insuf-mem.yml`

The memory limit is set to 20Mi and the request to 10Mi. Since we already know from Metrics Server’s data that MongoDB requires around 35Mi, memory resources are this time, much lower than the actual usage.

Applying the definition#

Let’s see what will happen when we apply the new configuration.

Applying Definition 'go-demo-2-insuf-mem.yml'

We applied the new configuration and retrieved the Pods. The output is as follows.

Output of 'kubectl get pods'

In your case, the status might not be OOMKilled. If so, wait for a while longer and retrieve the Pods again. The status should eventually change to CrashLoopBackOff.

As you can see, the status of the go-demo-2-db Pod is OOMKilled (Out Of Memory Killed). Kubernetes detected that the actual usage is way above the limit and it declared the Pod as a candidate for termination.

The container was terminated shortly afterward. Kubernetes will recreate the terminated container a while later only to discover that the memory usage is still above the limit. And so on, and so forth. The loop will continue.

ℹ️ A container can exceed its memory request if the node has enough available memory. On the other hand, a container is not allowed to use more memory than the limit. When that happens, it becomes a candidate for termination.

Looking into the deployment’s description#

Let’s describe the Deployment and see the status of the db container.

Describe pod 'go-demo-2-db'

The output, limited to relevant parts, is as follows.

Output of 'kubectl describe pod go-demo-2-db'

We can see that the last state of the db container is OOMKilled. When we explore the events, we can see that, so far, the container was restarted eight times with the reason BackOff.

Try it yourself#

For your ease, all the commands used in this lesson are given below.

Commands used in this Lesson

You can practice the commands in the following code playground by pressing the Run button and waiting for the cluster to set up.

/
go-demo-2-random.yml
go-demo-2-insuf-mem.yml
Exploring insufficient resources

Measuring the Actual Memory and CPU Consumption
Allocating Excessive Resource than the Actual Usage
Mark as Completed
Report an Issue