Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the differences between patch and replace the deployment in k8s?

Tags:

kubernetes

I want to update the image for the k8s deployment and I found two RESTAPI in k8s to update the deployment: PATCH and PUT. I found out, that the PATCH is for updating and the PUT is for replacing in the official document but after testing with the two command:

kubectl patch -p ...
kubectl replace -f ...

it seems to has no differences between the two method.

Both of them can rollback and name of the new pod changed.

I wondered if it is only different in the request body for this two commands? (patch only need the changed part and put need the whole parts)

like image 794
ling Avatar asked Jul 05 '18 08:07

ling


People also ask

What is patch in Kubernetes?

With the patch command, Kubernetes performs a merge, merging the JSON provided with the current definition of the deployment/versions object. Go ahead and reload the app in your browser, and then you should notice (after a few seconds) that the new version of the app becomes available.

How do you patch a deployment in Kubernetes?

Use a JSON merge patch to update a Deployment With a JSON merge patch, if you want to update a list, you have to specify the entire new list. And the new list completely replaces the existing list. For a comparison of JSON patch and JSON merge patch, see JSON Patch and JSON Merge Patch.

What is the difference between deployment and replica set?

A ReplicaSet ensures that a specified number of pod replicas are running at any given time. However, a Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features.

What is the difference between POD and deployment in Kubernetes?

As we now know, a pod is the smallest unit of Kubernetes used to house one or more containers and run applications in a cluster, while deployment is a tool that manages the performance of a pod.


2 Answers

According to the documenation:

kubectl patch

is to change the live configuration of a Deployment object. You do not change the configuration file that you originally used to create the Deployment object.

kubectl replace  

If replacing an existing resource, the complete resource spec must be provided.

like image 183
Ijaz Ahmad Avatar answered Nov 22 '22 02:11

Ijaz Ahmad


replace is a full replacement. You have to have ALL the fields present. patch is partial.

like image 28
Daein Park Avatar answered Nov 22 '22 00:11

Daein Park