What happens when a pod exceeds its memory limit

0 votes
When a pod exceeds its memory limit? What happens?
Jul 19, 2019 in Kubernetes by Athira
8,195 views

1 answer to this question.

+1 vote
  • Whenever a pod exceeds its memory limit a signal SIGKILL is sent which  immediately terminates the container and spawns a new one with OOM(out of memory) error. 

  • The OS, if using a cgroup based containerisation (docker, rkt, etc), will do the OOM killing. 

  • Kubernetes simply sets the cgroup limits but is not ultimately responsible for killing the processes.

  • 'SIGTERM ' is sent to PID 1 and k8s waits for (default of 30 seconds) `terminationGracePeriodSeconds` before sending the `SIGKILL` or you can change that time with terminationGracePeriodSeconds in the pod.

  • As long as your container will eventually exit, it should be fine to have a long grace period. If you want a graceful restart it would have to do it inside the pod. 

  • If you don't want it killed, then you shouldn't set a memory `limit` on the pod and there's not a way to disable it for the whole node. 

  • Also, when the liveness probe fails, the container will SIGTERM and SIGKILL after some grace period.

answered Jul 19, 2019 by Sirajul
• 59,230 points
0 votes
( Note that the memory limit is set at the container level and not at the pod level )

In most CRI Implementations, Kubernetes only sets the cgroups and it is the job of the OS (  OOM killer ) to kill the process if it exceeds the memory limit.

Also note that if the main process has forked and created multiple processes inside the container, ( Or if you are exec ing inside the container using kubectl ) , OS will not kill all processes within the group. Instead,  OS will decide  ( using oom score )  on a single process to kill first. If this process is not the PID 1 , then the container will not restart. ( So, if you use a third party program like stress-ng -  which forks multiple times - in order to stress test the application, make sure you pay attention to teh logs )
answered Jan 31, 2023 by Sony Antony

edited Mar 5

Related Questions In Kubernetes

0 votes
1 answer

How to terminate a pod when a specific event occurs?

You need to add a liveness and ...READ MORE

answered Jul 19, 2019 in Kubernetes by Sirajul
• 59,230 points
1,360 views
0 votes
1 answer

What is Ingress ? Is it something that runs as a pod or on a pod?

An ingress is an object that holds ...READ MORE

answered Jul 19, 2019 in Kubernetes by Sirajul
• 59,230 points
2,002 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,937 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,248 views
0 votes
1 answer

What happens when a master or worker node fails?

Whenever master node under kubernetes fails, the ...READ MORE

answered Jul 15, 2019 in Kubernetes by Sirajul
• 59,230 points
4,689 views
0 votes
1 answer

Is there a way to make a pod to automatically come up when the host restarts?

Yes using replication controller but it may ...READ MORE

answered Jul 19, 2019 in Kubernetes by Sirajul
• 59,230 points
2,554 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP