Skip to content

Commit fd75f1b

Browse files
committed
update using-api/api-concepts.md
1 parent 5a50fa4 commit fd75f1b

File tree

1 file changed

+58
-49
lines changed

1 file changed

+58
-49
lines changed

content/en/docs/reference/using-api/api-concepts.md

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ primary resources via the standard HTTP verbs (POST, PUT, PATCH, DELETE,
1515
GET).
1616

1717
For some resources, the API includes additional subresources that allow
18-
fine grained authorization (such as separate views for Pod details and
18+
fine-grained authorization (such as separate views for Pod details and
1919
log retrievals), and can accept and serve those resources in different
2020
representations for convenience or efficiency.
2121

@@ -65,7 +65,7 @@ example: Nodes), and so their names must be unique across the whole cluster.
6565
### API verbs
6666

6767
Almost all object resource types support the standard HTTP verbs - GET, POST, PUT, PATCH,
68-
and DELETE. Kubernetes also uses its own verbs, which are often written lowercase to distinguish
68+
and DELETE. Kubernetes also uses its own verbs, which are often written in lowercase to distinguish
6969
them from HTTP verbs.
7070

7171
Kubernetes uses the term **list** to describe returning a [collection](#collections) of
@@ -78,7 +78,6 @@ For PUT requests, Kubernetes internally classifies these as either **create** or
7878
based on the state of the existing object. An **update** is different from a **patch**; the
7979
HTTP verb for a **patch** is PATCH.
8080

81-
8281
## Resource URIs
8382

8483
All resource types are either scoped by the cluster (`/apis/GROUP/VERSION/*`) or to a
@@ -89,6 +88,7 @@ is controlled by authorization checks on the namespace scope.
8988
Note: core resources use `/api` instead of `/apis` and omit the GROUP path segment.
9089

9190
Examples:
91+
9292
* `/api/v1/namespaces`
9393
* `/api/v1/pods`
9494
* `/api/v1/namespaces/my-namespace/pods`
@@ -106,9 +106,12 @@ The following paths are used to retrieve collections and resources:
106106

107107
* Namespace-scoped resources:
108108

109-
* `GET /apis/GROUP/VERSION/RESOURCETYPE` - return the collection of all instances of the resource type across all namespaces
110-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` - return collection of all instances of the resource type in NAMESPACE
111-
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` - return the instance of the resource type with NAME in NAMESPACE
109+
* `GET /apis/GROUP/VERSION/RESOURCETYPE` - return the collection of all
110+
instances of the resource type across all namespaces
111+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE` - return
112+
collection of all instances of the resource type in NAMESPACE
113+
* `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME` -
114+
return the instance of the resource type with NAME in NAMESPACE
112115

113116
Since a namespace is a cluster-scoped resource type, you can retrieve the list
114117
(“collection”) of all namespaces with `GET /api/v1/namespaces` and details about
@@ -182,11 +185,15 @@ For example:
182185
```
183186

184187
### YAML resource encoding {#yaml-encoding}
185-
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html) media type for both requests and responses. [`YAML`](https://yaml.org/) can be used for defining Kubernetes manifests and API interactions.
188+
189+
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html)
190+
media type for both requests and responses. [`YAML`](https://yaml.org/)
191+
can be used for defining Kubernetes manifests and API interactions.
186192

187193
For example:
188194

189195
1. List all of the pods on a cluster in YAML format
196+
190197
```
191198
GET /api/v1/pods
192199
Accept: application/yaml
@@ -200,13 +207,14 @@ For example:
200207
```
201208

202209
1. Create a pod by sending YAML-encoded data to the server, requesting a YAML response:
210+
203211
```
204212
POST /api/v1/namespaces/test/pods
205213
Content-Type: application/yaml
206214
Accept: application/yaml
207215
… YAML encoded Pod object
208216
```
209-
217+
210218
```
211219
200 OK
212220
Content-Type: application/yaml
@@ -224,7 +232,7 @@ Kubernetes uses an envelope wrapper to encode [Protobuf](https://protobuf.dev/)
224232
That wrapper starts with a 4 byte magic number to help identify content in disk or in etcd as Protobuf
225233
(as opposed to JSON). The 4 byte magic number data is followed by a Protobuf encoded wrapper message, which
226234
describes the encoding and type of the underlying object. Within the Protobuf wrapper message,
227-
the inner object data is recorded using the `raw` field of Unknown (see the [IDL](##protobuf-encoding-idl)
235+
the inner object data is recorded using the `raw` field of Unknown (see the [IDL](#protobuf-encoding-idl)
228236
for more detail).
229237

230238
For example:
@@ -323,7 +331,6 @@ For example:
323331
Accept: application/vnd.kubernetes.protobuf, application/json
324332
```
325333

326-
327334
## Efficient detection of changes
328335

329336
The Kubernetes API allows clients to make an initial request for an object or a
@@ -576,7 +583,7 @@ of 500 pods at a time, request those chunks as follows:
576583
}
577584
```
578585

579-
2. Continue the previous call, retrieving the next set of 500 pods.
586+
1. Continue the previous call, retrieving the next set of 500 pods.
580587

581588
```
582589
GET /api/v1/pods?limit=500&continue=ENCODED_CONTINUE_TOKEN
@@ -597,7 +604,7 @@ of 500 pods at a time, request those chunks as follows:
597604
}
598605
```
599606

600-
3. Continue the previous call, retrieving the last 253 pods.
607+
1. Continue the previous call, retrieving the last 253 pods.
601608

602609
```
603610
GET /api/v1/pods?limit=500&continue=ENCODED_CONTINUE_TOKEN_2
@@ -642,14 +649,15 @@ collections of different types of resource. Collections have a kind
642649
named for the resource kind, with `List` appended.
643650

644651
When you query the API for a particular type, all items returned by that query are
645-
of that type.
646-
For example, when you **list** Services, the collection response
652+
of that type. For example, when you **list** Services, the collection response
647653
has `kind` set to
648-
[`ServiceList`](/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceList); each item in that collection represents a single Service. For example:
654+
[`ServiceList`](/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceList);
655+
each item in that collection represents a single Service. For example:
649656

650657
```
651658
GET /api/v1/services
652659
```
660+
653661
```yaml
654662
{
655663
"kind": "ServiceList",
@@ -876,7 +884,7 @@ These situations are:
876884
exception to this is for {{< glossary_tooltip
877885
term_id="CustomResourceDefinition" text="CRDs" >}} that explicitly choose not to prune unknown
878886
fields via `x-kubernetes-preserve-unknown-fields`).
879-
2. The field is duplicated in the object.
887+
1. The field is duplicated in the object.
880888

881889
### Validation for unrecognized or duplicate fields {#setting-the-field-validation-level}
882890

@@ -888,21 +896,21 @@ validation are `Ignore`, `Warn` (default), and `Strict`.
888896

889897
`Ignore`
890898
: The API server succeeds in handling the request as it would without the erroneous fields
891-
being set, dropping all unknown and duplicate fields and giving no indication it
892-
has done so.
899+
being set, dropping all unknown and duplicate fields and giving no indication it
900+
has done so.
893901

894902
`Warn`
895903
: (Default) The API server succeeds in handling the request, and reports a
896-
warning to the client. The warning is sent using the `Warning:` response header,
897-
adding one warning item for each unknown or duplicate field. For more
898-
information about warnings and the Kubernetes API, see the blog article
899-
[Warning: Helpful Warnings Ahead](/blog/2020/09/03/warnings/).
904+
warning to the client. The warning is sent using the `Warning:` response header,
905+
adding one warning item for each unknown or duplicate field. For more
906+
information about warnings and the Kubernetes API, see the blog article
907+
[Warning: Helpful Warnings Ahead](/blog/2020/09/03/warnings/).
900908

901909
`Strict`
902910
: The API server rejects the request with a 400 Bad Request error when it
903-
detects any unknown or duplicate fields. The response message from the API
904-
server specifies all the unknown or duplicate fields that the API server has
905-
detected.
911+
detects any unknown or duplicate fields. The response message from the API
912+
server specifies all the unknown or duplicate fields that the API server has
913+
detected.
906914

907915
The field validation level is set by the `fieldValidation` query parameter.
908916

@@ -962,7 +970,6 @@ string, working as an enum, and the only accepted values are:
962970
: Every stage runs as normal, except for the final storage stage where side effects
963971
are prevented.
964972

965-
966973
When you set `?dryRun=All`, any relevant
967974
{{< glossary_tooltip text="admission controllers" term_id="admission-controller" >}}
968975
are run, validating admission controllers check the request post-mutation, merge is
@@ -995,7 +1002,6 @@ Accept: application/json
9951002
The response would look the same as for non-dry-run request, but the values of some
9961003
generated fields may differ.
9971004

998-
9991005
### Generated values
10001006

10011007
Some values of an object are typically generated before the object is persisted. It
@@ -1005,7 +1011,8 @@ request is made. Some of these fields are:
10051011

10061012
* `name`: if `generateName` is set, `name` will have a unique random name
10071013
* `creationTimestamp` / `deletionTimestamp`: records the time of creation/deletion
1008-
* `UID`: [uniquely identifies](/docs/concepts/overview/working-with-objects/names/#uids) the object and is randomly generated (non-deterministic)
1014+
* `UID`: [uniquely identifies](/docs/concepts/overview/working-with-objects/names/#uids)
1015+
the object and is randomly generated (non-deterministic)
10091016
* `resourceVersion`: tracks the persisted version of the object
10101017
* Any field set by a mutating admission controller
10111018
* For the `Service` resource: Ports or IP addresses that the kube-apiserver assigns to Service objects
@@ -1045,7 +1052,8 @@ provided is stale), the API server returns a `409 Conflict` error response.
10451052

10461053
Instead of sending a PUT request, the client can send an instruction to the API
10471054
server to **patch** an existing resource. A **patch** is typically appropriate
1048-
if the change that the client wants to make isn't conditional on the existing data. Clients that need effective detection of lost updates should consider
1055+
if the change that the client wants to make isn't conditional on the existing data.
1056+
Clients that need effective detection of lost updates should consider
10491057
making their request conditional on the existing `resourceVersion` (either HTTP PUT or HTTP PATCH),
10501058
and then handle any retries that are needed in case there is a conflict.
10511059

@@ -1090,7 +1098,6 @@ corresponding HTTP `Content-Type` header:
10901098
Patch.
10911099
{{< /note >}}
10921100

1093-
10941101
Kubernetes' [Server Side Apply](/docs/reference/using-api/server-side-apply/)
10951102
feature allows the control plane to track managed fields for newly created objects.
10961103
Server Side Apply provides a clear pattern for managing field conflicts,
@@ -1143,10 +1150,10 @@ A **patch** update is helpful, because:
11431150

11441151
However:
11451152

1146-
* you need more local (client) logic to build the patch; it helps a lot if you have
1147-
a library implementation of JSON Patch, or even for making a JSON Patch specifically against Kubernetes
1148-
* as the author of client software, you need to be careful when building the patch
1149-
(the HTTP request body) not to drop fields (the order of operations matters)
1153+
* You need more local (client) logic to build the patch; it helps a lot if you have
1154+
a library implementation of JSON Patch, or even for making a JSON Patch specifically against Kubernetes.
1155+
* As the author of client software, you need to be careful when building the patch
1156+
(the HTTP request body) not to drop fields (the order of operations matters).
11501157

11511158
#### HTTP PATCH using Server-Side Apply {#update-mechanism-server-side-apply}
11521159

@@ -1155,13 +1162,13 @@ Server-Side Apply has some clear benefits:
11551162
* A single round trip: it rarely requires making a `GET` request first.
11561163
* and you can still detect conflicts for unexpected changes
11571164
* you have the option to force override a conflict, if appropriate
1158-
* Client implementations are easy to make
1165+
* Client implementations are easy to make.
11591166
* You get an atomic create-or-update operation without extra effort
1160-
(similar to `UPSERT` in some SQL dialects)
1167+
(similar to `UPSERT` in some SQL dialects).
11611168

11621169
However:
11631170

1164-
* Server-Side Apply does not work at all for field changes that depend on a current value of the object
1171+
* Server-Side Apply does not work at all for field changes that depend on a current value of the object.
11651172
* You can only apply updates to objects. Some resources in the Kubernetes HTTP API are
11661173
not objects (they do not have a `.metadata` field), and Server-Side Apply
11671174
is only relevant for Kubernetes objects.
@@ -1183,9 +1190,12 @@ resource versions for greater-than or less-than relationships).
11831190
Clients find resource versions in resources, including the resources from the response
11841191
stream for a **watch**, or when using **list** to enumerate resources.
11851192

1186-
[v1.meta/ObjectMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta) - The `metadata.resourceVersion` of a resource instance identifies the resource version the instance was last modified at.
1193+
[v1.meta/ObjectMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#objectmeta-v1-meta) -
1194+
The `metadata.resourceVersion` of a resource instance identifies the resource version the instance was last modified at.
11871195

1188-
[v1.meta/ListMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#listmeta-v1-meta) - The `metadata.resourceVersion` of a resource collection (the response to a **list**) identifies the resource version at which the collection was constructed.
1196+
[v1.meta/ListMeta](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#listmeta-v1-meta) -
1197+
The `metadata.resourceVersion` of a resource collection (the response to a **list**) identifies the
1198+
resource version at which the collection was constructed.
11891199

11901200
### `resourceVersion` parameters in query strings {#the-resourceversion-parameter}
11911201

@@ -1226,21 +1236,20 @@ quorum read to be served.
12261236

12271237
Setting the `resourceVersionMatch` parameter without setting `resourceVersion` is not valid.
12281238

1229-
12301239
This table explains the behavior of **list** requests with various combinations of
12311240
`resourceVersion` and `resourceVersionMatch`:
12321241

12331242
{{< table caption="resourceVersionMatch and paging parameters for list" >}}
12341243

1235-
| resourceVersionMatch param | paging params | resourceVersion not set | resourceVersion="0" | resourceVersion="{value other than 0}" |
1236-
|---------------------------------------|-------------------------------|-----------------------|-------------------------------------------|----------------------------------------|
1237-
| _unset_ | _limit unset_ | Most Recent | Any | Not older than |
1238-
| _unset_ | limit=\<n\>, _continue unset_ | Most Recent | Any | Exact |
1239-
| _unset_ | limit=\<n\>, continue=\<token\> | Continue Token, Exact | Invalid, treated as Continue Token, Exact | Invalid, HTTP `400 Bad Request` |
1240-
| `resourceVersionMatch=Exact` | _limit unset_ | Invalid | Invalid | Exact |
1241-
| `resourceVersionMatch=Exact` | limit=\<n\>, _continue unset_ | Invalid | Invalid | Exact |
1242-
| `resourceVersionMatch=NotOlderThan` | _limit unset_ | Invalid | Any | Not older than |
1243-
| `resourceVersionMatch=NotOlderThan` | limit=\<n\>, _continue unset_ | Invalid | Any | Not older than |
1244+
| resourceVersionMatch param | paging params | resourceVersion not set | resourceVersion="0" | resourceVersion="{value other than 0}" |
1245+
|----------------------------|---------------|-------------------------|---------------------|----------------------------------------|
1246+
| _unset_ | _limit unset_ | Most Recent | Any | Not older than |
1247+
| _unset_ | limit=\<n\>, _continue unset_ | Most Recent | Any | Exact |
1248+
| _unset_ | limit=\<n\>, continue=\<token\>| Continue Token, Exact | Invalid, treated as Continue Token, Exact | Invalid, HTTP `400 Bad Request` |
1249+
| `resourceVersionMatch=Exact` | _limit unset_ | Invalid | Invalid | Exact |
1250+
| `resourceVersionMatch=Exact` | limit=\<n\>, _continue unset_ | Invalid | Invalid | Exact |
1251+
| `resourceVersionMatch=NotOlderThan` | _limit unset_ | Invalid | Any | Not older than |
1252+
| `resourceVersionMatch=NotOlderThan` | limit=\<n\>, _continue unset_ | Invalid | Any | Not older than |
12441253

12451254
{{< /table >}}
12461255

0 commit comments

Comments
 (0)