简体   繁体   English

如何修改正在运行的pod的pod内存限制

[英]how to modify pod memory limit of a running pod

I am using YML to create pod and have specified the resource request and limit. 我正在使用YML创建pod并指定了资源请求和限制。 Now I am not aware of how to modify the resource limits of a running pod. 现在我不知道如何修改正在运行的pod的资源限制。 For example 例如

memory-demo.yml 内存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. 然后我运行命令oc create -f memory-demo.ymloc create -f memory-demo.yml一个pod名称memory-demo。

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? 我的问题是如何修改200Mi --> 600 Mi的内存限制200Mi --> 600 Mi ,我是否需要删除现有的pod并使用修改后的YML文件重新创建pod?

I am a total newbie. 我是个新手。 Need help. 需要帮忙。

First and for most, it is very unlikely that you really want to be (re)creating Pods directly. 首先,对于大多数人来说,你真的不想直接(重新)创建Pods。 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. 然后,您只需将更改应用于部署中的spec模板,kubernetes将升级该部署中的所有pod以匹配免提滚动更新中的新规范。

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). 实际更改运行容器的内存限制当然是可行的,但不能通过kubernetes(如果你这样做,也不会反映在kube状态)。 Look at docker update . 看看docker update

You can use replace command to modify an existing object based on the contents of the specified configuration file ( documentation ) 您可以使用replace命令根据指定配置文件的内容修改现有对象( 文档

oc replace -f memory-demo.yml

EDIT: However, some spec can not be update. 编辑:但是,有些规格无法更新。 The only way is delete and re-create the pod. 唯一的方法是删除并重新创建pod。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM