Skip to content

Commit 7a7e7f3

Browse files
authored
Merge pull request #42555 from windsonsea/mixedy
[zh] sync mixed-version-proxy.md
2 parents 8d00ac9 + 04de2a4 commit 7a7e7f3

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
title: 混合版本代理
3+
content_type: concept
4+
weight: 220
5+
---
6+
<!--
7+
reviewers:
8+
- jpbetz
9+
title: Mixed Version Proxy
10+
content_type: concept
11+
weight: 220
12+
-->
13+
14+
<!-- overview -->
15+
16+
{{< feature-state state="alpha" for_k8s_version="v1.28" >}}
17+
18+
<!--
19+
Kubernetes {{< skew currentVersion >}} includes an alpha feature that lets an
20+
{{< glossary_tooltip text="API Server" term_id="kube-apiserver" >}}
21+
proxy a resource requests to other _peer_ API servers. This is useful when there are multiple
22+
API servers running different versions of Kubernetes in one cluster
23+
(for example, during a long-lived rollout to a new release of Kubernetes).
24+
-->
25+
Kubernetes {{<skew currentVersion>}} 包含了一个 Alpha 特性,可以让
26+
{{<glossary_tooltip text="API 服务器" term_id="kube-apiserver">}}代理指向其他**对等**
27+
API 服务器的资源请求。当一个集群中运行着多个 API 服务器,且各服务器的 Kubernetes 版本不同时
28+
(例如在上线 Kubernetes 新版本的时间跨度较长时),这一特性非常有用。
29+
30+
<!--
31+
This enables cluster administrators to configure highly available clusters that can be upgraded
32+
more safely, by directing resource requests (made during the upgrade) to the correct kube-apiserver.
33+
That proxying prevents users from seeing unexpected 404 Not Found errors that stem
34+
from the upgrade process.
35+
36+
This mechanism is called the _Mixed Version Proxy_.
37+
-->
38+
此特性通过将(升级过程中所发起的)资源请求引导到正确的 kube-apiserver
39+
使得集群管理员能够配置高可用的、升级动作更安全的集群。
40+
该代理机制可以防止用户在升级过程中看到意外的 404 Not Found 错误。
41+
42+
这个机制称为 **Mixed Version Proxy(混合版本代理)**
43+
44+
<!--
45+
## Enabling the Mixed Version Proxy
46+
47+
Ensure that `UnknownVersionInteroperabilityProxy` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
48+
is enabled when you start the {{< glossary_tooltip text="API Server" term_id="kube-apiserver" >}}:
49+
-->
50+
## 启用混合版本代理 {#enabling-the-mixed-version-proxy}
51+
52+
当你启动 {{<glossary_tooltip text="API 服务器" term_id="kube-apiserver">}}时,
53+
确保启用了 `UnknownVersionInteroperabilityProxy`
54+
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
55+
56+
<!--
57+
```shell
58+
kube-apiserver \
59+
--feature-gates=UnknownVersionInteroperabilityProxy=true \
60+
# required command line arguments for this feature
61+
--peer-ca-file=<path to kube-apiserver CA cert>
62+
--proxy-client-cert-file=<path to aggregator proxy cert>,
63+
--proxy-client-key-file=<path to aggregator proxy key>,
64+
--requestheader-client-ca-file=<path to aggregator CA cert>,
65+
# requestheader-allowed-names can be set to blank to allow any Common Name
66+
--requestheader-allowed-names=<valid Common Names to verify proxy client cert against>,
67+
68+
# optional flags for this feature
69+
--peer-advertise-ip=`IP of this kube-apiserver that should be used by peers to proxy requests`
70+
--peer-advertise-port=`port of this kube-apiserver that should be used by peers to proxy requests`
71+
72+
# …and other flags as usual
73+
```
74+
-->
75+
```shell
76+
kube-apiserver \
77+
--feature-gates=UnknownVersionInteroperabilityProxy=true \
78+
# 需要为此特性添加的命令行参数
79+
--peer-ca-file=<指向 kube-apiserver CA 证书的路径>
80+
--proxy-client-cert-file=<指向聚合器代理证书的路径>,
81+
--proxy-client-key-file=<指向聚合器代理密钥的路径>,
82+
--requestheader-client-ca-file=<指向聚合器 CA 证书的路径>,
83+
# requestheader-allowed-names 可设置为空以允许所有 Common Name
84+
--requestheader-allowed-names=<验证代理客户端证书的合法 Common Name>,
85+
86+
# 此特性的可选标志
87+
--peer-advertise-ip=`应由对等方用于代理请求的 kube-apiserver IP`
88+
--peer-advertise-port=`应由对等方用于代理请求的 kube-apiserver 端口`
89+
90+
# ... 和其他常规标志
91+
```
92+
93+
<!--
94+
### Proxy transport and authentication between API servers {#transport-and-authn}
95+
96+
* The source kube-apiserver reuses the
97+
[existing APIserver client authentication flags](/docs/tasks/extend-kubernetes/configure-aggregation-layer/#kubernetes-apiserver-client-authentication)
98+
`--proxy-client-cert-file` and `--proxy-client-key-file` to present its identity that
99+
will be verified by its peer (the destination kube-apiserver). The destination API server
100+
verifies that peer connection based on the configuration you specify using the
101+
`--requestheader-client-ca-file` command line argument.
102+
103+
* To authenticate the destination server's serving certs, you must configure a certificate
104+
authority bundle by specifying the `--peer-ca-file` command line argument to the **source** API server.
105+
-->
106+
### API 服务器之间的代理传输和身份验证 {#transport-and-authn}
107+
108+
* 源 kube-apiserver
109+
重用[现有的 API 服务器客户端身份验证标志](/zh-cn/docs/tasks/extend-kubernetes/configure-aggregation-layer/#kubernetes-apiserver-client-authentication)
110+
`--proxy-client-cert-file``--proxy-client-key-file` 来表明其身份,供对等(目标 kube-apiserver)验证。
111+
目标 API 服务器根据你使用 `--requestheader-client-ca-file` 命令行参数指定的配置来验证对等连接。
112+
113+
* 要对目标服务器所用的证书进行身份验证,必须通过指定 `--peer-ca-file` 命令行参数来为****
114+
API 服务器配置一个证书机构包。
115+
116+
<!--
117+
### Configuration for peer API server connectivity
118+
119+
To set the network location of a kube-apiserver that peers will use to proxy requests, use the
120+
`--peer-advertise-ip` and `--peer-advertise-port` command line arguments to kube-apiserver or specify
121+
these fields in the API server configuration file.
122+
If these flags are unspecified, peers will use the value from either `--advertise-address` or
123+
`--bind-address` command line argument to the kube-apiserver. If those too, are unset, the host's default interface is used.
124+
-->
125+
### 对等 API 服务器连接的配置 {#config-for-peer-apiserver-connectivity}
126+
127+
要设置 kube-apiserver 的网络位置以供对等方来代理请求,
128+
使用为 kube-apiserver 设置的 `--peer-advertise-ip``--peer-advertise-port` 命令行参数,
129+
或在 API 服务器配置文件中指定这些字段。如果未指定这些参数,对等方将使用 `--advertise-address`
130+
`--bind-address` 命令行参数的值。如果这些也未设置,则使用主机的默认接口。
131+
132+
<!--
133+
## Mixed version proxying
134+
135+
When you enable mixed version proxying, the [aggregation layer](/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/)
136+
loads a special filter that does the following:
137+
-->
138+
## 混合版本代理 {#mixed-version-proxying}
139+
140+
启用混合版本代理时,
141+
[聚合层](/zh-cn/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/)会加载一个特殊的过滤器,
142+
完成以下操作:
143+
144+
<!--
145+
* When a resource request reaches an API server that cannot serve that API
146+
(either because it is at a version pre-dating the introduction of the API or the API is turned off on the API server)
147+
the API server attempts to send the request to a peer API server that can serve the requested API.
148+
It does so by identifying API groups / versions / resources that the local server doesn't recognise,
149+
and tries to proxy those requests to a peer API server that is capable of handling the request.
150+
* If the peer API server fails to respond, the _source_ API server responds with 503 ("Service Unavailable") error.
151+
-->
152+
* 当资源请求到达无法提供该 API 的 API 服务器时
153+
(可能的原因是服务器早于该 API 的正式引入日期或该 API 在 API 服务器上被关闭),
154+
API 服务器会尝试将请求发送到能够提供所请求 API 的对等 API 服务器。
155+
API 服务器通过发现本地服务器无法识别的 API 组/版本/资源来实现这一点,
156+
并尝试将这些请求代理到能够处理这些请求的对等 API 服务器。
157+
* 如果对等 API 服务器无法响应,则**** API 服务器将以 503("Service Unavailable")错误进行响应。
158+
159+
<!--
160+
### How it works under the hood
161+
162+
When an API Server receives a resource request, it first checks which API servers can
163+
serve the requested resource. This check happens using the internal `StorageVersion` API.
164+
165+
* If the resource is known to the API server that received the request
166+
(for example, `GET /api/v1/pods/some-pod`), the request is handled locally.
167+
-->
168+
### 内部工作原理 {#how-it-works-under-the-hood}
169+
170+
当 API 服务器收到一个资源请求时,它首先检查哪些 API 服务器可以提供所请求的资源。
171+
这个检查是使用内部的 `StorageVersion` API 进行的。
172+
173+
* 如果资源被收到请求(例如 `GET /api/v1/pods/some-pod`)的 API 服务器所了解,则请求会在本地处理。
174+
175+
<!--
176+
* If there is no internal `StorageVersion` object found for the requested resource
177+
(for example, `GET /my-api/v1/my-resource`) and the configured APIService specifies proxying
178+
to an extension API server, that proxying happens following the usual
179+
[flow](/docs/tasks/extend-kubernetes/configure-aggregation-layer/) for extension APIs.
180+
-->
181+
* 如果没有找到适合所请求资源(例如 `GET /my-api/v1/my-resource`)的内部 `StorageVersion` 对象,
182+
并且所配置的 APIService 设置了指向扩展 API 服务器的代理,那么代理操作将按照扩展 API
183+
的常规[流程](/zh-cn/docs/tasks/extend-kubernetes/configure-aggregation-layer/)进行。
184+
185+
<!--
186+
* If a valid internal `StorageVersion` object is found for the requested resource
187+
(for example, `GET /batch/v1/jobs`) and the API server trying to handle the request
188+
(the _handling API server_) has the `batch` API disabled, then the _handling API server_
189+
fetches the peer API servers that do serve the relevant API group / version / resource
190+
(`api/v1/batch` in this case) using the information in the fetched `StorageVersion` object.
191+
The _handling API server_ then proxies the request to one of the matching peer kube-apiservers
192+
that are aware of the requested resource.
193+
* If there is no peer known for that API group / version / resource, the handling API server
194+
passes the request to its own handler chain which should eventually return a 404 ("Not Found") response.
195+
* If the handling API server has identified and selected a peer API server, but that peer fails
196+
to respond (for reasons such as network connectivity issues, or a data race between the request
197+
being received and a controller registering the peer's info into the control plane), then the handling
198+
API server responds with a 503 (“Service Unavailable”) error.
199+
-->
200+
* 如果找到了对应所请求资源(例如 `GET /batch/v1/jobs`)的合法的内部 `StorageVersion` 对象,
201+
并且正在处理请求的 API 服务器(**处理中的 API 服务器**)禁用了 `batch` API,
202+
**正处理的 API 服务器** 使用已获取的 `StorageVersion` 对象中的信息,
203+
获取提供相关 API 组/版本/资源(在此情况下为 `api/v1/batch`)的对等 API 服务器。
204+
**处理中的 API 服务器**随后将请求代理到能够理解所请求资源且匹配的对等 kube-apiserver 之一。
205+
* 如果没有对等方了解所给的 API 组/版本/资源,则处理请求的 API 服务器将请求传递给自己的处理程序链,
206+
最终应返回 404("Not Found")响应。
207+
* 如果处理请求的 API 服务器已经识别并选择了一个对等 API 服务器,但该对等方无法响应
208+
(原因可能是网络连接问题或正接收的请求与向控制平面注册对等信息的控制器之间存在数据竞争等),
209+
则处理请求的 API 服务器会以 503("Service Unavailable")错误进行响应。

0 commit comments

Comments
 (0)