The API and the loopLesson 3 of 8
  1. Desired state and the reconcile loop, not reconciled
  2. Control plane and nodes, not reconciled
  3. API machinery: groups, versions and resource versions, not reconciled
    1. Groups, versions, kinds, resources
    2. Discovery
    3. Common metadata
    4. resourceVersion and conflicts
    5. generation and observedGeneration
    6. List and watch
    7. Versions over time
  4. kubectl and kubeconfig, not reconciled
  5. Namespaces, labels and annotations, not reconciled
  6. Declarative management and server-side apply, not reconciled
  7. Owners, finalizers and garbage collection, not reconciled
  8. Custom resources and operators, not reconciled

API machinery: groups, versions and resource versions

Every object lives at a predictable REST path, carries the same metadata, and changes under optimistic concurrency. Controllers follow those changes with list and watch instead of polling.

  • 22 min
  • 4 objectives
  • 7 scenes
  • Includes an On AWS layer

Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.

Every kubectl command becomes an HTTP request to the API server, and every controller is an HTTP client too. The API is regular enough that once you know its shape you can find any resource, predict how concurrent writers interact, and understand how a hundred controllers keep up with a cluster without flattening it. This lesson is that shape.

Reconcile, in 7 scenes

Groups, versions, kinds, resources

An object’s apiVersion names an API groupA named family of related resources, such as apps, batch or rbac.authorization.k8s.io, versioned as a unit. and a version: apps/v1 is version v1 of the apps group. The original resources belong to the core group, which has no name, so their apiVersion is just v1. kind names the type of the object in CamelCase singular (Deployment). The resource is the URL segment that serves that kind, lowercase and plural (deployments).

From those pieces you can write the REST path of anything:

ObjectapiVersionPath
Pod web-0 in shopv1/api/v1/namespaces/shop/pods/web-0
Deployment web in shopapps/v1/apis/apps/v1/namespaces/shop/deployments/web
Node kx-workerv1/api/v1/nodes/kx-worker
ClusterRole viewrbac.authorization.k8s.io/v1/apis/rbac.authorization.k8s.io/v1/clusterroles/view

The core group sits under /api/v1; named groups sit under /apis/GROUP/VERSION. Namespaced resources insert namespaces/NAMESPACE; cluster-scoped ones such as Nodes do not. Verbs map onto HTTP: get and list are GET, watch is a GET with ?watch=true, create is POST, update is PUT, patch is PATCH and delete is DELETE. RBAC rules are written in these same terms, which is why they name groups, resources and verbs.

Some resources have subresources below the object’s path. /status lets controllers write status without touching spec. /scale is what kubectl scale and the HorizontalPodAutoscaler use, and pods/binding is how the scheduler assigns a node. pods/log and pods/exec are not stored at all: the API server proxies them to the kubelet on the pod’s node, on TCP 10250.

Discovery

The API server describes itself. Discovery documents list every group, version and resource it serves, with short names, scope and verbs, and an OpenAPI schema describes every field. kubectl reads both and caches them under ~/.kube/cache:

Asking kx what it serves
kubectl api-resources --api-group=apps
NAME           SHORTNAMES   APIVERSION   NAMESPACED   KIND
daemonsets     ds           apps/v1      true         DaemonSet
deployments    deploy       apps/v1      true         Deployment
replicasets    rs           apps/v1      true         ReplicaSet
statefulsets   sts          apps/v1      true         StatefulSet
kubectl explain deployment.spec.replicas
GROUP:      apps
KIND:       Deployment
VERSION:    v1

FIELD: replicas <integer>


DESCRIPTION:
    Number of desired pods. This is a pointer to distinguish between explicit
    zero and not specified. Defaults to 1.
    

Because these commands ask the server, they describe that cluster’s version and whatever CRDs it has installed. kubectl explain on a 1.37 cluster documents 1.37 fields, which a web page for another version cannot promise. When a manifest fails with “no matches for kind”, discovery is the first place to look: the group or version it names is not served.

Common metadata

Every object carries the same metadata block, so tools that know nothing about a kind can still read it. This lesson’s cluster runs a Deployment web with two nginx replicas:

A Deployment's metadata
kubectl get deployment web -o yaml | head -16
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"web"},"name":"web","namespace":"default"},"spec":{"replicas":2,"selector":{"matchLabels":{"app":"web"}},"template":{"metadata":{"labels":{"app":"web"}},"spec":{"containers":[{"image":"nginx:1.30","name":"nginx"}]}}}}
  creationTimestamp: "2026-11-19T09:00:30Z"
  generation: 1
  labels:
    app: web
  name: web
  namespace: default
  resourceVersion: "261"
  uid: 85694271-5cb3-4bab-9fc4-fc111ace4711
spec:
kubectl get pods -l app=web -o jsonpath='{.items[0].metadata.ownerReferences[0].kind}/{.items[0].metadata.ownerReferences[0].name}'
ReplicaSet/web-89c8ffd94
FieldWhat it is for
name, namespaceIdentity: unique per resource type within a namespace, or cluster-wide for cluster-scoped kinds
uidUnique across time; delete web and create it again and the uid differs
labelsSmall key-value pairs that selectors match on
annotationsFree-form metadata for tools and people; nothing selects on it
resourceVersionChanges on every write; used for concurrency and watches
generationCounts changes to spec
ownerReferencesWhich object this one belongs to, for garbage collection
finalizersKeys that must be removed before the object can be deleted
deletionTimestampSet once deletion is requested, while finalizers or a pod’s grace period still hold the object

A finalizerA key in metadata.finalizers that tells the API server to keep an object until the controller responsible for that key has done its cleanup and removed it. turns delete into a two-step process. A delete request on an object with finalizers only sets deletionTimestamp. The object stays readable, and the controllers responsible clean up whatever the finalizer guards, such as a cloud disk or a load balancer, then remove their key. When the list is empty, the API server deletes the object:

A finalizer holds a ConfigMap after delete
kubectl delete configmap app-config --wait=false
configmap "app-config" deleted from default namespace
kubectl get configmap app-config -o jsonpath='{.metadata.deletionTimestamp} {.metadata.finalizers}'
2026-11-19T09:01:00Z ["example.com/hold"]

resourceVersion and conflicts

Every write to an object changes its resourceVersion, which comes from etcd’s revision counter. Treat it as a token you read and pass back unchanged. Within one resource type served by kube-apiserver you can also order two versions: they compare as increasing integers, even across namespaces, and from Kubernetes 1.35 conformance requires every API server implementation to keep that true. Versions of different resource types, such as a Pod and a Deployment, can only be checked for equality, and so can versions from an extension API server that do not parse as decimal numbers.

The token makes optimistic concurrencyA scheme where writers take no locks; each update states the version it was based on, and the server rejects it if the object has changed since. work. A read-modify-write cycle looks like this:

  1. Client A reads the ConfigMap at resourceVersion 4100.
  2. Client B reads the same version, changes it, and writes it. The stored version moves to 4107.
  3. Client A sends its update, still carrying resourceVersion: "4100".
  4. The API server sees that 4100 is not current and answers 409 Conflict. Client A re-reads at 4107, reapplies its change, and retries.

The message in the 409 response reads:

Operation cannot be fulfilled on configmaps "app-config": the object has been modified; please apply your changes to the latest version and try again

Without step 4, client A would overwrite client B’s change without either of them knowing, the classic lost update. With it, nobody holds a lock, readers never block, and conflicts cost one retry. Controllers wrap their updates in exactly that retry.

Patches behave differently. A JSON, merge or strategic merge patch without a resourceVersion applies to whatever is stored when it arrives, so two patches to different fields both succeed. That is why kubectl scale, label and client-side apply rarely conflict. kubectl edit works this way too: it sends only the fields you changed, with no resourceVersion, so a change someone made to other fields while your editor was open survives, and a change to a field you also edited is overwritten by yours without any conflict. You can make a patch conditional by including metadata.resourceVersion in it. Server-side apply tracks ownership per field instead, which the declarative management lesson covers.

generation and observedGeneration

metadata.generation starts at 1 and increments only when spec changes. Labels, annotations and status updates leave it alone. The controller that owns the object copies the generation it last acted on into status.observedGeneration. In Kubernetes 1.35 and later Pods carry the pair too, with the kubelet reporting the generation it has acted on. Compare the three numbers through a label change and an image change:

resourceVersion moves on every write, generation only on spec
kubectl get deployment web -o jsonpath='{.metadata.resourceVersion} {.metadata.generation} {.status.observedGeneration}'
261 1 1
kubectl label deployment web team=storefront
deployment.apps/web labeled
kubectl get deployment web -o jsonpath='{.metadata.resourceVersion} {.metadata.generation} {.status.observedGeneration}'
262 1 1
kubectl set image deployment/web nginx=nginx:1.31
deployment.apps/web image updated
kubectl get deployment web -o jsonpath='{.metadata.resourceVersion} {.metadata.generation} {.status.observedGeneration}'
273 2 2

The label write moved resourceVersion from 261 to 262 and left generation at 1. The image change bumped generation to 2, and by the time of the read the deployment controller had acted on it and reported 2. In between, the controller’s own status writes moved resourceVersion on to 273.

When observedGeneration is lower than generation, the controller has not acted on the spec as it stands, and every other status field describes the previous spec. kubectl rollout status waits for the two to match before it trusts replica counts, and your own scripts should too.

List and watch

A list returns a collection along with the resourceVersion it reflects. A watch started from that version streams every change after it as typed events: ADDED, MODIFIED, DELETED, plus BOOKMARK events that only advance the version. kubectl get --watch uses exactly this pair, and --output-watch-events shows the event types:

List, then watch
kubectl scale deployment web --replicas=3
deployment.apps/web scaled
kubectl get pods -l app=web --watch --output-watch-events
EVENT   NAME                  READY   STATUS    RESTARTS   AGE
ADDED   web-89c8ffd94-nshlv   1/1     Running   0          30s
ADDED   web-89c8ffd94-pggpj   1/1     Running   0          30s
ADDED   web-89c8ffd94-rlxff   0/1     Pending   0          0s
MODIFIED   web-89c8ffd94-rlxff   0/1     ContainerCreating   0          1s
MODIFIED   web-89c8ffd94-rlxff   1/1     Running             0          5s

The three ADDED lines are the initial list; the MODIFIED lines are the watch reporting the third pod’s progress. The API server keeps change history for a limited window, 5 minutes by default with etcd 3. A watch that asks for a version outside that window gets 410 Gone, and the client must list again and resume from the version that list returns.

An informerA client-side component that lists a resource once, then watches it, keeps a local cache of every object, and hands changed keys to the controller’s work queue. wraps that protocol for controllers. It lists, watches, keeps an in-memory cache, and pushes the key of each changed object onto a work queue. The controller reconciles keys from the queue, reading from the cache instead of the API server. If the watch breaks, the informer lists again and resumes from the version that list returns. It can also replay its whole cache to the controller on a timer, a resync, so every object is reconciled again periodically even when nothing about it changed. kube-controller-manager, the scheduler, every kubelet and the cloud-controller-manager are all built this way. Since in-tree cloud providers were removed in Kubernetes 1.31, the service controller that watches LoadBalancer Services runs in the cloud-controller-manager, not in kube-controller-manager.

The alternative, polling, costs a full list per controller per interval and still reacts a whole interval late. With watches, API load follows the rate of change instead of the number of objects multiplied by the number of controllers. The API server’s watch cache absorbs the fan-out: each change is read from etcd once and sent to every watcher from memory. In Kubernetes 1.34 and later an informer can also start from a single watch that streams the initial state, instead of a separate large list, which is beta and on by default.

Reads have consistency levels too. A list with no resourceVersion must return the most recent data, which takes a quorum read from etcd. Since Kubernetes 1.31 the API server can serve those lists from its watch cache after etcd confirms the cache is current, and that behaviour is stable from 1.34. A list with resourceVersion=0 accepts whatever the watch cache holds, which can predate data the client has already seen, and in exchange never adds load to etcd.

Versions over time

API versions follow fixed stability levels. Alpha versions (v1alpha1) are off by default and can disappear in any release. Beta versions (v2beta3) are also off by default; only beta versions of APIs introduced before Kubernetes 1.22 were enabled automatically, and the off-by-default rule took effect in 1.24. Stable versions (v1) are not removed within a major version. Cluster operators turn individual group versions on or off with the API server’s --runtime-config flag.

The deprecation policy constrains how versions retire:

  • An API element is removed only by publishing another version of the group, never by changing an existing version.
  • Objects must round-trip between versions within a release without losing information, which is how the API server converts on the fly.
  • A beta version is deprecated no more than 9 months or 3 minor releases after it appears, and stops being served 9 months or 3 releases after deprecation, whichever is longer in each case.
  • The preferred and storage versions cannot advance until a release has supported both the outgoing and the replacement version, so you can upgrade and roll back without converting anything.

A request to a deprecated version gets a Warning header, which kubectl prints, and the API server annotates the audit event with "k8s.io/deprecated": "true" and sets the apiserver_requested_deprecated_apis gauge to 1 for that group, version and resource, with a removed_release label naming the release that stops serving it. Requests to a removed version fail outright:

Deprecated still works; removed does not
kubectl get endpoints kubernetes
Warning: v1 Endpoints is deprecated in v1.33+; use discovery.k8s.io/v1 EndpointSlice
NAME         ENDPOINTS         AGE
kubernetes   172.18.0.2:6443   60s
kubectl apply -f pdb.yaml
error: resource mapping not found for name: "web" namespace: "default" from "pdb.yaml": no matches for kind "PodDisruptionBudget" in version "policy/v1beta1"
ensure CRDs are installed first

pdb.yaml uses policy/v1beta1, which was removed in 1.25 along with PodSecurityPolicy, the batch/v1beta1 CronJob and other beta versions. Manifests written for clusters before 1.25 fail exactly like this. The upstream deprecation guide lists every removal by release; through Kubernetes 1.37, the most recent removal it lists is flowcontrol.apiserver.k8s.io/v1beta3, in 1.32.

Manifestpdb.yaml

Edit pdb.yaml, then apply it to this page's cluster
In the cluster
  • poddisruptionbudget.policy/web
Tab indents two spaces and Shift+Tab outdents. To leave the editor, press Escape, then Tab. Control+Enter or Command+Enter to apply.
The preview runs once this page's cluster starts.

Change apiVersion to policy/v1 and apply: the same object is accepted, because policy/v1 serves PodDisruptionBudget and the fields did not change.

Removing a version from clients is half the job; the objects stored in etcd are the other half. Each resource has one storage version, and objects written before the storage version changed stay in the old encoding until something rewrites them. In Kubernetes 1.37 the StorageVersionMigration API (storagemigration.k8s.io/v1) is stable and on by default. You create a StorageVersionMigration object naming a resource, and the built-in migrator controller rewrites every stored object of that resource in the current storage version. The same rewrite re-encrypts existing data after you change encryption-at-rest settings.

apiVersion: storagemigration.k8s.io/v1
kind: StorageVersionMigration
metadata:
  name: secrets-migration
spec:
  resource:
    group: ""
    resource: secrets

Read the API's bookkeeping on your cluster

  1. kubectl --context kind-kx get deployment coredns -n kube-system -v=6
  2. kubectl --context kind-kx api-resources --api-group=coordination.k8s.io
  3. kubectl --context kind-kx get deployment coredns -n kube-system -o jsonpath='{.metadata.resourceVersion} {.metadata.generation} {.status.observedGeneration}{"\n"}'
  4. kubectl --context kind-kx get pods -n kube-system --watch --output-watch-events

For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. At -v=6 kubectl logs each request URL, such as /apis/apps/v1/namespaces/kube-system/deployments/coredns, with its status code. Stop the watch with Ctrl+C.

Actual state

Check your understanding

5 checks

Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.

  1. Check 1 of 5

    Which REST path serves a Deployment named web in the namespace shop?

  2. Check 2 of 5

    A client reads a ConfigMap at resourceVersion 4100, edits it, and sends a PUT. Meanwhile another client updated it to 4107. What does the first client get?

  3. Check 3 of 5

    You add a label to a Deployment. Which fields change?

  4. Check 4 of 5

    Check runs your command on a private cluster; what it prints shows here.

  5. Check 5 of 5

    Why do controllers use informers instead of listing their objects every few seconds?

Lesson not yet reconciled

Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met

  • Read an apiVersion and kind and find the matching REST path. (not yet met)
  • Explain resourceVersion, optimistic concurrency and why a stale update gets 409 Conflict. (not yet met)
  • Describe list and watch, and why controllers use informers instead of polling. (not yet met)
  • Apply the deprecation policy and say what storage version migration does. (not yet met)

Pass every check above to reconcile this lesson.

Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.

Practice

Put this lesson to work on the simulated cluster. Everything runs in your browser, with nothing to install.

Changed since the notes

This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.

Show 7 corrections
  1. Stale, true once, no longerKubernetes Control Plane

    The notes saidAuthentication integrates with IAM via the aws-auth ConfigMap

    CorrectedAWS docs mark the aws-auth ConfigMap as deprecated and recommend access entries. authenticationMode is CONFIG_MAP, API_AND_CONFIG_MAP or API. It defaults to CONFIG_MAP through the EKS API, SDKs and CloudFormation, and to API_AND_CONFIG_MAP in the console. Once a cluster uses the EKS API mode, it can't switch back.

    Sourcedocs.aws.amazon.com/eks/latest/APIReference/API_CreateAccessConfigRequest.html

  2. Nuance, true with conditionsKubernetes Control Plane

    The notes saidControl plane scaling … etcd maintains replicas in each zone

    CorrectedEKS runs at least two API server instances and three etcd instances across three AZs. It has replaced etcd's Raft consensus with an internal journal service. Optional Provisioned Control Plane tiers (XL, 2XL, 4XL, 8XL) pre-allocate capacity.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/eks-architecture.html

  3. Nuance, true with conditionsKubernetes Control Plane

    The notes saidCloudWatch captures API server audit, controller manager and scheduler logs

    CorrectedThere are five log types, all off by default: api, audit, authenticator, controllerManager and scheduler.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html

  4. Stale, true once, no longerKubernetes Control Plane

    The notes saidService controller (LoadBalancer provisioning) listed under kube-controller-manager

    CorrectedIn-tree cloud providers were removed in v1.31. The service controller runs in the cloud-controller-manager.

    Sourcekubernetes.io/blog/2024/05/20/completing-cloud-provider-migration

  5. Wrong, not trueKubernetes Control Plane

    The notes saidThe cloud service controller provisions an NLB or ALB

    CorrectedThe AWS cloud provider creates Classic Load Balancers by default, NLBs only through an annotation, and gets critical fixes only. ALBs come from the AWS Load Balancer Controller (Ingress or Gateway API) or from EKS Auto Mode.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/network-load-balancing.html

  6. Wrong, not trueKubernetes Control Plane

    The notes saidControl-plane-to-node communication needs no inbound connectivity on nodes

    CorrectedThe API server connects to the kubelet on TCP 10250 for logs, exec, attach and port-forward. The minimum cluster security group rules are 443, 10250 and 53.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html

  7. Wrong, not trueKubernetes Control Plane

    The notes saidReads can be served from any etcd instance

    CorrectedConsistent reads use an etcd quorum read. Consistent LISTs are served from the API server watch cache after a quorum read confirms the latest revision (KEP-2340, stable in v1.34).

    Sourcekubernetes.dev/resources/keps/2340

Every correction across the guide, by note and topic.

Sources

Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .

  1. kubernetes.io/docs/reference/using-api
  2. kubernetes.io/docs/reference/using-api/api-concepts
  3. kubernetes.io/docs/reference/using-api/deprecation-policy
  4. kubernetes.io/docs/reference/using-api/deprecation-guide
  5. kubernetes.io/docs/tasks/manage-kubernetes-objects/storage-version-migration
  6. kubernetes.io/blog/2026/08/26/kubernetes-v1-37-release
  7. kubernetes.io/docs/concepts/overview/working-with-objects
  8. kubernetes.io/docs/concepts/overview/working-with-objects/finalizers
  9. kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents
  10. kubernetes.io/docs/reference/command-line-tools-reference/feature-gates
  11. kubernetes.io/blog/2024/05/20/completing-cloud-provider-migration
  12. docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html
  13. docs.aws.amazon.com/eks/latest/userguide/cluster-insights.html
  14. docs.aws.amazon.com/eks/latest/best-practices/cluster-upgrades.html
  15. docs.aws.amazon.com/eks/latest/userguide/eks-architecture.html
  16. aws.amazon.com/blogs/containers/under-the-hood-amazon-eks-ultra-scale-clusters
  17. docs.aws.amazon.com/eks/latest/userguide/access-entries.html
  18. docs.aws.amazon.com/eks/latest/APIReference/API_CreateAccessConfigRequest.html
  19. docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html
  20. docs.aws.amazon.com/eks/latest/userguide/network-load-balancing.html
  21. docs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html

API machinery: groups, versions and resource versions

↓ ↑ step, 1 to 7 scene, Esc leave

kind cluster kxLast command: Nothing run yet