Search code examples
kubernetesopenshiftopenshift-3

Increase memory limit of a running pod


I have a pod running in openshift 3.11, I wish to increase the pod memory limit from 2GB to 4GB. How to do it via Openshift Web Console or via OC command line?

When I try to edit the yaml file in Openshift Web Console I got the following exception

Reason: Pod "hjaha" is invalid: spec: Forbidden: pod updates may not change fields other than spec.containers[*].image, spec.initContainers[*].image, spec.activeDeadlineSeconds or spec.tolerations (only additions to existing tolerations)...


Solution

  • Basically Pods are deployed using containers template of the controllers of the Pods, such as DeploymentConfig, Deployment, DaemonSet, StatefulSet and so on. First of all, you should verify what controller is used for your Pod deployment and modify the resources section on the controller yaml, not running Pod yaml. Look at the following example, if you modify the memory limit on the deployment controller yaml using oc CLI or web console, then it will deploy new pod with new configuration after that.

    // List some deployment controller resources as follows.
    // Then you can see one which is similar name with running pod name.
    $ oc get deploymentconfig,deployment,statefulset,daemonset -n <your project name>
    
    $ oc edit <deployment controller type> <the resource name>
    :
    kind: <deployment controller type>
    metadata:
      name: <the resource name>
    spec:
      :
      template:
        :
        spec:
          containers:
            - name: <the container name>
              resources:
                limits:
                  // modify the memory size from 2Gi to 4Gi.
                  memory: 4Gi