Server-side apply
Two tools write the same Deployment and a client-side apply silently keeps the last one. Server-side apply records an owner for every field, refuses a second writer until it forces the change, and installs manifests whose CRDs are too large for an annotation. Strimzi applies its own resources the same way, so a foreign annotation stays and an owned field returns.
The application manifests set a memory limit of 384Mi on order-service. A platform team raises it to 512Mi with a patch, and the next deployment of the application manifests puts it back to 384Mi. Nothing reports an error. The pod restarts twice and the last writer wins.
With kubectl apply as most people first learn it, nothing on the cluster refuses a second writer. The same gap shows when a manifest is too big to apply at all: the install of CloudNativePG, the PostgreSQL operator, fails before it creates anything.
Learning objectives
- Apply manifests server-side under a named field manager instead of the client-side default
- Read field ownership from managedFields to see which manager last set a value
- Resolve a conflict between two managers instead of forcing it without review
- Install a CustomResourceDefinition too large for the client-side annotation limit
Why this matters
When two tools apply to the same object with a client-side apply, neither write is refused: whichever applies last wins, with no error and no record of what the other one wanted. A platform team’s emergency memory bump gets reverted by the next routine deployment, and the only sign is a pod restarting twice for no apparent reason. A manifest too large for the client-side bookkeeping can fail to install at all. Name an owner for every field, and an unrefused overwrite becomes a reported conflict someone has to resolve.
Pattern: Field ownership
The problem
kubectl apply in its client-side form compares three things on the client: the manifest, the live object and a copy of the last manifest, stored in the annotation kubectl.kubernetes.io/last-applied-configuration. That copy is how it knows which fields to delete. It has two consequences.
The annotation holds the whole manifest, and the API server limits all annotations on one object to 256 KiB, 262144 bytes. A CustomResourceDefinition with a large schema carries its whole content into its own annotation and passes the limit. The install of CloudNativePG fails on clusters.postgresql.cnpg.io and on poolers.postgresql.cnpg.io:
CustomResourceDefinition.apiextensions.k8s.io "clusters.postgresql.cnpg.io" is invalid:
metadata.annotations: Too long: may not be more than 262144 bytes
The other consequence is that the server refuses neither of two writers. A second tool that sets a field the first one owns overwrites it, and the first tool overwrites it back on its next run. A client-side apply is an ordinary update: the server records which manager made it, moves the field to that manager and refuses nothing.
The solution
Apply server-side under a named field manager: the API server records the owner of each field, refuses a write from another manager that would change an owned field, and lets that manager force the change and take the field.
The apply is a request to the API server, not a patch computed on the client. The manifest is the set of fields the manager wants to own, and the server merges it with the other managers’ sets. Fields that two managers set to the same value are shared. Fields set to different values are a conflict, and a conflict is an error until the applier forces it. A field the manager sent earlier and leaves out now is removed, unless another manager also owns it (Kubernetes, Server-Side Apply). Server-side apply is a stable feature (KEP-555).
How Kubernetes and Strimzi model it
Ownership is stored in metadata.managedFields: one entry per manager and operation, with the owned paths. kubectl get --show-managed-fields prints it. The Strimzi operator is one more manager. In current releases it applies its Service, ServiceAccount, ConfigMap, Ingress and PersistentVolumeClaim resources server-side and the setting cannot be turned off (Strimzi changelog). The bootstrap Service of the Kafka cluster is one of them.
Installing the operators
The manifests of both operators are single files with their CRDs. A client-side apply of the CloudNativePG manifest stops at the two CRDs named above, and a server-side apply of the same manifest passes, because no manifest is copied into an annotation.
kubectl apply --dry-run=server -f cnpg.yaml # Too long
kubectl apply --server-side --dry-run=server -f cnpg.yaml # accepted
The Strimzi CRDs are smaller. The largest, kafkas.kafka.strimzi.io, stays under the limit, so a client-side apply of the Strimzi install passes. That is a property of the schemas, not a reason to prefer one form. CloudNativePG documents the server-side form for its install (CloudNativePG, Installation and upgrades).
Two writers on one Deployment
The application manifests are applied under the manager edp-apps:
kubectl apply --server-side --field-manager=edp-apps -k apps
A second manager, edp-platform, sends a partial Deployment with only the field it cares about:
apiVersion: apps/v1
kind: Deployment
metadata: {name: order-service, namespace: edp}
spec:
template:
spec:
containers:
- name: app
resources: {limits: {memory: 512Mi}}
containers is a list keyed by name, so the server merges the app container instead of replacing the list. The apply fails and changes nothing:
error: Apply failed with 1 conflict: conflict with "edp-apps":
.spec.template.spec.containers[name="app"].resources.limits.memory
The message names the manager and the field. With --force-conflicts the value becomes 512Mi, and managedFields shows edp-platform as the owner of limits.memory and no longer lists edp-apps for it. The next apply of the application manifests conflicts the other way, with edp-platform named, and takes the field back only when it forces. Two managers that apply the same value share the field without a conflict; a later change by either one then conflicts with the other.
The client-side form has no such step. A kubectl apply -f of the same value over a field the server-side applier owns reports configured, prints a warning about the missing last-applied annotation and takes the field under the manager kubectl-client-side-apply. The next server-side apply of edp-apps then conflicts with that manager. Mixing the two forms on one object is the way to lose track of owners.
kubectl diff --server-side --field-manager=edp-apps -k <dir> asks the server what the apply would do and prints it as a unified diff. A changed limit shows as one line removed and one added, and nothing is written. Run it before an apply of a shared object, and it shows whether another manager’s value is about to change.
A label that edp-apps sent once and then leaves out is removed on the next apply, because edp-apps is its only owner. The same label also owned by a second manager stays. That rule replaces the last-applied annotation: the server knows from managedFields which fields a manager sent before.
Strimzi’s own fields
The operator applies the Kafka bootstrap Service under the manager strimzi-kafka-operator, and managedFields lists it as an Apply owner of the annotation strimzi.io/discovery. Another manager adds an annotation next to it without any conflict, and the annotation survives the operator’s reconciliations:
kubectl apply --server-side --field-manager=edp-foreign -f annotation.yaml
kubectl -n edp-kafka annotate kafka edp r=1 --overwrite # a reconcile
A change to the operator’s own annotation is another matter. Without force it fails with a conflict naming strimzi-kafka-operator. With force it succeeds, and the operator puts its value back at the next reconciliation, 1 to 2 s after the reconcile was triggered. The operator first applies without force and, on a conflict, logs it and retries with force (Strimzi blog, Server-Side Apply in Strimzi). A tool that adds fields to Strimzi’s resources is therefore safe, and a tool that edits Strimzi’s fields loses.
The edit that belongs to the operator goes into the resource it reads, the Kafka or KafkaNodePool, not into a patch on the Service it creates: a forced change to a field it owns there is put back. A KafkaTopic is the same case: the resource is the source of truth and a change made elsewhere is reverted.
Build, run, observe
examples/_k8s/cluster.sh up
cd examples/30-server-side-apply
./verify.sh
The script deploys the event notification services under edp-apps, applies the CloudNativePG install both ways, lets edp-platform conflict and force, and adds a foreign annotation to the Strimzi Service, reading every owner back from managedFields; it ends with 25/25 checks passed.
Try one change and rerun:
APPLY=client ./verify.sh(demo code): both writers apply client-side, the conflicts never appear and the ownership checks fail.KEEP=1 ./verify.sh, thenkubectl --context edp -n edp get deploy order-service --show-managed-fields -o yamlshows each manager and its fields.kubectl --context edp diff --server-side --field-manager=edp-apps -k changes/memoryprints the one-line change without applying it.
When not to use it
A manifest applied once by one person to a throwaway cluster needs no owner. kubectl create does the job, and a name for the manager adds nothing.
Server-side apply is not a coordination tool. It reports a conflict between managers that apply the same field with different values. It does not say which value is right, and --force-conflicts in a pipeline that runs without a person turns the report off. Settle who owns a field before the second manager exists, and keep the force for a decision.
Objects created by a client-side apply carry the manager kubectl-client-side-apply. The first kubectl apply --server-side under kubectl’s default manager name takes over their fields without a conflict, and a different name, such as edp-apps, opts out of that transfer and conflicts instead (Kubernetes, Server-Side Apply).
Common pitfalls
- Mixing client-side and server-side applies on the same object loses track of ownership, since a client-side write takes the field under its own manager and the next server-side apply then conflicts with that manager instead of the one a person expects.
- Editing a field an operator owns directly on the resource it creates, instead of the resource it reads, gets the edit reverted at the next reconciliation.
- Assuming client-side apply is safe for every CustomResourceDefinition because it worked for one with a small schema breaks the moment a schema the size of CloudNativePG’s is applied the same way and exceeds the annotation limit.
🤖 Explore with your agent “In examples/30-server-side-apply, apply apps as edp-apps, then apply platform as edp-platform without and with –force-conflicts, and read the owners of limits.memory on Deployment order-service from managedFields each time. Then add an annotation to the Service edp-kafka-bootstrap as edp-foreign and change strimzi.io/discovery with and without force. Say which writer owns each field after every step and which apply should never be forced.” Check: the first edp-platform apply fails with a conflict naming edp-apps and leaves 384Mi, the forced apply gives 512Mi owned by edp-platform, and the operator owns strimzi.io/discovery again after its next reconciliation.
References
- Kubernetes, Server-Side Apply and kubectl apply
- Kubernetes, Declarative management of objects (the last-applied annotation) and Annotations (the 256 KiB limit)
- Kubernetes Enhancement Proposal 555, Server-side apply
- Strimzi blog, Server-Side Apply in Strimzi, 2026, and the changelog
- CloudNativePG, Installation and upgrades
- Strimzi and KRaft
- Unidirectional Topic Operator