Server-side apply and field ownership

Advanced · 14 min

Server-side apply moves the merge into the API server and records who owns each field, so tools sharing an object get conflicts instead of silent overwrites.

Before thisImperative commands and declarative apply

Aqua Security Open Source · 14 min

Server-side apply and field ownership

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Aqua Security Open SourceReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • With kubectl apply --server-side, the API server merges your configuration and records, in metadata.managedFields, which field manager owns each field.
  • Applying a different value to a field another manager owns fails with a conflict naming that manager. --force-conflicts takes ownership; matching the current value shares it.
  • Fields you drop from your configuration are released. They are deleted only if no other manager still owns them, which removes client-side apply's replicas trap.
  • Imperative writes (kubectl scale, set, edit, controllers using update) are recorded as Update operations and take ownership without a conflict.
  • Give every tool its own --field-manager name, leave fields another system owns (such as replicas under an HPA) out of your manifests, and use --dry-run=server or kubectl diff to see conflicts early.

When two tools edit the same object

Client-side apply, from the previous lesson, keeps one record of intent: the last file you applied, in an annotation. That works when one person owns an object. Real objects have several writers. CI applies the Deployment. An autoscaler changes replicas. A service mesh webhook injects a sidecar. An operator sets labels. An engineer runs kubectl set image during an incident. Each one sees only its own view, and with client-side apply the last writer silently wins.

Server-side apply (SSA) answers a sharper question. Not “what did the last applier want?” but “who is responsible for each field?” It went GA in Kubernetes 1.22 and is what controllers, Helm 4, Argo CD’s server-side sync option and Flux use to share objects safely.

Applying on the server

You send the API server a partial object containing only the fields you care about, as an Apply patch. The server merges it into the live object using the type’s schema, so lists such as containers merge by key, and it records ownership:

kubectl apply --server-side -f cart.yaml
# cart.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cart
spec:
  replicas: 3
  selector:
    matchLabels: {app: cart}
  template:
    metadata:
      labels: {app: cart}
    spec:
      containers:
      - name: cart
        image: ghcr.io/example/cart:1.4.2

managedFields: the ownership ledger

kubectl hides it by default; --show-managed-fields brings it back. From the lab, right after that apply:

managedFields:
- manager: kubectl
  operation: Apply
  fieldsV1:
    f:spec:
      f:replicas: {}
      f:selector: {}
      f:template:
        f:metadata:
          f:labels:
            f:app: {}
        f:spec:
          f:containers:
            k:{"name":"cart"}:
              .: {}
              f:image: {}
              f:name: {}
- manager: kube-controller-manager
  operation: Update
  subresource: status
  fieldsV1:
    f:metadata:
      f:annotations:
        f:deployment.kubernetes.io/revision: {}
    f:status:
      f:conditions: ...
      f:observedGeneration: {}

(Trimmed.) Each entry is a field manager, a name for one writer, plus the set of fields it owns. f: marks a field and k:{"name":"cart"} marks a list item by key. You can see kubectl owning what it applied and the Deployment controller owning the revision annotation and the status it reported. Think of it as a shared spreadsheet where each cell shows who last committed to it: anyone can read, but you cannot overwrite a cell someone else owns without saying so.

Conflicts

Now a second applier, with its own manager name, wants five replicas:

$ kubectl apply --server-side --field-manager=autoscaler-bot -f scaler.yaml
error: Apply failed with 1 conflict: conflict with "kubectl": .spec.replicas
...
* If you intend to manage all of these fields, please re-run the apply
  command with the `--force-conflicts` flag.
* If you do not intend to manage all of the fields, please edit your
  manifest to remove references to the fields that should keep their
  current managers.
* You may co-own fields by updating your manifest to match the existing
  value; ...

The server refused rather than overwriting. The message lists the three resolutions. Force takes ownership: --force-conflicts set replicas to 5, and kubectl lost ownership of that field. Drop the field from your config if it isn’t yours. Match the value and both managers co-own it.

Ownership now protects the bot. Re-applying cart.yaml, still saying replicas: 3, failed the other way: conflict with "autoscaler-bot": .spec.replicas.

Removing fields, done right

Here is the difference from client-side apply. With replicas deleted from cart.yaml and the file re-applied:

deployment.apps/cart serverside-applied
replicas=5

kubectl released its claim on replicas, but autoscaler-bot still owned it, so the field and its value stayed. The previous lesson’s trap, where removing replicas reset a Deployment to 1, cannot happen while another manager holds the field. A field is deleted only when its last owner lets go.

Imperative writes take ownership

Not every write is an apply. Ordinary update and patch calls, which is what kubectl scale, kubectl set, kubectl edit and many controllers send, are recorded as operation: Update and simply take ownership of what they change, without conflict. In the lab, kubectl scale deploy cart --replicas=7 moved replicas to a kubectl manager on the scale subresource, and the bot’s next apply hit:

error: Apply failed with 1 conflict: conflict with "kubectl" with subresource "scale" using apps/v1: .spec.replicas

Likewise kubectl set image became kubectl-set, and a later apply of the old image conflicted with it. Drift made by hand is no longer silent. It shows up as a named conflict at the next apply.

Migrating from client-side apply

Applying an object server-side that was previously managed client-side just works. On the shop Deployment from the last lesson, kubectl apply --server-side left these managers:

kubectl-last-applied  Apply
kubectl               Apply
kubectl               Update  scale
kubectl-annotate      Update
kubectl-set           Update
kube-controller-manager Update status

kubectl turned the old annotation into a kubectl-last-applied manager so that fields you once applied can still be released correctly, and every imperative change from the incident is visible with its tool’s name.

Practical rules

  • Give each tool its own --field-manager. Two pipelines sharing the name kubectl will happily overwrite each other.
  • Leave out fields another system owns. A Deployment under a Horizontal Pod Autoscaler should not set replicas.
  • Use kubectl diff --server-side or --dry-run=server in CI to surface conflicts before they fail a deploy.
  • Reach for --force-conflicts deliberately, in the pipeline that is meant to be the source of truth, not as a reflex.

About the video

The embed is “Kubernetes managedFields explained” from Aqua Security Open Source, presented by Itay of Aqua’s open source team (June 2020, 14 minutes). Its description says it explains the purpose of the managedFields property that Kubernetes 1.18 added to every object’s metadata, which some users found obtrusive. That is the ledger this lesson is built on. There are no chapters, so it was judged from the description and title. It predates SSA’s GA in 1.22, kubectl hiding managed fields by default, and tools like Helm 4 adopting SSA, so treat its version details as history. English was judged from the English title, description and caption track; there is no audio-track metadata. Daniele Polencic’s 2025 Learnk8s webinar in deeper spends its second half on SSA, comparing it with the three client-side patch strategies and covering multi-writer patterns.

What was run: every apply, conflict, managedFields listing and migration above ran against a local v1.37.3 API server with kubectl v1.37.3, on 2026-11-28. Helm 4’s SSA support is from its v4.0.0 release notes.

Where this fits

All of this rests on the API describing its own types. Next, how to read that description from the terminal: exploring the API with kubectl.

Check yourself

  1. 01Your CI applies a Deployment server-side with replicas: 3. An autoscaling tool, applying with its own field manager, set replicas to 5 with --force-conflicts. What happens on the next CI run, and what is the right fix?

    CI's apply fails with a conflict on .spec.replicas naming the autoscaler's manager. Forcing it would start a tug of war. The fix is to remove replicas from CI's manifest so the autoscaler is its only owner.

  2. 02With client-side apply, deleting replicas from a previously applied manifest reset the Deployment to 1. Why doesn't that happen with server-side apply when another manager also owns replicas?

    Server-side apply only releases your ownership of the field. Because another manager still owns it, the field and its value stay. A field is removed only when the last owner gives it up.

  3. 03kubectl apply --server-side fails with a conflict with kubectl-set on a container's image. What happened?

    Someone ran kubectl set image, an Update operation, which took ownership of that field under the manager name kubectl-set. Your file has a different image, so apply refuses to overwrite it silently. Decide which value is right, then either force or update your file.

  4. 04What happens to the kubectl.kubernetes.io/last-applied-configuration annotation when you start applying an existing object server-side?

    kubectl migrates ownership: fields recorded in the annotation become owned by the server-side apply manager, and a kubectl-last-applied entry appears in managedFields, so later server-side applies can still release fields you remove.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark