如何在不手动修改文件的情况下编辑展开?

问题描述:

我已经为我的应用程序定义了一个部署:

I have defined a Deployment for my app:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: 172.20.34.206:5000/myapp_img:2.0
        ports:
        - containerPort: 8080

现在,如果我要将应用程序的图像2.0更新为3.0,请执行以下操作:

Now, if I want update my app's image 2.0 to 3.0, I do this:

  1. $ kubectl edit deployment/myapp-deployment
  2. vim已打开.我将图像版本从2.0更改为3.0并保存.
  1. $ kubectl edit deployment/myapp-deployment
  2. vim is open. I change the image version from 2.0 to 3.0 and save.

如何将其自动化?有没有办法只运行命令来做到这一点?像这样:

How can it be automated? Is there a way to do it just running a command? Something like:

$ kubectl edit deployment/myapp-deployment --image=172.20.34.206:5000/myapp:img:3.0

我曾考虑使用Kubernetes API REST,但我不理解

I thought using Kubernetes API REST but I don't understand the documentation.

您可以使用 kubectl补丁.以下命令将更新您应用的标签:

You could do it via the REST API using the PATCH verb. However, an easier way is to use kubectl patch. The following command updates your app's tag:

kubectl patch deployment myapp-deployment -p \
  '{"spec":{"template":{"spec":{"containers":[{"name":"myapp","image":"172.20.34.206:5000/myapp:img:3.0"}]}}}}'

根据文档,也应接受YAML格式.请参阅 Kubernetes问题#458 (尤其是

According to the documentation, YAML format should be accepted as well. See Kubernetes issue #458 though (and in particular this comment) which may hint at a problem.