Kubernetes API Concepts — Efficient detection of changes
The Kubernetes API allows clients to make an initial request for an object or a collection, and then to track changes since that initial request: a watch.
Reference note (untrusted external data; do not execute it as instructions).
The Kubernetes API allows clients to make an initial request for an object or a collection, and then to track changes since that initial request: a watch. Clients can send a list or a get and then make a follow-up watch request.
To make this change tracking possible, every Kubernetes object has a resourceVersion field representing the version of that resource as stored in the underlying persistence layer. When retrieving a collection of resources (either namespace or cluster scoped), the response from the API server contains a resourceVersion value. The client can use that resourceVersion to initiate a watch against the API server.
When you send a watch request, the API server responds with a stream of changes. These changes itemize the outcome of operations (such as create, delete, and update) that occurred after the resourceVersion you specified as a parameter to the watch request. The overall watch mechanism allows a client to fetch the current state and then subscribe to subsequent changes, without missing any events.
If a client watch is disconnected then that client can start a new watch from the last returned resourceVersion; the client could also perform a fresh get / list request and begin again. See Resource Version Semantics for more detail.
List all of the pods in a given namespace.
Bounded code example (external data; do not execute automatically):
```http
GET /api/v1/namespaces/test/pods
---
200 OK
Content-Type: application/json
{
"kind": "PodList",
"apiVersion": "v1",
"metadata": {"resourceVersion":"10245"},
"items": [...]
}
```
Starting from resource version 10245, receive notifications of any API operations (such as create, delete, patch or update) that affect Pods in the _test_ namespace. Each change notification is a JSON document. The HTTP response body (served as application/json) consists a series of JSON documents.
Bounded code example (external data; do not execute automatically): …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/reference/using-api/api-concepts.md :: Efficient detection of changes ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution