kubectl apply Vs kubectl create
What’s the difference between kubectl apply
and kubectl create
?
There’s already a whole bunch of good explainers…
- Difference Between kubectl apply and kubectl create
- Obligatory Stackoverflow thread
- YouTube Explainer
But what, for example, assuming none of the K8s resources defined in the file exist, would the difference between…
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.2/manifests/tigera-operator.yaml
and
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.2/manifests/tigera-operator.yaml
be? We should end up with the same result right? Sadly, this is not the case. The apply command will result in a failed deployment and report the following error…
` The CustomResourceDefinition “installations.operator.tigera.io” is invalid: metadata.annotations: Too long: must have at most 262144 bytes `
There’s a Github thread going into detail about this but basically kubectl apply
should not be used as it was not designed to handle large resources. For [Calico] we should use kubectl create
on deployment and kubectl replace
on upgrade to handle this issue.