Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

kubectl: metadata.resourceVersion: Invalid value: 0x0

The 0x0 error means an update carried no resourceVersion. Switch to apply or patch, or read the live object first, and keep versions out of Git.

~5 min readKubernetes
#kubernetes#kubectl#apply#api
Bold white headline reading RESOURCE VERSION with a Kubernetes object crate holding an empty amber version plate on the right.

Introduction & Quick Summary

kubectl rejects an update before the API server touches etcd:

code
The Deployment "web" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update

0x0 is Go's zero value for a string printed as hex — in practice, an empty metadata.resourceVersion. Kubernetes carries a resource version on every object and requires it on a full replacement (PUT) so two writers cannot overwrite each other blindly. A manifest taken from Git has no resource version, so any path that turns it into a PUT fails with this message.

Quick answer, in order of preference:

bash
kubectl apply -f deploy.yaml # PATCH, no resourceVersion needed kubectl patch deployment web --type=merge -p '{"spec":{"replicas":3}}' kubectl apply --server-side -f deploy.yaml # server-side apply, no resourceVersion needed

Use kubectl replace only with an object that carries the live resource version:

bash
kubectl replace -f deploy.yaml # fails: no resourceVersion kubectl get deploy web -o yaml | kubectl replace -f - # succeeds: live object

Who hits it: kubectl replace in a script, a controller or operator calling the Update API with a struct it built from scratch, Terraform's Kubernetes provider when a resource is recreated from imported state, and migration jobs that rewrite manifests with yq and then replace.

Core Mechanics, Signatures & Reproducible Setup

The API server's write verbs differ in what they require:

VerbHTTPRequires resourceVersionConflict detection
createPOSTno; ignored if presentAlreadyExists
updatePUTyes409 if it does not match live
patchPATCHno, unless an optimistic-lock precondition is sent409 on that precondition
apply (client-side)PATCHnomerge semantics per field
apply (server-side)PATCH with field managerno409 ApplyFailedConflict on foreign fields
deleteDELETEno, optional Preconditions404 if gone

A minimal reproduction, using a namespace you can throw away:

bash
kubectl create ns rvtest kubectl -n rvtest create deployment web --image=nginx --replicas=1 kubectl -n rvtest get deploy web -o yaml > web.yaml kubectl -n rvtest replace -f web.yaml # works: file came from the cluster kubectl -n rvtest get deploy web -o yaml \ | grep -v 'resourceVersion\|uid:\|creationTimestamp\|generation' > bare.yaml kubectl -n rvtest replace -f bare.yaml # 0x0 error

The server has no version to compare against, and an unconditional PUT would silently discard a concurrent change — exactly the bug resource versions exist to prevent.

Two related strings appear in the same situations and mean different things:

code
Operation cannot be fulfilled on deployments.apps "web": the object has been modified; please apply your changes to the latest version and try again

That is a version that was present but stale (HTTP 409). 0x0 is a version that was absent (HTTP 422). A retry loop fixes the first if it re-reads the object; it never fixes the second.

Key Comparison Table

Choosing the write path for a GitOps or scripted deploy:

ApproachHolds state inIdempotentNeeds resourceVersionField ownership
kubectl apply (client-side)last-applied-configuration annotationyesnolast writer wins per key
kubectl apply --server-sidemanagedFieldsyesnoper-field manager, conflicts surfaced
kubectl replacecalleryes, but destructiveyesfull object replaced
kubectl patchcalleryesnotouched fields only
kubectl createcallernonon/a
Helm upgraderelease secretyesnothree-way merge patch

What each error is telling you:

MessageHTTPCauseFix
resourceVersion: Invalid value: 0x0422PUT without a versionuse apply or patch, or read the live object first
the object has been modified409PUT with a stale versionre-get, re-apply your change, retry
ApplyFailedConflict409two field managers own one field--force-conflicts with a chosen manager name
metadata.resourceVersion: Invalid value: "123": must be specified for an update422quoted or numeric version from a templatepass it as a string from the API
field is immutable422a field the API forbids changingrecreate the object

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Replace inside a deploy script

bash
# broken: manifest from the repo has no resourceVersion kubectl replace -f k8s/deployment.yaml # fixed: apply is the right verb for declarative files kubectl apply -f k8s/deployment.yaml # fixed, if replace is genuinely required RV=$(kubectl get deploy web -o jsonpath='{.metadata.resourceVersion}') yq -i ".metadata.resourceVersion = \"$RV\"" k8s/deployment.yaml kubectl replace -f k8s/deployment.yaml

The environment variable form is what the second half of that snippet relies on; if you keep these commands in a script, review how the shell expands them with the environment variable reference, because a missing RV reproduces the original error with a confusing twist.

2. Generating a manifest by editing kubectl get -o yaml

kubectl get -o yaml includes resourceVersion, uid, generation, creationTimestamp, and status. Feeding that output to replace in a different cluster fails with uid mismatch or a version conflict rather than 0x0, and stripping the wrong subset produces 0x0. Strip deterministically:

bash
kubectl get deploy web -o yaml \ | yq 'del(.metadata.resourceVersion, .metadata.uid, .metadata.generation, .metadata.creationTimestamp, .metadata.managedFields, .status)' \ > clean.yaml

yq 4 requires the quoted expression form above; yq 3 used del(...) without quotes. Compare the two outputs with the YAML formatter before committing, since a YAML indentation change is easier to spot there than in a diff of a 700-line manifest.

3. Server-side apply and its own conflicts

bash
kubectl apply --server-side --field-manager=ci-pipeline -f deploy.yaml # ApplyFailedConflict: conflict with "kubectl-client-side-apply" kubectl apply --server-side --field-manager=ci-pipeline --force-conflicts -f deploy.yaml

Server-side apply does not need resource versions; it needs a stable manager name. Two pipelines using different names will fight over the same replicas field, and every deploy logs a conflict until one of them owns it. Pick the name once and keep it in the pipeline configuration.

4. Controllers and client-go Update calls

An informer cache holds an object that can be several seconds old. Calling Update on the cached copy sends its resource version, which the server may have already moved past:

go
// unsafe: object comes from the lister, version may be stale obj, _ := lister.Deployments(ns).Get(name) obj.Spec.Replicas = ptr.To(int32(3)) _, err := client.AppsV1().Deployments(ns).Update(ctx, obj, metav1.UpdateOptions{}) // conflict-tolerant: re-read on 409 and retry with backoff if apierrors.IsConflict(err) { return ctrl.Result{Requeue: true}, nil }

A struct built with &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "web"}} — no version at all — produces the 0x0 error on the very first call, which is why operators should always start from a read.

5. Terraform and other declarative tools

The Kubernetes provider performs a create-or-update cycle. After an import, or after a failed apply that partially created the object, the provider can attempt an update with empty state fields and surface the same API message. The fix is to refresh state so the provider learns the live resource_version, then apply again:

bash
terraform state rm kubernetes_deployment.web terraform import kubernetes_deployment.web default/web terraform plan

terraform plan should show no changes after the import. If it does, the configuration and the cluster have diverged, and applying would replace the object wholesale.

6. Checking a manifest before it reaches a cluster

bash
kubectl apply --dry-run=server -f deploy.yaml # validates against the live API kubectl diff -f deploy.yaml # what apply would change

--dry-run=server catches schema errors that client mode misses, including invalid field values, and it does so without writing anything. kubectl diff previews what apply would change.

Common Compilation/Runtime Mistakes & Version Gotchas

Committing resourceVersion to Git. The value is cluster-specific and changes on every write. A pipeline that stores it deploys once and then fails every subsequent run with a stale-version conflict, or succeeds against the wrong cluster if the numbers happen to agree.

Retrying 0x0 in a loop. The error is deterministic: the object never gains a version by being retried. Retry loops belong on 409 conflicts, where a fresh read changes the outcome.

Using --force to escape a conflict. kubectl replace --force deletes and recreates the object, which empties it of everything applied by other tools: sidecar injections, autoscaler annotations, and the persistent volume binding of a StatefulSet pod. On a Deployment it causes a short outage; on a StatefulSet it can be unrecoverable by itself.

Version differences. Server-side apply reached GA in 1.22, and managedFields became the source of truth for ownership. Strict field validation became the default in 1.27, so a typo that used to be ignored now returns strict decoding error: unknown field. kubectl 1.32 and later warn when client and server differ by more than one minor, often the first hint that a CI image is older than the cluster.

Watching what actually changed. After a successful apply, confirm the object moved the way you intended with kubectl get -o yaml and a diff against your file rather than trusting the exit code; kubectl diff and the text diff tool both show the delta, and the second one works when the cluster is unreachable.

Reference material: API concepts: resource versions and Server-side apply.

Official references

primary documentation

The Kubernetes documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Kubernetes work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Kubernetes guides

More in Kubernetes

All Kubernetes guides

The guides filed next to this one in Kubernetes, in library order.