kubectl patch updates selected fields of a Kubernetes object without requiring a complete manifest edit or replacement. It is useful when one change must keep related fields consistent, such as changing both a Deployment's container image and its application-version label. section 15.2.1
Update an image and label together
Run `kubectl patch deploy kiada --patch '{"spec":{"template":{"metadata":{"labels":{"ver":"0.6"}},"spec":{"containers":[{"name":"kiada","image":"luksa/kiada:0.6"}]}}}}'`. This changes the image and matching Pod-template label in one operation. section 15.2.1
$ kubectl patch deploy kiada --patch ' #1
spec: #2
template: #2
metadata: #2
labels: #2
ver: "0.6" #2
spec: #2
containers: #2
- name: kiada #2
image: luksa/kiada:0.6' #2
Use a multiline YAML patch when the JSON form is difficult to parse; the patch contains only the fields being changed. section 15.2.1
After patching a Deployment with the Recreate strategy:
- Existing Pods terminate together. section 15.2.1
- Replacement Pods start with the new image and label. section 15.2.1
- The old ReplicaSet reaches zero desired Pods while the new one becomes ready. section 15.2.1
