Bootstrap FreeKB - OpenShift - Update a deployment with CPU Memory resource requests and limits
OpenShift - Update a deployment with CPU Memory resource requests and limits

Updated:   |  OpenShift articles

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

  • Limits can be used to set the minimum and maximum amount of CPU/memory/storage for:
    • a single deployment related asset (e.g. container / pod) in a namespace and is typically defined in deployment YAML or deployment config YAML
    • all deployment related assets (e.g. containers / pods) in a namespace
  • Quotas can be used to:
    • set the maximum amount of CPU and memory that can be used in a namespace
    • set the maximum number of running resources (e.g. persistent volume claims, pods, replication controllers, routes, secrets, services, et cetera) in a namespace
  • Cluster Resource Quotas is the same as Quotas except the minimum and maximum are associated with:
    • A user
    • One or more namespaces

You can set both requests and limits.

  • requests
    • the amount of memory / CPU that is reserved or allocated for the container.
  • limit
    • the maximum amount of memory / CPU a container can use
    • if a container reaches the CPU limit, the container will be throttled (won’t let it consume any more CPU)
    • if a container reaches the memory limit, Out Of Memory (OOM) should occur and the pod should be killed
    • if a container reaches the storage limit, the pod should be evicted

 

The oc set resources command can be used to update a deployment or deployment config requests / limits. This will update the deployment or pod YAML to have the requests / limits.

AVOID TROUBLE

This will set the CPU and memory requests / limits for a single deployment / container / pod in the project. If you want to set the combined CPU and memory limits of all of the containers or pods in a namespace, refer to Create CPU Memory Limits using a YAML template file.

~]$ oc set resources deployment my-deployment --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=256Mi
deployment.apps/my-deployment resource requirements updated

 

Or, you can edit the deployment, deployment config, replica set, replication controller, stateful set, or pod YAML with requests / limits.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-openshift
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-openshift
  template:
    metadata:
      labels:
        app: hello-openshift
    spec:
      containers:
      - name: hello-openshift
        image: openshift/hello-openshift:latest
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 10m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 512Mi

 

The oc apply or oc create command with the -f or --filename option can be used to create the deployment using the template JSON or YAML file.

The oc replace command can be used to replace a deployment using a new or updated template JSON or YAML file.

The oc edit command can be used to update a deployments template YAML file.

~]$ oc create --filename deployment.yml
deployment.apps/hello-openshift created

 

The oc get deployments command can be used to list the deployments.

~]# oc get deployments
NAME                DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-openshift     1         1         1            1           23s

 

The oc get pods command can be used to determine if the pod is up and running.

~]$ oc get pods
NAME                READY   STATUS      RESTARTS   AGE
hello-openshift     1/1     Running     0          23s

 

The oc describe deployment or oc describe pod command can be used to validate that the deployment or pod has CPU and memory limits.

~]$ oc describe deployment my-deployment
Pod Template:
  Containers:
   my-container:
    Limits:
      cpu:     200m
      memory:  512Mi
    Requests:
      cpu:        100m
      memory:     256Mi

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 825640 in the box below so that we can be sure you are a human.