The Kubernetes API and object model

Intermediate · 8 min

Groups, versions and resources, the fields every object carries, spec against status, resourceVersion and conflicts, generation, and owner references.

Before thisThe control plane

Shahrooz Aghili · 8 min

The Kubernetes API and object model

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

Taught by Shahrooz AghiliReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • The API is plain REST over HTTPS. A resource lives at a path built from its group, version, namespace and plural name, such as /apis/apps/v1/namespaces/default/deployments/web.
  • Every object has apiVersion, kind and metadata. Most also have spec, the desired state you write, and status, the observed state controllers write through a separate status subresource.
  • resourceVersion gives optimistic concurrency. An update carrying a stale resourceVersion is rejected with 409 Conflict instead of silently overwriting someone else's change.
  • metadata.generation counts spec changes only. When status.observedGeneration equals it, the controller has seen your latest spec.
  • ownerReferences link objects into a tree, such as Pod to ReplicaSet to Deployment, so the garbage collector can delete children when the owner goes.

One shape for everything

A cluster holds dozens of different things: workloads, network rules, storage claims, permissions, certificates, and whatever custom types your operators add. If each had its own protocol, every tool would need a special client for each. Kubernetes avoids that by making every one of them an object with the same skeleton, served by the same REST API, with the same rules for reading, writing, watching and deleting. Learn the shape once and kubectl, Helm, Argo CD and a Go controller all look alike.

The core objects lesson showed what the main objects are for. This one is about the shape they share.

Groups, versions, resources

Every API path is built from three coordinates:

  • Group: a family of related types. The original types (Pods, Services, ConfigMaps) live in the unnamed core group at /api/v1. Everything newer lives under /apis/<group>/<version>: apps, batch, networking.k8s.io, rbac.authorization.k8s.io and so on.
  • Version: v1alpha1, v1beta1, v1. A group can serve several versions of the same type at once, converting between them.
  • Resource: the plural, lower-case URL name, such as deployments.

So one Deployment lives at:

/apis/apps/v1/namespaces/default/deployments/web

The lab’s v1.37.3 API server lists 21 named groups at /apis, from apps and batch to resource.k8s.io (Dynamic Resource Allocation) and storagemigration.k8s.io. Asking one group what it serves:

$ kubectl get --raw /apis/apps/v1
controllerrevisions   namespaced  ControllerRevision
daemonsets            namespaced  DaemonSet
daemonsets/status     namespaced  DaemonSet
deployments           namespaced  Deployment
deployments/scale     namespaced  Scale
deployments/status    namespaced  Deployment
replicasets  ...  statefulsets  ...

(The JSON reply was trimmed to name, scope and kind.) Two things stand out. Each resource is either namespaced or cluster-scoped; Nodes, PersistentVolumes and ClusterRoles have no namespace. And some resources have subresources such as /status and /scale, which are separate endpoints with their own permissions. The kind (Deployment) is the type name inside the object; the resource (deployments) is the URL. People blur the two, but the API does not.

The fields every object has

Here is a real ConfigMap as the API server returns it:

{
  "kind": "ConfigMap",
  "apiVersion": "v1",
  "metadata": {
    "name": "app-config",
    "namespace": "default",
    "uid": "21240632-43e6-4861-95a2-4584e5769c62",
    "resourceVersion": "452",
    "creationTimestamp": "2026-11-28T17:54:33Z",
    "managedFields": [ { "manager": "kubectl-create", "operation": "Update", ... } ]
  },
  "data": { "color": "blue" }
}

apiVersion and kind say what it is. metadata is the same on every object: name and namespace identify it to humans, uid identifies this particular incarnation (delete and recreate it and the uid changes), and labels, annotations, finalizers and owner references hang here too. managedFields records who set which field; server-side apply is built on it.

Spec and status

Most objects then split into two halves. spec is what you want. status is what the system observed. A ConfigMap has neither, just data, because there is nothing to reconcile.

The split is enforced. For types with a status subresource, writes to the main endpoint ignore status, and only writes to /status change it. In the lab:

$ kubectl patch deploy api --type=merge -p '{"status":{"readyReplicas":2}}'
deployment.apps/api patched (no change)

Users write intent, controllers write observations, and RBAC can grant the two separately.

resourceVersion: no lost updates

Every object carries a resourceVersion, an opaque string that changes on every write. It powers optimistic concurrency. When you send a full update (PUT), the API server compares your copy’s resourceVersion with the stored one and rejects a mismatch. Two copies of the same ConfigMap, edited to different colours and replaced one after the other:

$ kubectl replace -f a.json
configmap/app-config replaced
$ kubectl replace -f b.json
Error from server (Conflict): error when replacing "b.json": Operation cannot be
fulfilled on configmaps "app-config": the object has been modified; please apply
your changes to the latest version and try again

Think of it as a library card stamp. You may return your edited copy only if nobody else returned one since you checked it out. The fix is to re-read and retry, which is exactly what controllers do; the lab’s audit log shows the Deployment controller getting a 409 on a Deployment status update and succeeding on a retry a few milliseconds later. The same number powers watches: a client lists objects, notes the resourceVersion, then asks for every change after it.

generation and observedGeneration

metadata.generation is a counter the API server bumps when the spec changes, and not for metadata or status. Controllers copy the generation they have processed into status.observedGeneration:

gen=1 observed=1      # after create
gen=2 observed=2      # after kubectl scale --replicas=2
gen=2                 # after kubectl label: metadata changed, generation did not

If observedGeneration lags behind generation, the controller has not caught up with your edit yet. kubectl rollout status waits on exactly this before it trusts the replica counts.

Owner references

The Pods a Deployment creates point back up the chain:

"ownerReferences": [{"apiVersion":"apps/v1","kind":"ReplicaSet","name":"api-5f8476ddb6",
  "uid":"17f0378a-...","controller":true,"blockOwnerDeletion":true}]

The ReplicaSet in turn points at the Deployment. Delete the Deployment and the garbage collector controller removes the ReplicaSet, then the Pods. controller: true marks the one owner that manages the object, which is how a ReplicaSet knows not to adopt a Pod some other controller already claims.

About the video

The embed is Shahrooz Aghili’s “Introduction to Kubernetes API: Architecture, Interaction, and Object Model - Part 1” (February 2025, 8 minutes). Judged from its chapters, it covers the API’s architecture, how clients interact with it, API groups and versions, and the object model, which is this lesson’s spine at slide-talk speed. It does not go into resourceVersion, generation or owner references, which the lesson adds. English was judged from the English title, description and caption track; there is no audio-track metadata. KodeKloud’s longer 2021 video in deeper spends more time on groups, versions and the deprecation policy; its version examples are dated.

What was run: every output above, the group list, /apis/apps/v1, the ConfigMap JSON, the 409 Conflict, the ignored status patch, the generation counts and the owner reference, came from a local v1.37.3 API server whose nodes run no containers, on 2026-11-28. Field semantics are from the API conventions document and the API concepts page, checked the same day.

Where this fits

Status gets written by controllers. Next, how they work: controllers and the reconcile loop.

Check yourself

  1. 01Two scripts read the same ConfigMap, each change one value, and each send a full update. What happens with the second write, and why is that good?

    It fails with 409 Conflict, because its resourceVersion no longer matches the stored one. Without that check it would silently erase the first script's change. The second script should re-read the object and retry.

  2. 02You run kubectl patch to set a Deployment's status.readyReplicas to 5. What happens?

    Nothing. For resources with a status subresource, writes to the main endpoint ignore status, and kubectl reports no change. Status is written through /status, normally only by the controller, so users cannot fake what the system observed.

  3. 03You changed a Deployment's image. How can a script tell that the Deployment controller has at least seen the change?

    Compare metadata.generation with status.observedGeneration. The edit bumped generation; when the controller processes it, it copies that number into observedGeneration. kubectl rollout status uses this check before looking at replica counts.

  4. 04What is the difference between a kind and a resource?

    A kind is the type of an object, such as Deployment, named in the object's body. A resource is the URL name the API serves it at, such as deployments. One kind can be served by more than one resource; Scale, for example, appears as deployments/scale and replicasets/scale.

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