Appearance

Watches and server-side apply

Keep a client’s object view current and resolve conflicts when two writers declare the same field.

What you will understand

  • Describe how a list response and resourceVersion establish a watch starting point.
  • Explain how to recover a watch when its history is no longer available.
  • Inspect managed fields and resolve a server-side apply conflict deliberately.

Builds on: Request lifecycle and admission

How a client keeps its object view current

A controller needs to know which ConfigMaps exist and keep track of changes. It can list the relevant objects to build an initial view, then watch for later additions, modifications, and deletions. A list response includes a resourceVersion the client can use to request changes after that snapshot. This gives the client a way to avoid missing a change between its initial read and the start of the watch.

If the connection drops, the client can resume from a suitable recent version. If the API server has discarded too much history, a 410 Gone response tells the client to list again and rebuild its view before watching further. A resource version is a cursor for API state and should be passed back as provided; use the API’s documented comparison guarantees only where they apply. It is distinct from a wall-clock time or a count of application changes.

Open Inspect the watch to follow each resource version. Step through a ConfigMap update, a reconnect with expired history, and the fresh list that lets the client resume.

How does a watch keep a cached object list current?

List first, retain the returned resource version, then watch for changes after that version.

  1. ClientList the objects
    API serverThe response contains both the current objects and a resource version for the list.
  2. ClientWatch from that version
    API serverThe server can send changes that occurred after the listed view.
  3. Watch streamDeliver an object change
    Client cacheThe cache advances. If a cursor expires, the client rebuilds it by listing again.
Follow the sequence

List first, retain the returned resource version, then watch for changes after that version.

A traditional list-then-watch client is shown; optional streaming-list optimizations are omitted. Documented same-resource version ordering does not make the cursor a clock or event count.

Inspect the watch

A reader lists ConfigMaps, watches the same scope, then recovers when its last saved version is no longer available.

1 / 8

From API serverTo Watch client

List the ConfigMaps

The list response contains the matching objects. The client builds its local view and keeps the collection resourceVersion as the point to watch from.

List metadata.resourceVersion
Before
No initial cursor
After
Cursor A
List the ConfigMaps

The list response contains the matching objects. The client builds its local view and keeps the collection resourceVersion as the point to watch from.

Cursor A, B, and C stand for resourceVersion values returned by the API. Replay the values unchanged in a real request. This example uses a traditional list followed by a watch, with no fixed expiry time.

The server returns 410 Gone. Can retrying cursor B recover the missing events?
Reveal prediction answer

The client should rebuild its view from a new list and start watching from the returned version. Some intermediate changes may be unavailable.

Use the lab’s short watch to inspect its starting ConfigMap. The recovery from expired history is illustrated in this trace.

Open a ConfigMap watch in the controller lab
Explore another case

What happens when field managers disagree

Now imagine two writers setting the ConfigMap’s data.release field. One declares git-declared from a repository and another applies a manual change. Server-side apply tracks each writer’s declared fields under a field manager in metadata.managedFields. Applying a different value to a field owned by another manager can cause a conflict. A different manager can apply the same value and share ownership. Compare both outcomes in the scene.

apiVersion: v1
kind: ConfigMap
metadata:
  name: m14-ownership
  namespace: kv-lab
  labels:
    lab: m14
# Only this key is part of this manager's intention.
data:
  release: git-declared

What happens when two writers claim the same field?

Server-side apply records which manager declared each field, so a second manager can hit a conflict when it changes a field already owned by the first.

  1. Apply the first declaration

    kv-gitops applies data.release and becomes an owner of that declared field.

  2. Inspect managedFields

    The stored value and managedFields describe the result; unrelated fields can belong to other managers.

  3. Resolve the ownership conflict

    A second manager can declare a separate field, or share ownership by applying the same value.

One scalar field illustrates ownership; map and list ownership depend on the API schema.

Inspect the apply conflict

A Git manager and a human manager both apply the same ConfigMap field. Follow the rejected change and the successful apply when they agree on the value.

1 / 5

From Git field managerTo API server

Apply the Git value

The first Server-Side Apply request creates m14-ownership with data.release set to git-declared. The API server records kv-gitops as the manager of that field.

Live value / field manager
Before
No ConfigMap
After
git-declared / kv-gitops
Apply the Git value

The first Server-Side Apply request creates m14-ownership with data.release set to git-declared. The API server records kv-gitops as the manager of that field.

Uses two Server-Side Apply requests to one teaching ConfigMap. Ownership evidence is scoped to data.release. The API server may track other fields for these managers as well.

If the apply is rejected, what should you check to confirm whether it changed the object?
Reveal prediction answer

Read the live value and check which manager owns that field. In this exercise, both stay the same after the conflict.

Use kubectl get with --show-managed-fields before the conflict and after both managers have applied the agreed value.

Reproduce the conflict and check the owners
Explore another case

Open Inspect the apply conflict to see what the API server retains after rejecting a second manager’s value. Compare that with both managers applying the same value and sharing ownership of the field.

Reproduce and inspect an apply conflict

Use the disposable kind lab cluster and source lab-env.sh. Save the ConfigMap as ownership.yaml and start with the kv-gitops manager. Apply a different value as kv-human and read which manager and field the conflict names. A rejected apply leaves the live data.release value unchanged.

kubectl --context kind-kv-lab get namespace kv-lab >/dev/null 2>&1 || \
  kubectl --context kind-kv-lab create namespace kv-lab
kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f ownership.yaml
kubectl --context kind-kv-lab -n kv-lab get configmap m14-ownership -o yaml --show-managed-fields

This command should return a conflict naming kv-gitops and .data.release.

sed 's/^  release: git-declared$/  release: human-declared/' ownership.yaml | \
  kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-human -f -

Now apply the original file as kv-human. Both managers agree on the value, so both can own data.release. In managedFields, look for f:data and f:release under each manager. Delete the teaching ConfigMap when you finish.

kubectl --context kind-kv-lab -n kv-lab get configmap m14-ownership -o jsonpath='{.data.release}{"\n"}'
kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-human -f ownership.yaml
kubectl --context kind-kv-lab -n kv-lab get configmap m14-ownership -o yaml --show-managed-fields
kubectl --context kind-kv-lab -n kv-lab delete configmap m14-ownership

Try this in the API mechanics lab. For a shared cluster, resolve a conflict by deciding who should manage the field. Remove the field from a manager’s declared configuration where appropriate, coordinate an update through the owner, or take ownership deliberately with a reviewed force apply. Transferring ownership changes what other reconcilers may be able to apply.

Check whether the controller saw the write

A watch observes API writes. A controller may still need to process the update and report its progress. Compare object status and values produced by reconciliation separately. After a relist, evaluate current state instead of assuming every intermediate change was available to the client.

Check your understanding

A controller reconnects with a stale watch resourceVersion and the server sends 410 Gone. What happens to its cached view?

The client refreshes its view from a new list response and watches from that version. That works even if some intermediate events are unavailable, because the controller can reconcile from current desired and observed state.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu