Home > database >  Can I have Kubernetes shut down pods that reach certain RAM percentage?
Can I have Kubernetes shut down pods that reach certain RAM percentage?

Time:11-18

I'm dealing with a certain service that causes (seemingly unresolvable) memory leaks from time to time. RAM memory inside of the container/pod grows high and stays that way. The pod soon becomes unusable and I would very much like to configure Kubernetes to mark those pods for termination and stop routing to them.

For example, if RAM reaches 80% inside the pod can I configure Kubernetes to shut down such pods?

Any links you can share about this would be great.

Thanks

CodePudding user response:

apiVersion: v1
kind: Pod
metadata:
  name: memory-demo
  namespace: mem-example
spec:
  containers:
  - name: memory-demo-ctr
    image: polinux/stress
    resources:
      limits:
        memory: "200Mi"

To specify a memory limit: resources:limits
when process use more than 200Mi,pod will be killed because it is out of memory (OOM)

CodePudding user response:

There are two different types of resource configurations that can be set on each container of a pod.

They are requests and limits.

Requests define the minimum amount of resources that containers need.

If you think that your app requires at least 256MB of memory to operate, this is the request value.

The application can use more than 256MB, but Kubernetes guarantees a minimum of 256MB to the container.

On the other hand, limits define the max amount of resources that the container can consume.

Your application might require at least 256MB of memory, but you might want to be sure that it doesn't consume more than 1GB of memory.This is your limit.

You can increase your request up to the limit range i.e, 1GB of memory. If the request is more than the limit, Kubernetes stops or throttles the pod.

For Example:

resources:

 limits:

   memory: 1 GB

  requests:

    memory: 256 MB
  • Related