I am learning Kubernetes recently, and I am not very clear about the difference between "kubectl apply" and "kubectl replace". Is there any situation that we can only use one of them?
相关问题
- helm and kubectl context mismatch
- Update Node Selector field for PODs on the fly
- AWS EKS add user restricted to namespace
- Kubectl rollout restart for statefulset
- Are you trying to mount a directory onto a file
相关文章
- How to save content of a configmap to a file with
- How to access canonical kubernetes dashboard exter
- Accidentally drained all nodes in Kubernetes (even
- How to recycle pods in Kubernetes
- TLS handshake timeout with kubernetes in GKE
- kubectl delete/create secret forbidden (Google clo
- Getting “ErrImageNeverPull” in pods
- Minikube not working in Windows 8
The difference is that
replace
first deletes the resources, then creates it from the file you give it; whereasapply
attempts to directly update, in the current live resource, only the attributes you give it in the file. See In-place updates and disruptive updates.A consequence of that is that the file you use in an
apply
can be an incomplete spec, ie only what you want to change; whereas withreplace
, the spec must be complete.So you could
apply
a file that changes only an annotation, without specifying any other properties of the resource; but if you tried to use the same file with areplace
command, the command would fail, due to missing information.Also,
apply
only works on some properties of resources; if you need to update properties for whichapply
doesn't apply (sorry for the pun!), you have to usereplace
instead.From: https://github.com/kubernetes/website/blob/master/content/en/docs/concepts/cluster-administration/manage-deployment.md