Sobes.tech
Middle

What are limits and requests in Kubernetes?

sobes.tech AI

Answer from AI

Limits (limits) and requests (requests) in Kubernetes define resource consumption (CPU and memory) for containers.

  • requests: The minimum guaranteed amount of resources that a container will attempt to use. The Kubernetes scheduler considers requests when distributing pods across nodes to ensure the availability of declared resources.
  • limits: The maximum amount of resources a container can use. If a container tries to exceed the memory limit, it will be terminated (OOMKilled). Exceeding the CPU limit results in performance throttling but not termination.

Example in pod specification:

# Container specification
containers:
  - name: my-app
    image: my-image
    resources:
      requests:
        memory: "64Mi" # Request 64 megabytes of memory
        cpu: "250m"   # Request 0.25 CPU core (250 millicores)
      limits:
        memory: "128Mi" # Limit 128 megabytes of memory
        cpu: "500m"   # Limit 0.5 CPU core (500 millicores)

Units of measurement:

  • CPU: In millicores (m). 1000m = 1 core.
  • Memory: In bytes (B, kB, MB, GB, Ti, Pi...), preferably using binary prefixes (Ki, Mi, Gi, Ti, Pi...).

Importance:

  • Scheduling: Requests help Kubernetes efficiently distribute pods across nodes, preventing overload.
  • Stability: Limits prevent resource monopolization by a single pod, increasing cluster stability.
  • Cost Management: They allow estimating and controlling resource consumption, affecting cloud costs.

Without defining limits and requests, containers can receive unlimited resources, which may lead to node and cluster instability under high load.