Skip to content

Commit c268f09

Browse files
authored
Merge pull request #45431 from chanieljdan/merged-main-dev-1.30
Merge main branch into dev-1.30
2 parents 790379c + 804b365 commit c268f09

File tree

40 files changed

+1971
-493
lines changed

40 files changed

+1971
-493
lines changed

content/en/docs/concepts/overview/kubernetes-api.md

Lines changed: 141 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,139 @@ external components communicate with one another.
2222
The Kubernetes API lets you query and manipulate the state of API objects in Kubernetes
2323
(for example: Pods, Namespaces, ConfigMaps, and Events).
2424

25-
Most operations can be performed through the
26-
[kubectl](/docs/reference/kubectl/) command-line interface or other
27-
command-line tools, such as
28-
[kubeadm](/docs/reference/setup-tools/kubeadm/), which in turn use the
29-
API. However, you can also access the API directly using REST calls.
25+
Most operations can be performed through the [kubectl](/docs/reference/kubectl/)
26+
command-line interface or other command-line tools, such as
27+
[kubeadm](/docs/reference/setup-tools/kubeadm/), which in turn use the API.
28+
However, you can also access the API directly using REST calls. Kubernetes
29+
provides a set of [client libraries](/docs/reference/using-api/client-libraries/)
30+
for those looking to
31+
write applications using the Kubernetes API.
32+
33+
Each Kubernetes cluster publishes the specification of the APIs that the cluster serves.
34+
There are two mechanisms that Kubernetes uses to publish these API specifications; both are useful
35+
to enable automatic interoperability. For example, the `kubectl` tool fetches and caches the API
36+
specification for enabling command-line completion and other features.
37+
The two supported mechanisms are as follows:
38+
39+
- [The Discovery API](#discovery-api) provides information about the Kubernetes APIs:
40+
API names, resources, versions, and supported operations. This is a Kubernetes
41+
specific term as it is a separate API from the Kubernetes OpenAPI.
42+
It is intended to be a brief summary of the available resources and it does not
43+
detail specific schema for the resources. For reference about resource schemas,
44+
please refer to the OpenAPI document.
45+
46+
- The [Kubernetes OpenAPI Document](#openapi-specification) provides (full)
47+
[OpenAPI v2.0 and 3.0 schemas](https://www.openapis.org/) for all Kubernetes API
48+
endpoints.
49+
The OpenAPI v3 is the preferred method for accessing OpenAPI as it
50+
provides
51+
a more comprehensive and accurate view of the API. It includes all the available
52+
API paths, as well as all resources consumed and produced for every operations
53+
on every endpoints. It also includes any extensibility components that a cluster supports.
54+
The data is a complete specification and is significantly larger than that from the
55+
Discovery API.
56+
57+
## Discovery API
58+
59+
Kubernetes publishes a list of all group versions and resources supported via
60+
the Discovery API. This includes the following for each resource:
61+
62+
- Name
63+
- Cluster or namespaced scope
64+
- Endpoint URL and supported verbs
65+
- Alternative names
66+
- Group, version, kind
67+
68+
The API is available both aggregated and unaggregated form. The aggregated
69+
discovery serves two endpoints while the unaggregated discovery serves a
70+
separate endpoint for each group version.
71+
72+
### Aggregated discovery
73+
74+
{{< feature-state state="beta" for_k8s_version="v1.27" >}}
3075

31-
Consider using one of the [client libraries](/docs/reference/using-api/client-libraries/)
32-
if you are writing an application using the Kubernetes API.
76+
Kubernetes offers beta support for aggregated discovery, publishing
77+
all resources supported by a cluster through two endpoints (`/api` and
78+
`/apis`). Requesting this
79+
endpoint drastically reduces the number of requests sent to fetch the
80+
discovery data from the cluster. You can access the data by
81+
requesting the respective endpoints with an `Accept` header indicating
82+
the aggregated discovery resource:
83+
`Accept: application/json;v=v2beta1;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList`.
84+
85+
Without indicating the resource type using the `Accept` header, the default
86+
response for the `/api` and `/apis` endpoint is an unaggregated discovery
87+
document.
88+
89+
The [discovery document](https://github.com/kubernetes/kubernetes/blob/release-v{{< skew currentVersion >}}/api/discovery/aggregated_v2beta1.json)
90+
for the built-in resources can be found in the Kubernetes GitHub repository.
91+
This Github document can be used as a reference of the base set of the available resources
92+
if a Kubernetes cluster is not available to query.
93+
94+
The endpoint also supports ETag and protobuf encoding.
95+
96+
### Unaggregated discovery
97+
98+
Without discovery aggregation, discovery is published in levels, with the root
99+
endpoints publishing discovery information for downstream documents.
100+
101+
A list of all group versions supported by a cluster is published at
102+
the `/api` and `/apis` endpoints. Example:
103+
104+
```
105+
{
106+
"kind": "APIGroupList",
107+
"apiVersion": "v1",
108+
"groups": [
109+
{
110+
"name": "apiregistration.k8s.io",
111+
"versions": [
112+
{
113+
"groupVersion": "apiregistration.k8s.io/v1",
114+
"version": "v1"
115+
}
116+
],
117+
"preferredVersion": {
118+
"groupVersion": "apiregistration.k8s.io/v1",
119+
"version": "v1"
120+
}
121+
},
122+
{
123+
"name": "apps",
124+
"versions": [
125+
{
126+
"groupVersion": "apps/v1",
127+
"version": "v1"
128+
}
129+
],
130+
"preferredVersion": {
131+
"groupVersion": "apps/v1",
132+
"version": "v1"
133+
}
134+
},
135+
...
136+
}
137+
```
138+
139+
Additional requests are needed to obtain the discovery document for each group version at
140+
`/apis/<group>/<version>` (for example:
141+
`/apis/rbac.authorization.k8s.io/v1alpha1`), which advertises the list of
142+
resources served under a particular group version. These endpoints are used by
143+
kubectl to fetch the list of resources supported by a cluster.
33144

34145
<!-- body -->
35146

36-
## OpenAPI specification {#api-specification}
147+
<a id="#api-specification" />
37148

38-
Complete API details are documented using [OpenAPI](https://www.openapis.org/).
149+
## OpenAPI interface definition
39150

151+
For details about the OpenAPI specifications, see the [OpenAPI documentation](https://www.openapis.org/).
152+
153+
Kubernetes serves both OpenAPI v2.0 and OpenAPI v3.0. OpenAPI v3 is the
154+
preferred method of accessing the OpenAPI because it offers a more comprehensive
155+
(lossless) representation of Kubernetes resources. Due to limitations of OpenAPI
156+
version 2, certain fields are dropped from the published OpenAPI including but not
157+
limited to `default`, `nullable`, `oneOf`.
40158
### OpenAPI V2
41159

42160
The Kubernetes API server serves an aggregated OpenAPI v2 spec via the
@@ -74,11 +192,6 @@ request headers as follows:
74192
</tbody>
75193
</table>
76194

77-
Kubernetes implements an alternative Protobuf based serialization format that
78-
is primarily intended for intra-cluster communication. For more information
79-
about this format, see the [Kubernetes Protobuf serialization](https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md) design proposal and the
80-
Interface Definition Language (IDL) files for each schema located in the Go
81-
packages that define the API objects.
82195

83196
### OpenAPI V3
84197

@@ -149,7 +262,20 @@ Refer to the table below for accepted request headers.
149262
</tbody>
150263
</table>
151264

152-
A Golang implementation to fetch the OpenAPI V3 is provided in the package `k8s.io/client-go/openapi3`.
265+
A Golang implementation to fetch the OpenAPI V3 is provided in the package
266+
[`k8s.io/client-go/openapi3`](https://pkg.go.dev/k8s.io/client-go/openapi3).
267+
268+
Kubernetes {{< skew currentVersion >}} publishes
269+
OpenAPI v2.0 and v3.0; there are no plans to support 3.1 in the near future.
270+
271+
### Protobuf serialization
272+
273+
Kubernetes implements an alternative Protobuf based serialization format that
274+
is primarily intended for intra-cluster communication. For more information
275+
about this format, see the [Kubernetes Protobuf serialization](https://git.k8s.io/design-proposals-archive/api-machinery/protobuf.md)
276+
design proposal and the
277+
Interface Definition Language (IDL) files for each schema located in the Go
278+
packages that define the API objects.
153279

154280
## Persistence
155281

@@ -238,8 +364,6 @@ ways that require deleting all existing alpha objects prior to upgrade.
238364
Refer to [API versions reference](/docs/reference/using-api/#api-versioning)
239365
for more details on the API version level definitions.
240366

241-
242-
243367
## API Extension
244368

245369
The Kubernetes API can be extended in one of two ways:

content/en/docs/contribute/style/style-guide.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,20 @@ The copy is called a "fork". | The copy is called a "fork."
116116

117117
## Inline code formatting
118118

119-
### Use code style for inline code, commands, and API objects {#code-style-inline-code}
119+
### Use code style for inline code, commands {#code-style-inline-code}
120120

121121
For inline code in an HTML document, use the `<code>` tag. In a Markdown
122-
document, use the backtick (`` ` ``).
122+
document, use the backtick (`` ` ``). However, API kinds such as StatefulSet
123+
or ConfigMap are written verbatim (no backticks); this allows using possessive
124+
apostrophes.
123125

124126
{{< table caption = "Do and Don't - Use code style for inline code, commands, and API objects" >}}
125127
Do | Don't
126128
:--| :-----
127-
The `kubectl run` command creates a `Pod`. | The "kubectl run" command creates a pod.
128-
The kubelet on each node acquires a `Lease`… | The kubelet on each node acquires a lease…
129-
A `PersistentVolume` represents durable storage… | A Persistent Volume represents durable storage…
129+
The `kubectl run` command creates a Pod. | The "kubectl run" command creates a Pod.
130+
The kubelet on each node acquires a Lease… | The kubelet on each node acquires a `Lease`
131+
A PersistentVolume represents durable storage… | A `PersistentVolume` represents durable storage…
132+
The CustomResourceDefinition's `.spec.group` field… | The `CustomResourceDefinition.spec.group` field…
130133
For declarative management, use `kubectl apply`. | For declarative management, use "kubectl apply".
131134
Enclose code samples with triple backticks. (\`\`\`)| Enclose code samples with any other syntax.
132135
Use single backticks to enclose inline code. For example, `var example = true`. | Use two asterisks (`**`) or an underscore (`_`) to enclose inline code. For example, **var example = true**.
@@ -191,37 +194,60 @@ Set the value of `image` to nginx:1.16. | Set the value of `image` to `nginx:1.1
191194
Set the value of the `replicas` field to 2. | Set the value of the `replicas` field to `2`.
192195
{{< /table >}}
193196

197+
However, consider quoting values where there is a risk that readers might confuse the value
198+
with an API kind.
199+
194200
## Referring to Kubernetes API resources
195201

196202
This section talks about how we reference API resources in the documentation.
197203

198204
### Clarification about "resource"
199205

200-
Kubernetes uses the word "resource" to refer to API resources, such as `pod`,
201-
`deployment`, and so on. We also use "resource" to talk about CPU and memory
202-
requests and limits. Always refer to API resources as "API resources" to avoid
203-
confusion with CPU and memory resources.
206+
Kubernetes uses the word _resource_ to refer to API resources. For example,
207+
the URL path `/apis/apps/v1/namespaces/default/deployments/my-app` represents a
208+
Deployment named "my-app" in the "default"
209+
{{< glossary_tooltip text="namespace" term_id="namespace" >}}. In HTTP jargon,
210+
{{< glossary_tooltip text="namespace" term_id="namespace" >}} is a resource -
211+
the same way that all web URLs identify a resource.
212+
213+
Kubernetes documentation also uses "resource" to talk about CPU and memory
214+
requests and limits. It's very often a good idea to refer to API resources
215+
as "API resources"; that helps to avoid confusion with CPU and memory resources,
216+
or with other kinds of resource.
217+
218+
If you are using the lowercase plural form of a resource name, such as
219+
`deployments` or `configmaps`, provide extra written context to help readers
220+
understand what you mean. If you are using the term in a context where the
221+
UpperCamelCase name could work too, and there is a risk of ambiguity,
222+
consider using the API kind in UpperCamelCase.
204223

205224
### When to use Kubernetes API terminologies
206225

207226
The different Kubernetes API terminologies are:
208227

209-
- Resource type: the name used in the API URL (such as `pods`, `namespaces`)
210-
- Resource: a single instance of a resource type (such as `pod`, `secret`)
211-
- Object: a resource that serves as a "record of intent". An object is a desired
228+
- _API kinds_: the name used in the API URL (such as `pods`, `namespaces`).
229+
API kinds are sometimes also called _resource types_.
230+
- _API resource_: a single instance of an API kind (such as `pod`, `secret`).
231+
- _Object_: a resource that serves as a "record of intent". An object is a desired
212232
state for a specific part of your cluster, which the Kubernetes control plane tries to maintain.
233+
All objects in the Kubernetes API are also resources.
213234

214-
Always use "resource" or "object" when referring to an API resource in docs.
215-
For example, use "a `Secret` object" over just "a `Secret`".
235+
For clarity, you can add "resource" or "object" when referring to an API resource in Kubernetes
236+
documentation.
237+
An example: write "a Secret object" instead of "a Secret".
238+
If it is clear just from the capitalization, you don't need to add the extra word.
239+
240+
Consider rephrasing when that change helps avoid misunderstandings. A common situation is
241+
when you want to start a sentence with an API kind, such as “Secret”; because English
242+
and other languages capitalize at the start of sentences, readers cannot tell whether you
243+
mean the API kind or the general concept. Rewording can help.
216244

217245
### API resource names
218246

219247
Always format API resource names using [UpperCamelCase](https://en.wikipedia.org/wiki/Camel_case),
220-
also known as PascalCase, and code formatting.
221-
222-
For inline code in an HTML document, use the `<code>` tag. In a Markdown document, use the backtick (`` ` ``).
248+
also known as PascalCase. Do not write API kinds with code formatting.
223249

224-
Don't split an API object name into separate words. For example, use `PodTemplateList`, not Pod Template List.
250+
Don't split an API object name into separate words. For example, use PodTemplateList, not Pod Template List.
225251

226252
For more information about PascalCase and code formatting, please review the related guidance on
227253
[Use upper camel case for API objects](/docs/contribute/style/style-guide/#use-upper-camel-case-for-api-objects)
@@ -237,7 +263,7 @@ guidance on [Kubernetes API terminology](/docs/reference/using-api/api-concepts/
237263
{{< table caption = "Do and Don't - Don't include the command prompt" >}}
238264
Do | Don't
239265
:--| :-----
240-
kubectl get pods | $ kubectl get pods
266+
`kubectl get pods` | `$ kubectl get pods`
241267
{{< /table >}}
242268

243269
### Separate commands from output

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ Example CEL expressions:
5555
| `has(self.expired) && self.created + self.ttl < self.expired` | Validate that 'expired' date is after a 'create' date plus a 'ttl' duration |
5656
| `self.health.startsWith('ok')` | Validate a 'health' string field has the prefix 'ok' |
5757
| `self.widgets.exists(w, w.key == 'x' && w.foo < 10)` | Validate that the 'foo' property of a listMap item with a key 'x' is less than 10 |
58-
| `type(self) == string ? self == '99%' : self == 42` | Validate an int-or-string field for both the int and string cases |
58+
| `type(self) == string ? self == '99%' : self == 42` | Validate an int-or-string field for both the int and string cases |
5959
| `self.metadata.name == 'singleton'` | Validate that an object's name matches a specific value (making it a singleton) |
6060
| `self.set1.all(e, !(e in self.set2))` | Validate that two listSets are disjoint |
6161
| `self.names.size() == self.details.size() && self.names.all(n, n in self.details)` | Validate the 'details' map is keyed by the items in the 'names' listSet |
62+
| `self.details.all(key, key.matches('^[a-zA-Z]*$')` | Validate the keys of the 'details' map |
63+
| `self.details.all(key, self.details[key].matches('^[a-zA-Z]*$')` | Validate the values of the 'details' map |
6264
{{< /table >}}
6365

6466
## CEL options, language features, and libraries

content/en/docs/tutorials/kubernetes-basics/update/update-intro.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h3>Update the version of the app</h3>
133133
and look for the <code>Image</code> field:</p>
134134
<p><code><b>kubectl describe pods</b></code></p>
135135
<p>To update the image of the application to version 2, use the <code>set image</code> subcommand, followed by the deployment name and the new image version:</p>
136-
<p><code><b>kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2</b></code></p>
136+
<p><code><b>kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=docker.io/jocatalin/kubernetes-bootcamp:v2</b></code></p>
137137
<p>The command notified the Deployment to use a different image for your app and initiated a rolling update. Check the status of the new Pods, and view the old one terminating with the <code>get pods</code> subcommand:</p>
138138
<p><code><b>kubectl get pods</b></code></p>
139139
</div>

content/en/examples/access/validating-admission-policy-audit-annotation.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ spec:
1111
operations: ["CREATE", "UPDATE"]
1212
resources: ["deployments"]
1313
validations:
14-
- key: "high-replica-count"
15-
expression: "object.spec.replicas > 50"
14+
- expression: "object.spec.replicas > 50"
1615
messageExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"
16+
auditAnnotations:
17+
- key: "high-replica-count"
18+
valueExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"

0 commit comments

Comments
 (0)