Back to Terraform

Kubernetes Deep Dive: Server-Side Apply and Controller Field Conflicts

November 6, 2026 Wasil Zafar 28 min read

Identify Terraform, controllers and human field managers through a controlled provider-specific rehearsal

Table of Contents

  1. Read Managed Fields as an Ownership Record
  2. Reproduce One Harmless Field Conflict
  3. Choose a Narrow Ownership or Computed-Field Contract
  4. Verify Controller Convergence and Plan Stability
  5. Document a Reversible Handoff

Read Managed Fields as an Ownership Record

A field manager is the name attached to a write, and the managed-fields list is the receipt. Server-side apply records one entry per writer, naming the manager, the operation, a timestamp and a tree of the paths that write sent. That tree is the only direct evidence of who owns a value; labels such as a managed-by convention are a claim someone typed, not a fact the API enforces.

The tree encodes one address from the object root to the leaf. Each node nests map keys and struct fields under an f: prefix, so a parent path and its children read as a single field address. A path that appears in two entries is shared ownership; a path that appears twice with different values is the disagreement the next apply is refused over.

Operation tells you how the entry was produced, and therefore how much to trust its breadth. An entry from an apply lists only the paths in that patch, while an entry from an update can claim a whole subtree the writer merely echoed back after a read. A controller doing read-modify-write therefore looks greedier in the record than it behaves, and a human who edits one field can appear to own a block of keys they never touched.

Manager identity is configuration, not a constant. The manifest resource writes under the name Terraform unless its field manager block overrides it, so two roots that keep the default are one manager to the API. Give each root a distinct name and the record becomes readable at a glance, with no need to guess which pipeline wrote a value.

Manager entryTypical operationFields it usually claimsWhat it means for the plan
tf-app (a root you named)Applyonly the paths in that root's manifestsafe to share the object with other writers
tf-platform (a second root)Applycluster-scoped bootstrap fieldsa different object, not a different field of this one
kube-controller-managerUpdatestatus, and the scale subresourcedo not declare these fields in a manifest
kubectl or a human managerApplythe field the person changeda one-time takeover that needs a follow-up commit
kubectl-client-side-applyUpdatethe fields in the last-applied annotationan older owner that must be released, not ignored

Merge semantics decide whether sharing a list is even possible. A list the schema declares as a map keyed on name merges per entry, which is why a service mesh can append its sidecar to the Deployment's container list without deleting yours. A list with no merge strategy is atomic: whoever applies it owns every element, and a second writer's addition is dropped rather than merged.

Typed resources never reach this conversation. The typed resource family writes with a full update, so there is no apply patch for the API to check field by field and no conflict response to read. A controller's value is simply overwritten on the next apply and reappears as drift on the plan after that, which is a slower and less honest signal than a refusal.

An ownership entry can outlive the writer that made it. Deleting an autoscaler or an operator does not delete the entry it created; the field stays claimed until another manager takes it or the API prunes old entries. That is why a retired controller can still block a write months later, and why the record is a history as much as a map.

The status subresource keeps two arguments from colliding. Writes to status go through a different endpoint, so a controller updating conditions and Terraform updating the spec never contend for the same path even when both are recorded on one object. That separation is a property of the API design rather than a courtesy the controller extends, which is why writing status from configuration is an error and not a negotiation.

Read the record before the write, not after the failure. A get request with managed fields shown prints the entries beside the object, and the output is small enough to diff between two applies. Captured before the change, the conflict message becomes a lookup instead of an investigation.

A refusal names the fields it found, not only the first one. One failure is usually a complete inventory of the disagreement for that request, which is more useful than a single path and easier to skim past. Read all of it before deciding which owner is wrong, because fixing one path and re-running often reveals the next.

Figure 1 follows one field from three entries to a single answer.

Read Managed Fields as an Ownership Record
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    O["Live object
read with managed fields"] --> M["three manager entries
one field path"] M --> T["tf-app
operation Apply"] M --> C["kube-controller-manager
operation Update"] M --> H["human manager
operation Apply"] T --> Q{"Do the owners
agree on the value?"} C --> Q H --> Q Q -->|"one value"| S["shared ownership
no request refused"] Q -->|"different values"| X["409 conflict
apply rejected"] S --> P["plan is stable while
each writer stays in bounds"] X --> R["name the owner, then
release or take over once"] R --> P classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class O,M,Q primary; class T,C,H secondary; class S,P ok; class X danger; class R warn;

Sharing an object is normal; sharing a path is the exception. Figure 2 separates one Deployment into the zones that three different writers legitimately hold, so the ownership question becomes local instead of object-wide.

One Deployment split into three ownership lanes recorded in managed fields A single Deployment divides into three lanes. The blue lane is applied by Terraform under the manager tf-app and holds the app container and the ConfigMap keys that root manages. The teal lane is written by the service mesh under istiod and holds the injected sidecar container and its annotation. The amber lane is written by kube-controller-manager and holds the replica count and status. A footer explains that a map list merges by key name, a scalar has one owner, and status is evidence rather than configuration. One object, three legitimate owners The record answers a question about a path, not about the whole resource. Deployment web in namespace ssa-lab one spec, three writers, one managed-fields list tf-app · Apply containers[name=app] image, ports, environment data.owner and data.greeting the keys this root sends owns only what the manifest contains istiod · Apply containers[name=istio-proxy] injected by the webhook labels[security.istio.io/tlsMode] added on every write coexists because the list is keyed kube-controller-manager · Update spec.replicas written on every scale event status.availableReplicas read as convergence evidence one scalar, one owner A map list merges by key name. A scalar has a single owner. The sidecar and the app container coexist because containers is keyed on name. If Terraform also sends spec.replicas, the amber lane becomes a conflict, not a handoff. The same object can be shared safely. The same path cannot.

Three questions turn the record into a decision. Who wrote the path, with which operation, and do they still run? A live Terraform manager plus a live controller over disjoint paths is a design; a stale entry plus a new claim over one path is a conflict waiting for the next plan.

Reproduce One Harmless Field Conflict

A ConfigMap is the cheapest object that still has real field semantics. Its data is a map of string keys, so ownership is per key rather than per object and a conflict names one key instead of the whole document. Nothing in the lab schedules a pod, which keeps a mistake inside a disposable namespace.

Create the object with Terraform first. The manifest resource owns exactly what the manifest contains, so the first apply records one entry for the Terraform manager over two keys: greeting and owner. A third key, note, is deliberately left to a human writer, which will show that disjoint keys coexist with no tolerance setting at all.

Then let a second manager write the same object. A server-side apply from the command line under a different manager adds a key Terraform does not manage, and that key is accepted immediately because nothing claims it. The same write also changes greeting, and that part is refused, because Terraform already owns the key at a different value; adding the force flag lets it through and transfers the claim. The object now carries two apply entries, one of them taken rather than granted.

The refusal is the mechanism working. A conflict response is not an outage, a credential problem or a version skew; it is the API stating that two writers disagree about one path and neither has been authorised to overrule the other. Repeating the identical apply reproduces it exactly, which is the useful property: nothing is half-written and nothing drifts while you decide.

Reverse the direction and the lesson holds. Terraform changes greeting again and the same check runs against the human entry, so this time Terraform is the writer being refused. The failure moved but the cause did not: nobody released the key, and force was used to paper over the first disagreement instead of resolving it.

Client-side apply leaves a different kind of owner behind. It records the fields in a last-applied annotation and adds a manager entry of its own, so an object moved from an older kubectl habit to server-side apply carries two claims before anyone edits a value. The first server-side write can then be refused by a record nobody remembers creating, which is why the migration is a planned release rather than a switch.

Release is a write that removes a path from your own applied set. Re-applying the human manifest without the greeting key drops that manager's claim, because a manager owns only the fields in its last applied configuration. With no other owner the key is then deleted from the object, which is the real cost of releasing a field that nobody else writes; Terraform's next apply recreates it at its own value.

A controller changes the consequence of the same step. When another manager also owns the field, withdrawing Terraform's claim leaves the value in place because the controller re-asserts it on its next reconcile. The identical release therefore deletes a ConfigMap key and preserves a replica count, which is exactly why the contract has to name the field's real owner before the handoff.

The refusal is per resource, not per run. Terraform stops at the failing resource, but earlier resources in the same apply are already written and recorded in state, so a conflict is also a partial apply. Re-plan after resolving it instead of resuming from memory, because the graph has already moved.

FieldTerraform managerHuman managerNext Terraform apply
data.greetinghellohello-fixed, forcedrefused with a conflict on this key
data.ownertf-labnot claimedunchanged, still Terraform-owned
data.notenot claimedfrom-kubectlpreserved, never touched
metadata.labelsteam=paymentsnot claimedunchanged, per-key merge

Figure 3 is the same sequence with the branches that matter, including the one where release deletes instead of hands over.

Reproduce One Harmless Field Conflict
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Terraform apply
creates the ConfigMap"] --> B["human server-side apply
sets greeting"] B --> Q{"Same key,
different value?"} Q -->|"no, a new key"| OK["two entries
no error"] Q -->|"yes"| X1["409 conflict
names manager and key"] X1 --> F["force-conflicts
takes the key"] F --> C["Terraform changes greeting"] C --> X2["409 conflict
Terraform is refused"] X2 --> R["human re-applies
without the key"] R --> D{"Another owner
of the key?"} D -->|"no"| DEL["key deleted
from the object"] D -->|"yes, a controller"| KEEP["value kept
claim withdrawn only"] DEL --> T["Terraform apply sets
its value without force"] KEEP --> T T --> V["two clean plans
field has one owner"] OK --> V classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,Q,D primary; class B,F,C,R secondary; class T,V,OK,KEEP ok; class X1,X2 danger; class DEL warn;

The lab works because nothing reconciles it. A ConfigMap has no controller, so every change in the record belongs to a writer you can name and every disagreement stays a two-party argument. Add a controller and the same test stops being about who typed last; it becomes about which of the two is supposed to be right.

Choose a Narrow Ownership or Computed-Field Contract

The contract has three clauses and one prohibition. The first clause is the manager name, the second is the set of paths you send, and the third is the tolerance for values the server rewrites after the write. The prohibition is force as a steady state, because a permanent override is not a contract with the other owner; it is the absence of one.

Manager identity belongs to the root, not to the resource. Give each root a stable name that says which pipeline wrote the value, and record it beside the object's address in the ownership list. A name invented per resource multiplies entries without improving the answer, and a shared default merges two roots into one indistinguishable writer.

The manifest is the field list. Under server-side apply, omission is a claim boundary rather than an oversight: a path you never send is a path you never own. That makes removing a field from the manifest the primary release operation, and it makes a copied default a new claim on a value the schema was governing.

Typed resources need a different contract. They send a whole spec, so the only lever is the plan: omit the field where the schema permits it, or exclude that one attribute from change detection. That changes what Terraform proposes and leaves API ownership exactly as it was, and the two effects must not be confused in review.

The tolerance list has a default that is easy to erase. Declaring computed fields covers the values a mutating webhook or the API may change, and the default covers metadata labels and annotations. Supplying your own list replaces that default rather than extending it, so name the narrowest path that actually moves and re-include the metadata entry when you still depend on it.

A tolerant path is not an ownership transfer. Terraform still sends its value on every apply; the tolerance only decides whether the returned value is treated as an error. If the server's value should win permanently, delete the field from the manifest instead of teaching Terraform to accept an answer it keeps overwriting.

Force removes the check for the entire resource. It is not a per-field override, it does not remember why it was enabled, and it does not expire. A one-time takeover is defensible as a separate commit followed by a commit that removes the flag; a flag left on converts every future disagreement into a silent overwrite by whichever side applied last.

Another reconciler changes the manager name, not the mechanism. A Helm release writes under its own manager, and a GitOps controller writes under another, so one object can carry three apply entries from three tools. The rule from the prerequisite still holds — one reconciler per object — and the field list is what makes deliberate sharing safe rather than accidental.

ClauseProvider settingScopeWhat it provesFailure mode
Manager identityfield_manager.nameone resource per rootthe record distinguishes your writerstwo roots appear as one manager
Field boundarythe manifest itselfone path per omissionyou own only what you senda field you needed is simply absent
Server tolerancecomputed_fieldsnamed paths onlyadmission may rewrite these pathsa path typo covers nothing and still errors
Takeoverforce_conflictsthe whole resourcea deliberate, one-time overridepermanent last-writer-wins
Plan-only exclusionignore_changes on a typed resourceone attributethe diff stays quietownership is still contested in the API

Narrow is a boundary, not a gap. Figure 4 shows the difference between a gate that admits one named path and a wall that is removed entirely, because that is the whole choice between a tolerance and a takeover.

A narrow computed-field gate compared with a resource-wide force override The left panel is Terraform's applied field set. A narrow gate in the middle admits exactly one named path, through which a tolerated server rewrite passes. The right panel holds the fields the API and controllers write. A crimson bar below shows that forcing conflicts removes the wall for every field of the resource, including the controller's replica count. A footer says the narrow gate is a tolerance and the wide one is a takeover. Tolerate one path, or remove the whole wall A computed field is a named exception. A force flag is a resource-wide policy. TERRAFORM APPLIED SET spec.template data.owner metadata.labels[team] computed_fields one named path tolerated API AND CONTROLLERS defaulted fields status.* spec.replicas, written by the autoscaler force_conflicts = true The conflict check is removed for every field of this resource, not for one path. The autoscaler's replica count, the webhook's sidecar and the schema's defaults all become overwritable. The narrow gate is a tolerance. The wide one is a takeover. Choose the path, not the resource, and write down who owns what was left out.

A contract that owns three fields and states them is stronger than one that owns everything by force. Every remaining diff is then a question someone can answer, and every silent overwrite has already been ruled out by design rather than by discipline.

Verify Controller Convergence and Plan Stability

Five observations look alike in a terminal and need different answers. A conflict refuses a write, drift proposes one, defaulting fills a value the configuration never sent, a webhook mutation changes a value that was sent, and a controller mutation changes a field Terraform never claimed. The response differs in each case, so naming the observation is the first step rather than a formality.

ObservationWhere it appearsWas anything writtenCorrect response
Field conflictapply fails, naming a manager and a pathno, the request is refusedchange the contract, then release or take over once
Driftplan proposes an updateyes, when applieddecide whether Terraform should own the field
Defaultinga value appears after apply with no config changeyes, by the APIleave the field out of the manifest
Admission mutationthe same, caused by a webhookyes, by the webhooktolerate the exact path or let the webhook own it
Controller mutationa value Terraform keeps resettingyes, on every applywithdraw the claim from the manifest

A conflict writes nothing, which is why it is safe to investigate. Ownership is validated before the patch is stored, so a refusal leaves the object at its previous value and the plan unchanged. That safety is about a single request; a retry loop simply reproduces the same refusal with more noise in the logs.

Drift is a difference, and a difference is not a verdict. A plan that proposes a change is asking who has authority over the field; if a controller is the right owner, the answer is to stop declaring it, not to schedule more applies. The repeating diff is the symptom of two writers, and applying harder never resolves a disagreement about authority.

Defaulting happens on write, every write. The API fills a field because the object would otherwise be incomplete, and the typed provider absorbs that by reading the value back into a computed attribute. The manifest provider instead compares what you sent with what came back, so an untolerated default is reported as an inconsistent result rather than silently accepted.

Convergence is a runtime claim, not an apply result. A Deployment can be stored, accepted and still be mid-rollout or crash-looping, so read the rollout status, the Deployment conditions and pod readiness as separate evidence. The apply proves the API took the object; it never proves the workload works.

A refresh reads the cluster, and reading claims nothing. Refreshing after a controller change updates state with the live value, which can make the next plan quiet without changing who owns the field. A quiet plan after a refresh is evidence about the read rather than about the contract, so pair it with the manager entry before calling the dispute resolved.

Stability needs two plans separated by an event. The first plan after the change shows the record settled; a controller event between the two proves the settlement survives reconciliation. Two plans with nothing in between only prove that nothing happened.

Use the exit code instead of parsing prose. A detailed-exitcode plan returns 0 for no changes, 2 for changes and 1 for an error, so a pipeline can tell a clean cluster from an edited one without matching English text. That single integer is the difference between a gate and a habit.

Figure 5 places the before and after side by side, with the event that separates the two plans.

Two writers looping before a handoff, and one writer with two clean plans after it The left panel shows Terraform applying a replica count of two while the autoscaler writes four, so each apply undoes the other and the plan never settles. An arrow labelled withdraw the claim leads to the right panel, where Terraform owns every field except the replica count and the autoscaler owns that one. Two clean plans, separated by a scale event, are the proof. A footer states that stability is two clean plans separated by a controller event. The plan is the scoreboard, not the game A repeated change is an ownership dispute that every apply restages. BEFORE: TWO WRITERS tf-app applies replicas = 2 autoscaler writes replicas = 4 next plan proposes 2 again apply writes 2, the loop restarts Every apply is a rollback of the autoscaler. withdraw the claim AFTER: ONE WRITER PER PATH tf-app owns every field except replicas the autoscaler owns spec.replicas plan after the handoff: no changes plan after a scale event: no changes Both writers keep doing their job. Stability is two clean plans separated by a controller event. A single clean plan only proves that nothing had changed yet.

The check is cheap enough to run on every change. Capture the manager entries, run a plan, trigger or wait for one controller event, and run the plan again. If the second plan is clean, the ownership contract holds; if it is not, the diff names the path that is still being claimed twice.

Document a Reversible Handoff

Execution status: design-only. The procedure is written for Terraform 1.17.1 with hashicorp/kubernetes 3.5.0 and was not run against a live cluster for this article. Use a disposable cluster and a namespace you are allowed to delete.

Prerequisites. A cluster where you may create a namespace, a Deployment and a horizontal autoscaler; metrics available to that autoscaler; and one root that manages the Deployment through a manifest resource with its own field manager name. No cloud resource, storage class or ingress is involved.

Lab

Document a Reversible Handoff

  1. Capture the baseline. Read the Deployment with managed fields shown, record the manager entries, and run a plan with the detailed exit code. Expect 0, meaning the object and the configuration already agree.
  2. Reproduce the dispute without changing anything. Drive CPU above the autoscaler's target, wait for it to raise the count, then plan again. Expect a proposed change back to the configured count; stop there, because applying it would only restage the loop.
  3. Name the new owner in the contract. Remove the replica count from the manifest, or move it to a bootstrap-only resource that is not part of the steady-state root. Add a comment naming the autoscaler and the review that approved the handoff.
  4. Apply once and watch what does not happen. Expect success with no replacement and no change to the running replica count, because Terraform no longer sends that field and the autoscaler's entry still holds it.
  5. Read the record, not the plan. Confirm that Terraform's entry no longer lists the replica path and that the controller's entry still does. The claim is gone; the value is not.
  6. Prove the plan is stable. Plan, expect no changes, then drive another scale event and plan again. A change on the second plan means the field is still somewhere in the manifest or in a second root.
  7. Prove the controller still reconciles. Delete one pod and confirm the controller replaces it while the count stays at the autoscaler's target. A controller that had stopped reconciling would leave the replacement missing and the object at whatever count was last written.
  8. Prove Terraform still owns its half. Change the image tag in the manifest, apply, and confirm the rollout completes with no replica churn. If the count moves during the rollout, the field re-entered the applied set.
  9. Rehearse the reversal. Delete the autoscaler, restore the replica count to the manifest, and plan. If the plan conflicts with the retired entry, perform one apply with the force flag, remove the flag in the following commit, and prove a clean plan. The record outlives the writer, so a takeover step is expected rather than surprising.
  10. Record the handoff as an artifact. Write down the manager names, the field list per owner, the two plan results, the manager-entry excerpt and the reversal steps. The document is what makes the next engineer able to reverse the decision without repeating the experiment.
CheckEvidencePass looks like
Dispute is realplan after a scale eventa proposed change Terraform did not need to make
Claim withdrawnmanager entry for the DeploymentTerraform no longer lists the replica path
Value preservedlive object after the applythe count the autoscaler set is still in place
Plan stabletwo plans with a scale event betweenboth report no changes
Controller healthypod deletion and replacementthe controller restores the desired count
Terraform still worksimage change and rolloutrollout completes, count does not move
Reversal documentedplan after restoring the fieldclean, or one deliberate takeover then clean

Expected observation. Withdrawing the field removes Terraform's claim without touching the value, because the autoscaler re-asserts it. The first plan after the handoff is the proof that the claim is gone, and the second plan after a scale event is the proof that it stays gone.

Failure checks. If the first plan still proposes the old count, the field is present somewhere else: a second root, a bootstrap resource, or a template that renders it back into the manifest. If the apply reports a conflict, the autoscaler is not the owner you assumed; read the entries before forcing anything. If the count drops to zero or one after the handoff, nothing owns the field, which is a different bug from a conflict.

Cost dimensions. The lab is close to free: one namespace, one Deployment and one autoscaler on a disposable cluster. There is no load balancer, node pool or persistent volume, so the only realistic charge is the cluster you already run.

Cleanup. Delete the autoscaler first so it stops writing, then the Deployment, then the namespace, and confirm no cluster-scoped object remains. Run a final plan against the root to prove it manages nothing else, and keep the manager-entry excerpt with the handoff record rather than in the pull request description.

The deliverable is the pair of plans, not the paragraph explaining them. A reviewer can see the claim before the change, the claim after it, and the same clean result surviving a controller event, which is the only evidence that the handoff is real and reversible.