Search code examples
kubernetesresources

Allow resource limit violation for some time


I have a pod which exceeds the disk resource limits sometimes for a short time. The pod then gets evicted. Is there a way to allow the pod to exceed the resource limits for e.g. 30 seconds?


Solution

  • Yes, if the sizeLimit is breached your Pod will be evicted (Kubernetes will terminate your containers and schedule a replacement Pod). If the node where a Pod is running has enough of a resource available, it's possible for a container to use more resources than its request for that resource specifies. However, a container is not allowed to use more than its resource limit.

    As suggested by David Maze, Nodes have local ephemeral storage. You can provide a default ephemeral-storage request and limit on your LimitRange. A LimitRange is a policy to constrain resource allocations (to Pods or Containers) in a namespace.

    To make the resource quota work on ephemeral-storage, two things need to be done:

    • An admin sets the resource quota for ephemeral-storage in a namespace.
    • A user needs to specify limits for the ephemeral-storage resource in the Pod spec.

    The kubelet can measure how much local storage it is using. It does this provided that you have set up the node using one of the supported configurations(single or two file systems) for local ephemeral storage.If you have a different configuration, then the kubelet does not apply resource limits for ephemeral local storage.

    If the user doesn't specify the ephemeral-storage resource limit in the Pod spec, the resource quota is not enforced on ephemeral-storage.

    Kubernetes lets you track, reserve and limit the amount of ephemeral local storage a Pod can consume.If a Pod is using more ephemeral storage than you allow it to, the kubelet sets an eviction signal that triggers Pod eviction.

    Example:

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        resources:
          requests:
            ephemeral-storage: "2Gi"
          limits:
            ephemeral-storage: "4Gi"
        
    

    You can refer to how pods with ephemeral storage requests are scheduled.