You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/reference/using-api/api-concepts.md
+61-5Lines changed: 61 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,7 @@ For PUT requests, Kubernetes internally classifies these as either **create** or
76
76
based on the state of the existing object. An **update** is different from a **patch**; the
77
77
HTTP verb for a **patch** is PATCH.
78
78
79
+
79
80
## Resource URIs
80
81
81
82
All resource types are either scoped by the cluster (`/apis/GROUP/VERSION/*`) or to a
@@ -162,7 +163,7 @@ For example:
162
163
```
163
164
164
165
2. Starting from resource version 10245, receive notifications of any API operations
165
-
(such as **create**, **delete**, **apply** or **update**) that affect Pods in the
166
+
(such as **create**, **delete**, **patch** or **update**) that affect Pods in the
166
167
_test_ namespace. Each change notification is a JSON document. The HTTP response body
167
168
(served as `application/json`) consists a series of JSON documents.
168
169
@@ -750,7 +751,7 @@ Once the last finalizer is removed, the resource is actually removed from etcd.
750
751
751
752
## Single resource API
752
753
753
-
The Kubernetes API verbs **get**, **create**, **apply**, **update**, **patch**,
754
+
The Kubernetes API verbs **get**, **create**, **update**, **patch**,
754
755
**delete** and **proxy** support single resources only.
755
756
These verbs with single resource support have no support for submitting multiple
756
757
resources together in an ordered or unordered list or transaction.
@@ -937,15 +938,70 @@ rules:
937
938
938
939
See [Authorization Overview](/docs/reference/access-authn-authz/authorization/).
939
940
940
-
## Server Side Apply
941
+
## Updates to existing resources {#patch-and-apply}
942
+
943
+
You can overwrite (**update**) an existing resource - for example, a ConfigMap -
944
+
using an HTTP PUT. For a PUT request, it is the client's responsibility to specify
945
+
the `resourceVersion` (taking this from the object being updated). Kubernetes uses
946
+
that `resourceVersion` information so that the API server can detect lost updates
947
+
and reject requests made by a client that is out of date with the cluster.
948
+
In the event that the resource has changed (the `resourceVersion` the client
949
+
provided is stale), the API server returns a `409 Conflict` error response.
950
+
951
+
Instead of sending a PUT request, the client can send an instruction to the API
952
+
server to **patch** an existing resource. A **patch** is typically appropriate
953
+
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
954
+
making their request conditional on the existing `resourceVersion` (either HTTP PUT or HTTP PATCH),
955
+
and then handle any retries that are needed in case there is a conflict.
956
+
957
+
The Kubernetes API supports four different PATCH operations, determined by their
958
+
corresponding HTTP `Content-Type` header:
959
+
960
+
`application/apply-patch+yaml`
961
+
: Server Side Apply YAML (a Kubernetes-specific extension, based on YAML).
962
+
All JSON documents are valid YAML, so you can also submit JSON using this
963
+
media type. See [Server Side Apply serialization](/docs/reference/using-api/server-side-apply/#serialization)
964
+
for more details.
965
+
To Kubernetes, this is a **create** operation if the object does not exist,
966
+
or a **patch** operation if the object already exists.
967
+
968
+
`application/json-patch+json`
969
+
: JSON Patch, as defined in [RFC6902](https://tools.ietf.org/html/rfc6902).
970
+
A JSON patch is a sequence of operations that are executed on the resource;
971
+
for example `{"op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ]}`.
972
+
To Kubernetes, this is a **patch** operation.
973
+
974
+
A **patch** using `application/json-patch+json` can include conditions to
975
+
validate consistency, allowing the operation to fail if those conditions
976
+
are not met (for example, to avoid a lost update).
977
+
978
+
`application/merge-patch+json`
979
+
: JSON Merge Patch, as defined in [RFC7386](https://tools.ietf.org/html/rfc7386).
980
+
A JSON Merge Patch is essentially a partial representation of the resource.
981
+
The submitted JSON is combined with the current resource to create a new one,
982
+
then the new one is saved.
983
+
To Kubernetes, this is a **patch** operation.
984
+
985
+
`application/strategic-merge-patch+json`
986
+
: Strategic Merge Patch (a Kubernetes-specific extension based on JSON).
987
+
Strategic Merge Patch is a custom implementation of JSON Merge Patch.
988
+
To Kubernetes, this is a **patch** operation.
989
+
990
+
{{< note >}}
991
+
The Kubernetes _server side apply_ mechanism has superseded Strategic Merge
992
+
Patch.
993
+
{{< /note >}}
941
994
942
995
Kubernetes' [Server Side Apply](/docs/reference/using-api/server-side-apply/)
943
996
feature allows the control plane to track managed fields for newly created objects.
944
997
Server Side Apply provides a clear pattern for managing field conflicts,
945
-
offers server-side `Apply` and `Update` operations, and replaces the
998
+
offers server-side **apply** and **update** operations, and replaces the
946
999
client-side functionality of `kubectl apply`.
947
1000
948
-
The API verb for Server-Side Apply is **apply**.
1001
+
For Server-Side Apply, Kubernetes treats the request as a **create** if the object
1002
+
does not yet exist, and a **patch** otherwise. For other requests that use PATCH
1003
+
at the HTTP level, the logical Kubernetes operation is always **patch**.
1004
+
949
1005
See [Server Side Apply](/docs/reference/using-api/server-side-apply/) for more details.
0 commit comments