Skip to content
Latchkey

kubectl "Error from server (Conflict): Operation cannot be fulfilled" in CI - Fix it

Kubernetes uses optimistic concurrency: every update carries the resourceVersion it read. If another writer (a controller or a parallel job) changed the object first, your stale update is rejected with a Conflict and you must re-read and retry.

What this error means

A kubectl apply, patch, or replace fails with Error from server (Conflict): Operation cannot be fulfilled on deployments.apps "api": the object has been modified; please apply your changes to the latest version and try again.

kubectl
Error from server (Conflict): Operation cannot be fulfilled on
deployments.apps "api": the object has been modified; please apply your changes
to the latest version and try again

Common causes

A concurrent write bumped the resourceVersion

A controller (HPA, operator) or a parallel pipeline updated the object between your read and write, invalidating your version.

A stale object from kubectl replace

kubectl replace with an old manifest carries an outdated resourceVersion and loses the race against a fresher state.

How to fix it

Re-read and retry, or use apply

  1. Re-run kubectl apply so it merges against the current object.
  2. Add a small retry around the update to absorb transient concurrent writes.
  3. Avoid kubectl replace with a hardcoded resourceVersion in CI.
Terminal
for i in 1 2 3; do kubectl apply -f deploy.yaml && break; sleep 2; done

Use server-side apply to reduce conflicts

Server-side apply merges field ownership instead of replacing whole objects, which avoids many resourceVersion races.

Terminal
kubectl apply --server-side -f deploy.yaml --field-manager=ci

How to prevent it

  • Prefer kubectl apply over replace so updates merge against current state.
  • Add a short retry around updates that race controllers.
  • Avoid two pipelines writing the same object at once.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →