Kubectl error: the object has been modified; please apply your changes to the latest version and try again

It seems likely that your yaml configurations were copy pasted from what was generated, and thus contains fields such as creationTimestamp, which don't belong in a declarative configuration file.

Go through your yaml and clean it up. Remove things that are instance specific. Your final yaml should be simple enough that you can easily understand it.


Give attention to put the last resourceVersion in your update, you can get it running:

kubectl get deployment <DEPLOYMENT-NAME> -o yaml | grep resourceVersion

you may have been edited the same exported deployment file..

1 - try to reexport it with:

kubectl get deployment <DEPLOYMENT-NAME> -o yaml > deployment-file.yaml

2 - make the needed modifications in "deployment-file.yaml"

3 - apply the changes with:

kubectl apply -f deployment-file.yaml

OR:

you may want to edit the deployment directly.. use :

kubectl edit deployment <DEPLOYMENT-NAME> -o yaml

change the default editor if you aren't familiar with VI editor : export EDITOR=nano