Changing container memory and cpu limits

Article ID:360054171152
2 minute readKnowledge base

Issue

Find the default memory limit for dynamically provisioned pod agents Where to change resources limit/request in kubernetes JNLP? Allocate more resource to build agents CloudBees CI on modern platform

Environment

Resolution

By default, there is no resource request or limit set for kubernetes agents in CloudBees CI. For instances running kubernetes plugin 1.25.0 and above, the JNLP container is assigned a default memory and CPU request of 256Mi and 100m respectively. To change the default memory/cpu request or limit for the JNLP or any other container you can apply below yaml to Raw yaml for the pod field under pod template in Kubernetes shared cloud configuration on Operations Center or Kubernetes cloud configuration for a controller.

apiVersion: v1
kind: Pod
spec:
  containers:
  - name: jnlp
    resources:
      requests:
        memory: "1Gi"
        cpu: "500m"
      limits:
        memory: "1Gi"
        cpu: "500m"

The example above is used to set change memory/cpu request and limit values for default JNLP container. Same configuration applies for other containers, just change to name of the container from jnlp to match that of the container.

Alternatively you can also apply the same configuration under container template section in pod template configuration from Kubernetes shared cloud configuration on Operations Center or Kubernetes cloud configuration for a controller. See image below.

container limits ui

The above method applies to pod templates defined in UI. For pod templates defined within a pipeline, you could use containerTemplate() instruction to explicitly specify container memory and cpu resources.

podTemplate(cloud: 'kubernetes', containers: [
    containerTemplate(
      ...
        resourceRequestCpu: '50m',
        resourceLimitCpu: '100m',
        resourceRequestMemory: '100Mi',
        resourceLimitMemory: '200Mi',
    ),
    ...