Configure resource requests and limits

You can configure resource limits and requests, specifically for CPU and memory, for individual Knative services.

The following example shows how you can set the requests and limits fields for a service:

  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: example-service
  5. namespace: default
  6. spec:
  7. template:
  8. spec:
  9. containers:
  10. - image: docker.io/user/example-app
  11. resources:
  12. requests:
  13. cpu: 100m
  14. memory: 640M
  15. limits:
  16. cpu: 1

Configure Queue Proxy resources

In order to set the Queue Proxy resource requests and limits you can either set them globally in the deployment config map or you can set them at the service level using the corresponding annotations targeting cpu, memory and ephemeral-storage resource types. The above example becomes:

  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: example-service
  5. namespace: default
  6. spec:
  7. template:
  8. metadata:
  9. annotations:
  10. queue.sidecar.serving.knative.dev/cpu-resource-request: "1"
  11. queue.sidecar.serving.knative.dev/cpu-resource-limit: "2"
  12. queue.sidecar.serving.knative.dev/memory-resource-request: "1Gi"
  13. queue.sidecar.serving.knative.dev/memory-resource-limit: "2Gi"
  14. queue.sidecar.serving.knative.dev/ephemeral-storage-resource-request: "400Mi"
  15. queue.sidecar.serving.knative.dev/ephemeral-storage-resource-limit: "450Mi"
  16. spec:
  17. ...

Alternatively, you could use a special annotation queue.sidecar.serving.knative.dev/resource-percentage that calculates the Queue Proxy resources as a percentage of the application’s container. In this case there are min, max boundaries applied to the cpu and memory resource requirements:

Resource RequirementsMinMax
Cpu Request25m100m
Cpu Limit40m500m
Memory Request50Mi200Mi
Memory Limit200Mi500Mi

Note

If the user simultaneously sets a percentage annotation and a specific resource value via the corresponding resource annotation then the latter takes precedence.

Warning

The queue.sidecar.serving.knative.dev/resource-percentage annotation is now deprecated and will be removed in future versions.

Additional resources