Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

People also ask

How do I edit a deployment file in Kubernetes?

Updating a Kubernetes Deployment You can edit a Deployment by changing the container image from one version to the other, decreasing or increasing the number of instances by changing the ReplicaSet value. etc. For example, the container image nginx we have been using in our exercises has many versions.

How do I edit a Edit in kubectl?

To use the kubectl edit command, create a KUBE_EDITOR environment variable and specify your preferred text editor as the variable value. In addition, append the watch flag ( -w ) to the value so that kubectl knows when you have committed (saved) your changes.

How do I edit a file in a Kubernetes pod?

There are two ways to edit a file in an existing pod: either by using kubectl exec and console commands to edit the file in place, or kubectl cp to copy an already edited file into the pod.


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.


There is a set image command which may be useful in simple cases

Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs)

kubectl set image (-f FILENAME | TYPE NAME) CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N

http://kubernetes.io/docs/user-guide/kubectl/kubectl_set_image/

$ kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
deployment "nginx-deployment" image updated

http://kubernetes.io/docs/user-guide/deployments/


(I would have posted this as a comment if I had enough reputation)

Yes, as per http://kubernetes.io/docs/user-guide/kubectl/kubectl_patch/ both JSON and YAML formats are accepted.

But I see that all the examples there are using JSON format. Filed https://github.com/kubernetes/kubernetes.github.io/issues/458 to add a YAML format example.


I have recently built a tool to automate deployment updates when new images are available, it works with Kubernetes and Helm:

https://github.com/rusenask/keel

You only have to label your deployments with Keel policy like keel.sh/policy=major to enable major version updates, more info in the readme. Works similarly with Helm, no additional CLI/UI required.