Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise “Kubernetes API Concepts” #25299

Merged
merged 4 commits into from
Nov 1, 2021

Conversation

sftim
Copy link
Contributor

@sftim sftim commented Nov 29, 2020

Revise Kubernetes API Concepts [preview]

ℹ️ This PR includes a Sass (CSS) change to indent definition lists. I think the impact is OK but I wanted to call it out.

Note Concept pages should live inside https://kubernetes.io/docs/concepts/. I think this page is in the right section (reference) and the thing to change is its title. That can happen in a separate PR that just covers the retitling.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 29, 2020
@sftim
Copy link
Contributor Author

sftim commented Nov 29, 2020

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 29, 2020
@k8s-ci-robot k8s-ci-robot added sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 29, 2020
@netlify
Copy link

netlify bot commented Nov 29, 2020

✔️ Deploy Preview for kubernetes-io-main-staging ready!

🔨 Explore the source changes: 3fc2bcb

🔍 Inspect the deploy log: https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/617561b5cc9a7c00083ee183

😎 Browse the preview: https://deploy-preview-25299--kubernetes-io-main-staging.netlify.app


Almost all object resource types support the standard HTTP verbs - GET, POST, PUT, PATCH, and DELETE. Kubernetes uses the term **list** to describe returning a collection of resources to distinguish from retrieving a single resource which is usually called a **get**.
Almost all object resource types support the standard HTTP verbs - GET, POST, PUT, PATCH, and DELETE. Kubernetes uses the term **List** to describe returning a collection of resources to distinguish from retrieving a single resource which is usually called a **Get**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do NOT change list to List or get to Get to cause more confusion, please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some reference for mapping verbs. Let's be careful when introducing this kind of spelling changes.
https://kubernetes.io/docs/reference/access-authn-authz/authorization/#determine-the-request-verb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd got confused between watch (the verb) and Watch (the noun). It's hard to document; I'm learning as I go to be honest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've revised my approach here (having learned the API enough to understand what this page is trying to say).

Copy link
Contributor

@tengqm tengqm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why we keep "beautifying" the doc without adding new meats or fixing defects. Such changes are difficult to diff and difficult to synchronize to localizations.


The verbs supported for each subresource will differ depending on the object - see the API documentation more information. It is not possible to access sub-resources across multiple resources - generally a new virtual resource type would be used if that becomes necessary.


## Efficient detection of changes

To enable clients to build a model of the current state of a cluster, all Kubernetes object resource types are required to support consistent lists and an incremental change notification feed called a **watch**. Every Kubernetes object has a `resourceVersion` field representing the version of that resource as stored in the underlying database. When retrieving a collection of resources (either namespace or cluster scoped), the response from the server will contain a `resourceVersion` value that can be used to initiate a watch against the server. The server will return all changes (creates, deletes, and updates) that occur after the supplied `resourceVersion`. This allows a client to fetch the current state and then watch for changes without missing any updates. If the client watch is disconnected they can restart a new watch from the last returned `resourceVersion`, or perform a new collection request and begin again. See [Resource Version Semantics](#resource-versions) for more detail.
To enable clients to build a model of the current state of a cluster, all Kubernetes object resource types are required to support consistent lists and an incremental change notification feed called a **watch**. Every Kubernetes object has a `resourceVersion` field representing the version of that resource as stored in the underlying database. When retrieving a collection of resources (either namespace or cluster scoped), the response from the server will contain a `resourceVersion` value that can be used to initiate a Watch against the server. The server will return all changes (creates, deletes, and updates) that occur after the supplied `resourceVersion`. This allows a client to fetch the current state and then watch for changes without missing any updates. If the client Watch is disconnected they can restart a new Watch from the last returned `resourceVersion`, or perform a new collection request and begin again. See [Resource Versions](#resource-versions) for more detail.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use code block formatting around the watch term instead of double asterisks or capitalization?
Can you cleanup the "will contain" to "contains" and "will return" to "returns"
Edit:
If a client is disconnected from a watch, they can restart a new watch from the last returned resourceVersion, or perform a new collection request to receive updates again. See Resource Versions for more detail.

Copy link
Contributor Author

@sftim sftim Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just realized that there are three meanings of “watch” in Kubernetes - it's a verb, watch (eg in RBAC); it's a noun, Watch, as well (representing a structure in an API response for example), and then the English word watch describes what you use those jargon terms to achieve.

I guess I need to work out which I think each of these is closest to and adjust styling to match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've omitted this change from the latest revision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now addressed, I think.


### Watch bookmarks

To mitigate the impact of short history window, we introduced a concept of `bookmark` watch event. It is a special kind of event to mark that all changes up to a given `resourceVersion` the client is requesting have already been sent. Object returned in that event is of the type requested by the request, but only `resourceVersion` field is set, e.g.:
To mitigate the impact of short history window, Kubernetes provides `bookmark` Watch events. A _bookmark_ is a special kind of event to mark that all changes up to a given `resourceVersion` the client is requesting have already been sent. The object returned in that event is of the type requested by the request, but only `resourceVersion` field is set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To mitigate the impact of a short history window,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible edit?
A bookmark is a special kind of event that marks all changes occurring before a client requests a given resourceVersion as sent by the API server. The object returned in the bookmark event is the same as the type set in the client request, but only the resourceVersion field is set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the bookmark watch event should be spelled as BOOKMARK. As shown in the example on line 139.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed, I think.


## Retrieving large results sets in chunks

{{< feature-state for_k8s_version="v1.9" state="beta" >}}

On large clusters, retrieving the collection of some resource types may result in very large responses that can impact the server and client. For instance, a cluster may have tens of thousands of pods, each of which is 1-2kb of encoded JSON. Retrieving all pods across all namespaces may result in a very large response (10-20MB) and consume a large amount of server resources. Starting in Kubernetes 1.9 the server supports the ability to break a single large collection request into many smaller chunks while preserving the consistency of the total request. Each chunk can be returned sequentially which reduces both the total size of the request and allows user-oriented clients to display results incrementally to improve responsiveness.
On large clusters, retrieving the collection of some resource types may result in very large responses that can impact the server and client. For instance, a cluster may have tens of thousands of pods, each of which is 1-2KiB of encoded JSON. Retrieving all pods across all namespaces may result in a very large response (10-20MB) and consume a large amount of server resources. The kube-apiserver supports the ability to break a single large collection request into many smaller chunks while preserving the consistency of the total request. Each chunk can be returned sequentially; this chunking reduces the size of each HTTP response message and also allows user-oriented clients to display results incrementally to improve responsiveness. Splitting retrieval over multiple HTTP responses means that if a client needs to retry a fetch, only the missing portion needs to be retransmitted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a "user-oriented" client -- a web browser?
Possible edit?
Each chunk is returned sequentially. Chunking reduces the size of an HTTP response which improves responsiveness in user-oriented clients. When a message is split over multiple HTTP responses and the client retries a fetch, only the missing portion of the message needs to be retransmitted by the API server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a "user-oriented" client -- a web browser?

Let's save dealing with that to another PR? This one is already quite involved. I'd rather make some improvements now than hold off making any until I fully understand the Kubernetes API.


Like a watch operation, a `continue` token will expire after a short amount of time (by default 5 minutes) and return a `410 Gone` if more results cannot be returned. In this case, the client will need to start from the beginning or omit the `limit` parameter.
Like a Watch operation, a `continue` token expires after a defined amount of time (5 minutes by default). If more results cannot be returned the API server returns a 410 (Gone) status. On receiving a 410 (Gone) response, the client needs to make a new request (possibly omitting the `limit` parameter, or using a larger `limit`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check about formatting response codes and capitalization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

410 is the right code and isn't capitalized. “Gone” is the text that 410 represents, both in English and as commonly returned as the status string by HTTP/1.x servers. However, this is not an actual HTTP/1.1 response; those look like:

HTTP/1.1 410 Gone
…

See https://tools.ietf.org/html/rfc7231#section-6.5.9 for an example of idiomatic representation in running text.

@liggitt
Copy link
Member

liggitt commented Aug 30, 2021

I likely won't have time until after 1.23 enhancement freeze (9/9)


Kubernetes generally leverages standard RESTful terminology to describe the API concepts:
You can view the [API reference](/docs/reference/kubernetes-api/) online,
or read on to learn about the API in general.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Line 27, You could end the sentence with "online".

Most Kubernetes API resource types are
[objects](/docs/concepts/overview/working-with-objects/kubernetes-objects/#kubernetes-objects):
they represent a concrete instance of a concept on the cluster, like a
pod or namespace. A smaller number of API resource types are *virtual* in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Are there two types of resource:

  • object
  • virtual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a question for WG API Expression, I think (I don't know the answer).


### API verbs

Almost all object resource types support the standard HTTP verbs - GET, POST, PUT, PATCH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about: "Almost all object resource types". Is this the same as:
A Kubernetes resource type that represents an object supports the HTTP verbs: GET, POST, ...

When are the Kubernetes verbs (lowercase) used (add this information)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When are the Kubernetes verbs (lowercase) used?

Could you clarify that question? I infer you're asking on behalf of the reader. What is it that they want to know?


For PUT requests, Kubernetes internally classifies these as either **create** or **update**
based on the state of the existing object. An **update** is different from a **patch**; the
HTTP verb for a **patch** is PATCH.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence seems redundant:
the HTTP verb for a patch is PATCH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

the HTTP verb for a patch is PATCH, not PUT.

?

## Resource URIs

All resource types are either scoped by the cluster (`/apis/GROUP/VERSION/*`) or to a
namespace (`/apis/GROUP/VERSION/namespaces/NAMESPACE/*`). A namespace-scoped resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could break up the sentence, "A namespace-scoped resource ..."
The API server (?) deletes the namespace-scoped resource when the namespace is deleted. Access to a resource type is controlled by authorization checks on the namespace scope.


* Cluster-scoped subresource: `GET /apis/GROUP/VERSION/RESOURCETYPE/NAME/SUBRESOURCE`
* Namespace-scoped subresource: `GET /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME/SUBRESOURCE`

The verbs supported for each subresource will differ depending on the object - see the API documentation for more information. It is not possible to access sub-resources across multiple resources - generally a new virtual resource type would be used if that becomes necessary.
The verbs supported for each subresource will differ depending on the object -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: replace "will differ"
Each sub-resource supports various verbs. For more information, see API Reference.


```console
There are dozens of collection types (such as `PodList`, `ServiceList`,
and `NodeList`) defined in the Kubernetes API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@kbhawkey
Copy link
Contributor

👋 @sftim .
I am in favor of moving this pull request forward. I am not sure whether there are remaining questions or comments (@liggitt @lavalamp )?
Can you check on the commits. I noticed that you included updates to the theme and generator sub-modules.
Thanks.

@sftim sftim force-pushed the 20201129_revise_api_reference branch 2 times, most recently from 759ae72 to 52c9ddd Compare September 27, 2021 09:45
@sftim
Copy link
Contributor Author

sftim commented Sep 27, 2021

I fixed the submodules, thanks for spotting that.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 22, 2021
sftim added 4 commits October 24, 2021 14:31
Table is now GA
Use padding to make the lists stand out from surrounding text.
@sftim sftim force-pushed the 20201129_revise_api_reference branch from 52c9ddd to 3fc2bcb Compare October 24, 2021 13:37
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 24, 2021
@celestehorgan
Copy link
Contributor

We've waited on @liggitt and @lavalamp for final comment for approximately one month now; and as such, by lazy consensus I'm going to assume they have no more comments.

I'm gonna merge it! :D

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 1, 2021
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 9f56bdf4399b41f7e0ea5c312bf67ac9811a45e9

@k8s-ci-robot k8s-ci-robot merged commit 1a8c641 into kubernetes:main Nov 1, 2021
@tengqm
Copy link
Contributor

tengqm commented Nov 2, 2021

/refactor

@tengqm
Copy link
Contributor

tengqm commented Nov 2, 2021

/label refactor

@k8s-ci-robot k8s-ci-robot added the refactor Indicates a PR with large refactoring changes e.g. removes files or moves content label Nov 2, 2021
@sftim sftim deleted the 20201129_revise_api_reference branch December 8, 2021 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language lgtm "Looks good to me", indicates that a PR is ready to be merged. refactor Indicates a PR with large refactoring changes e.g. removes files or moves content sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. wg/api-expression Categorizes an issue or PR as relevant to WG API Expression.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants