how to modify pod memory limit of a running pod

8/16/2018

I am using YML to create pod and have specified the resource request and limit. Now I am not aware of how to modify the resource limits of a running pod. For example

memory-demo.yml

apiVersion: v1
kind: Pod
metadata:
  name: memory-demo
  namespace: mem-example
spec:
  containers:
  - name: memory-demo-ctr
    image: polinux/stress
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"
    command: ["stress"]
    args: ["--vm", "1", "--vm-bytes", "150M", "--vm-hang", "1"]

Then I run the command oc create -f memory-demo.yml and a pod name memory-demo get created.

My Question is what should I do to modify the memory limits from 200Mi --> 600 Mi, Do I need to delete the existing pod and recreate the pod using the modified YML file?

I am a total newbie. Need help.

-- Casey
docker
kubernetes
openshift

2 Answers

8/16/2018

First and for most, it is very unlikely that you really want to be (re)creating Pods directly. Dig into what Deployment is and how it works. Then you can simply apply the change to the spec template in deployment and kubernetes will upgrade all the pods in that deployment to match new spec in a hands free rolling update.

Live change of the memory limit for a running container is certainly possible but not by means of kubernetes (and will not be reflected in kube state if you do so). Look at docker update.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

8/16/2018

You can use replace command to modify an existing object based on the contents of the specified configuration file (documentation)

oc replace -f memory-demo.yml

EDIT: However, some spec can not be update. The only way is delete and re-create the pod.

-- hgiasac
Source: StackOverflow