Configure resource requests and limits

Big picture

Resource requests and limits are essential configurations for managing resource allocation and ensuring optimal performance of Kubernetes workloads. In Calico, these configurations can be customized using custom resources to meet specific requirements and optimize resource utilization.

Configure resource requests and limits - 图1note

It’s important to note that the CPU and memory values used in the examples are for demonstration purposes and should be adjusted based on individual system requirements. To find the list of all applicable containers for a component, please refer to its specification.

APIServer custom resource

The APIServer CR provides a way to configure APIServerDeployment. The following sections provide example configurations for this CR.

APIServerDeployment

To configure resource specification for the APIServerDeployment, patch the APIServer CR using the below command:

  1. kubectl patch apiserver default --type=merge --patch='{"spec": {"apiServerDeployment":{"spec": {"template": {"spec": {"containers":[{"name":"calico-apiserver","resources":{"limits":{"cpu":"1", "memory":"1000Mi"},"requests":{"cpu":"100m", "memory":"100Mi"}}},{"name":"tigera-queryserver","resources":{"limits":{"cpu":"1", "memory":"1000Mi"},"requests":{"cpu":"100m", "memory":"100Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get deployment.apps/calico-apiserver -n calico-apiserver -o json | jq '.spec.template.spec.containers[] | {name: .name, resources: .resources}'

This command will output the configured resource requests and limits for the Calico APIServerDeployment component in JSON format.

  1. {
  2. "name": "calico-apiserver",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }

Installation custom resource

The Installation CR provides a way to configure resources for various Calico Enterprise components, including TyphaDeployment, calicoNodeDaemonSet, CalicoNodeWindowsDaemonSet, csiNodeDriverDaemonSet and KubeControllersDeployment. The following sections provide example configurations for this CR.

TyphaDeployment

To configure resource specification for the TyphaDeployment, patch the installation CR using the below command:

  1. kubectl patch installations default --type=merge --patch='{"spec": {"typhaDeployment": {"spec": {"template": {"spec": {"containers": [{"name": "calico-typha", "resources": {"requests": {"cpu": "100m", "memory": "100Mi"}, "limits": {"cpu": "1", "memory": "1000Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get deployment.apps/calico-typha -n calico-system -o json | jq '.spec.template.spec.containers[]| {name:.name,resources:.resources}'

This command will output the configured resource requests and limits for the Calico TyphaDeployment component in JSON format.

  1. {
  2. "name": "calico-typha",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }

CalicoNodeDaemonSet

To configure resource requests for the calicoNodeDaemonSet component, patch the installation CR using the below command:

  1. kubectl patch installations default --type=merge --patch='{"spec": {"calicoNodeDaemonSet":{"spec": {"template": {"spec": {"containers":[{"name":"calico-node","resources":{"requests":{"cpu":"100m", "memory":"100Mi"}, "limits":{"cpu":"1", "memory":"1000Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get daemonset.apps/calico-node -n calico-system -o json | jq '.spec.template.spec.containers[]| {name:.name,resources:.resources}'

This command will output the configured resource requests and limits for the Calico calicoNodeDaemonSet component in JSON format.

  1. {
  2. "name": "calico-node",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }

calicoNodeWindowsDaemonSet

To configure resource requests for the calicoNodeWindowsDaemonSet component, patch the installation CR using the below command:

  1. kubectl patch installations default --type=merge --patch='{"spec": {"calicoNodeWindowsDaemonSet":{"spec": {"template": {"spec": {"containers":[{"name":"calico-node-windows","resources":{"requests":{"cpu":"100m", "memory":"100Mi"}, "limits":{"cpu":"1", "memory":"1000Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get daemonset.apps/calico-node -n calico-system -o json | jq '.spec.template.spec.containers[]| {name:.name,resources:.resources}'

This command will output the configured resource requests and limits for the Calico calicoNodeWindowsDaemonSet component in JSON format.

  1. {
  2. "name": "calico-node",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }

CalicoKubeControllersDeployment

To configure resource requests for the CalicoKubeControllersDeployment component, patch the installation CR using the below command:

  1. kubectl patch installations default --type=merge --patch='{"spec": {"calicoKubeControllersDeployment":{"spec": {"template": {"spec": {"containers":[{"name":"calico-kube-controllers","resources":{"requests":{"cpu":"100m", "memory":"100Mi"}, "limits":{"cpu":"1", "memory":"1000Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get deployment.apps/calico-kube-controllers -n calico-system -o json | jq '.spec.template.spec.containers[]| {name:.name,resources:.resources}'

This command will output the configured resource requests and limits for the Calico CalicoKubeControllersDeployment component in JSON format.

  1. {
  2. "name": "calico-kube-controllers",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }

CSINodeDriverDaemonSet

To configure resource requests for the CSINodeDriverDaemonSet component, patch the installation CR using the below command:

  1. kubectl patch installations default --type=merge --patch='{"spec": {"csiNodeDriverDaemonSet":{"spec": {"template": {"spec": {"containers":[{"name":"calico-csi","resources":{"requests":{"cpu":"100m", "memory":"100Mi"}, "limits":{"cpu":"1", "memory":"1000Mi"}}},{"name":"csi-node-driver-registrar","resources":{"requests":{"cpu":"50m", "memory":"50Mi"}, "limits":{"cpu":"1", "memory":"1000Mi"}}}]}}}}}}'

This command sets the CPU request to 100 milliCPU (mCPU) and the memory request is set to 100 Mebibytes (MiB) while the CPU limit is set to 1 CPU and the memory limit is set to 1000 Mebibytes (MiB).

Verification

You can verify the configured resources using the following command:

  1. kubectl get daemonset.apps/csi-node-driver -n calico-system -o json | jq '.spec.template.spec.containers[]| {name:.name,resources:.resources}'

This command will output the configured resource requests and limits for the Calico calicoNodeDaemonSet component in JSON format.

  1. {
  2. "name": "calico-csi",
  3. "resources": {
  4. "limits": {
  5. "cpu": "1",
  6. "memory": "1000Mi"
  7. },
  8. "requests": {
  9. "cpu": "100m",
  10. "memory": "100Mi"
  11. }
  12. }
  13. }
  14. {
  15. "name": "csi-node-driver-registrar",
  16. "resources": {
  17. "limits": {
  18. "cpu": "1",
  19. "memory": "1000Mi"
  20. },
  21. "requests": {
  22. "cpu": "50m",
  23. "memory": "50Mi"
  24. }
  25. }
  26. }

Update via Helm

To update configurations during installation via the Helm chart, modify the values.yaml with the necessary resource values for the components prior to executing the helm install.

Configure resource requests and limits - 图2note

The provided example illustrates configuring the apiserver component. Follow a similar approach for other components to update resource requests and limits during installation using the Helm chart.

APIServer custom resource

The APIServer CR provides a way to configure APIServerDeployment. The following sections provide example values.yaml for apiserver component.

APIServerDeployment

To configure resource specification for the APIServerDeployment, update values.yaml with the appropriate resource values.

  1. apiServer:
  2. apiServerDeployment:
  3. spec:
  4. template:
  5. spec:
  6. containers:
  7. - name: calico-apiserver
  8. resources:
  9. limits:
  10. cpu: 1
  11. memory: 1000Mi
  12. requests:
  13. cpu: 100m
  14. memory: 100Mi

You can verify the configured resources using the following command:

  1. kubectl get deployment.apps/calico-apiserver -n calico-apiserver -o json | jq '.spec.template.spec.containers[] | {name: .name, resources: .resources}'