Selected topic

Resource Requests and Limits

Scheduling

Prefer practical output? Use related tools below while reading.

Resource Requests:

  • A request is the minimum amount of a resource (e.g., CPU or memory) that a Pod needs to run.
  • The request is used by the kubelet to schedule the Pod on a node, ensuring there is enough resources available.
  • If the requested resource is not available on any node, the Pod cannot be scheduled.

Resource Limits:

  • A limit is the maximum amount of a resource (e.g., CPU or memory) that a Pod can use.
  • The limit prevents the Pod from consuming too many resources and impacting other Pods running on the same node.
  • If a Pod exceeds its resource limits, it will be terminated by the kubelet.

Example:

Suppose we have a Deployment with 3 replicas of a Pod that requests 1 CPU core and 512 MiB of memory. The Pod also has a limit of 2 CPU cores and 1024 MiB of memory.
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: example-app
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
      - name: example-container
        image: example/image:latest
        resources:
          requests:
            cpu: 100m
            memory: 512Mi
          limits:
            cpu: 200m
            memory: 1024Mi

In this example:

  • The Pod requests 1 CPU core (100m) and 512 MiB of memory, which means it needs at least that much resource to run.
  • The Pod has a limit of 2 CPU cores (200m) and 1024 MiB of memory, which means it can use up to those amounts of resources, but not more.
If the node running this Deployment has:
  • Less than 1 CPU core available
  • Less than 512 MiB of memory available
The Pod will not be scheduled, as the requested resources are not available on any node.

However, if there is enough resources available on a node (e.g., 2 CPU cores and 1024 MiB of memory), the Pod can run without exceeding its resource limits. If it uses more than its allowed resources, it will be terminated by the kubelet to prevent impacting other Pods running on the same node.

I hope this summary helps! Let me know if you have any further questions.