This topic tells you how to configure the memory and CPU allocation of resources in the knative-serving
namespace.
By default, Knative deployments are allocated a predefined amount of CPU and memory. These default allocations support general use cases, but you might adjust the allocations for the following reasons:
You can tailor the memory and CPU of Knative system controllers by using the Cloud Native Runtimes resource_management
config option.
To configure the memory and CPU allocation for the deployments in the knative-serving
namespace, you must specify the resource_management
config option on Cloud Native Runtimes. You can only configure the following deployments:
activator
autoscaler
autoscaler-hpa
controller
net-certmanager-controller
net-certmanager-webhook
net-contour-controller
webhook
The following example shows how to adjust the CPU and memory requests and limits by using the resource_management
option of the Knative activator
deployment. By default, the activator
deployment has the following resources:
resources:
requests:
cpu: 300m
memory: 60Mi
limits:
cpu: 1000m
memory: 600Mi
Specify the following resources to the activator pod:
cnrs:
resource_management:
- name: NAME
requests:
memory: MEMORY
cpu: CPU
limits:
memory: MEMORY
cpu: CPU
Where:
NAME
represents the name of the deployment you want to configure.requests
specifies the amount of resources that are allocated to the pods of this deployment:
MEMORY
is how many megabytes of memory you want to request.CPU
is how many CPU cores, 100 millicpu units, you want to request.limits
sets the maximum amount of resources that the pods can use:
MEMORY
is the limit of how many megabytes of memory that the pods can use.CPU
is the limit of how many CPU cores, 100 millicpu units, pods can use.NoteYou can provide any of the resource units supported by Kubernetes as explained in the Kubernetes documentation.
After updating Cloud Native Runtimes, get the deployment information to confirm the activator
deployment updated:
kubectl get deployment activator -n knative-serving -o=jsonpath='{.spec.template.spec.containers[?(@.name=="activator")].resources}'
{"limits":{"cpu":"1","memory":"1000Mi"},"requests":{"cpu":"100m","memory":"100Mi"}}
All fields, such as the request and limits of CPUs, and the memory’s request and limits, are optional, except for the deployment’s name, causing it to use the default values specified for these deployments.
For example, to change only the limit and the memory’s request of the Knative controller
, you can provide the following configuration to resource_management
:
cnrs:
resource_management:
- name: "controller"
requests:
memory: "130M"
limits:
cpu: "0.5"