Conflict updating a resource
Production Risk
Occasional conflicts are normal. Persistent conflicts may indicate a 'fight' between two controllers over a resource, which can lead to instability.
An attempt to update or delete a resource failed because the version of the resource you are modifying is outdated. This is a mechanism to prevent you from overwriting changes made by another user or controller.
- 1You read a resource, another process updated it, and then you tried to update the original version you read
- 2Running `kubectl apply` on a resource that has been modified by a controller since the last apply
- 3Two controllers or users attempting to modify the same resource at the same time
Running `kubectl apply` or `kubectl edit` fails with a conflict error.
kubectl apply -f my-deployment.yaml
expected output
Error from server (Conflict): error when applying patch: ... Operation: "replace" for field "spec" failed: conflict: Please apply your changes to the latest version and try again
Fix 1
Fetch the latest version and re-apply
WHEN An update fails due to a conflict during manual changes
kubectl get deployment my-deployment -o yaml > my-deployment.yaml
Why this works
Get the latest version of the resource from the API server and save it. Then, merge your intended changes into this new file and re-apply it.
Fix 2
Force the apply (with caution)
WHEN You are certain your changes should overwrite the server's state
kubectl apply -f my-deployment.yaml --force
Why this works
The force flag deletes the resource and then recreates it with your new definition. This is a destructive action that can cause downtime for services.
✕ Repeatedly try the same command without updating the resource version
It will continue to fail with a conflict error every time. The client must resolve the conflict by working with the latest resource version.
k8s.io/apimachinery/pkg/api/errors/errors.go
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev