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

7/5/2018

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)

-- ling
kubernetes

2 Answers

10/16/2018

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.

-- Ijaz Ahmad Khan
Source: StackOverflow

7/5/2018

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

-- Daein Park
Source: StackOverflow