Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 views
in Technique[技术] by (71.8m points)

kubernetes - How can I edit a Deployment without modify the file manually?

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

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 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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"}]}}}}'

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...