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)
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.
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.
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.
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.
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.
replace
is a full replacement. You have to have ALL the fields present.
patch
is partial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With