Skip to content

Commit a045f62

Browse files
authored
Merge pull request #40203 from Zhuzhenghao/socks5-proxy-access-api
[zh] resync page socks5-proxy-access-api
2 parents bf73a2d + 915792f commit a045f62

File tree

1 file changed

+57
-48
lines changed

1 file changed

+57
-48
lines changed

content/zh-cn/docs/tasks/extend-kubernetes/socks5-proxy-access-api.md

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ graph LR;
6767
client([client])-- local <br> traffic .-> local_ssh[Local SSH <br> SOCKS5 proxy];
6868
end
6969
local_ssh[SSH <br>SOCKS5 <br> proxy]-- SSH Tunnel --\>sshd
70-
70+
7171
subgraph remote[Remote server]
7272
sshd[SSH <br> server]-- local traffic --\>service1;
7373
end
@@ -110,86 +110,62 @@ Figure 1. SOCKS5 tutorial components
110110
<!--
111111
## Using ssh to create a SOCKS5 proxy
112112
113-
This command starts a SOCKS5 proxy between your client machine and the remote server.
114-
The SOCKS5 proxy lets you connect to your cluster's API server.
113+
The following command starts a SOCKS5 proxy between your client machine and the remote SOCKS server:
115114
-->
116115
## 使用 SSH 创建 SOCKS5 代理
117116

118-
此命令在你的客户端计算机和远程服务器之间启动一个 SOCKS5 代理。
119-
SOCKS5 代理允许你连接到集群的 API 服务器。
117+
下面的命令在你的客户端计算机和远程 SOCKS 服务器之间启动一个 SOCKS5 代理:
120118

121119
```shell
122120
# 运行此命令后,SSH 隧道继续在前台运行
123121
ssh -D 1080 -q -N [email protected]
124122
```
125123

126124
<!--
125+
The SOCKS5 proxy lets you connect to your cluster's API server based on the following configuration:
127126
* `-D 1080`: opens a SOCKS proxy on local port :1080.
128127
* `-q`: quiet mode. Causes most warning and diagnostic messages to be suppressed.
129128
* `-N`: Do not execute a remote command. Useful for just forwarding ports.
130-
* `[email protected]`: the remote SSH server where the Kubernetes cluster is running.
129+
* `[email protected]`: the remote SSH server behind which the Kubernetes cluster
130+
is running (eg: a bastion host).
131131
-->
132132
* `-D 1080`: 在本地端口 1080 上打开一个 SOCKS 代理。
133133
* `-q`: 静音模式。导致大多数警告和诊断消息被抑制。
134134
* `-N`: 不执行远程命令。仅用于转发端口。
135-
* `[email protected]`:运行 Kubernetes 集群的远程 SSH 服务器。
135+
* `[email protected]`:运行 Kubernetes 集群的远程 SSH 服务器(例如:堡垒主机)
136136

137137
<!--
138138
## Client configuration
139139
140-
To explore the Kubernetes API you'll first need to instruct your clients to send their queries through
141-
the SOCKS5 proxy we created earlier.
142-
143-
For command-line tools, set the `https_proxy` environment variable and pass it to commands that you run.
140+
To access the Kubernetes API server through the proxy you must instruct `kubectl` to send queries through
141+
the `SOCKS` proxy we created earlier. Do this by either setting the appropriate environment variable,
142+
or via the `proxy-url` attribute in the kubeconfig file. Using an environment variable:
144143
-->
145144
## 客户端配置
146145

147-
要探索 Kubernetes API,你首先需要指示你的客户端通过我们之前创建的 SOCKS5
148-
代理发送他们的查询。
149-
对于命令行工具,设置 `https_proxy` 环境变量并将其传递给你运行的命令。
146+
要通过代理访问 Kubernetes API 服务器,你必须指示 `kubectl` 通过我们之前创建的 SOCKS5
147+
代理发送查询。
148+
这可以通过设置适当的环境变量或通过 kubeconfig 文件中的 `proxy-url` 属性来实现。
149+
使用环境变量:
150150

151151
```shell
152-
export https_proxy=socks5h://localhost:1080
152+
export HTTPS_PROXY=socks5://localhost:1080
153153
```
154154

155155
<!--
156-
When you set the `https_proxy` variable, tools such as `curl` route HTTPS traffic through the proxy
157-
you configured. For this to work, the tool must support SOCKS5 proxying.
158-
-->
159-
当你设置 `https_proxy` 变量时,`curl` 等工具会通过你配置的代理路由 HTTPS 流量。
160-
为此,该工具必须支持 SOCKS5 代理。
161-
162-
{{< note >}}
163-
<!--
164-
In the URL https://localhost:6443/api, `localhost` does not refer to your local client computer.
165-
Instead, it refers to the endpoint on the remote server known as `localhost`.
166-
The `curl` tool sends the hostname from the HTTPS URL over SOCKS, and the remote server
167-
resolves that locally (to an address that belongs to its loopback interface).
156+
To always use this setting on a specific `kubectl` context, specify the `proxy-url` attribute in the relevant
157+
`cluster` entry within the `~/.kube/config` file. For example:
168158
-->
169-
在 URL https://localhost:6443/api 中,`localhost` 不是指你的本地客户端计算机。
170-
它指的是远程服务器上称为 `localhost` 的端点。
171-
`curl` 工具通过 SOCKS 从 HTTPS URL 发送主机名,远程服务器在本地解析(到属于其环回接口的地址)。
172-
{{< /note >}}
173-
174-
```shell
175-
curl -k -v https://localhost:6443/api
176-
```
177-
178-
<!--
179-
To use the official Kubernetes client `kubectl` with a proxy, set the `proxy-url` element
180-
for the relevant `cluster` entry within your `~/.kube/config` file. For example:
181-
-->
182-
要将 Kubernetes 官方客户端 `kubectl` 与代理一起使用,
183-
请在 `~/.kube/config` 文件中为相关的
184-
`cluster` 条目设置 `proxy-url` 元素。例如:
159+
要始终在特定的 `kubectl` 上下文中使用此设置,请在 `~/.kube/config` 文件中为相关的
160+
`cluster` 条目设置 `proxy-url` 属性。例如:
185161

186162
```yaml
187163
apiVersion: v1
188164
clusters:
189165
- cluster:
190166
certificate-authority-data: LRMEMMW2 # 简化以便阅读
191167
# “Kubernetes API”服务器,换言之,kubernetes-remote-server.example 的 IP 地址
192-
server: https://<API_SERVER_IP_ADRESS>:6443
168+
server: https://<API_SERVER_IP_ADRESS>:6443
193169
# 上图中的“SSH SOCKS5代理”(内置 DNS 解析)
194170
proxy-url: socks5://localhost:1080
195171
name: default
@@ -209,10 +185,11 @@ users:
209185
```
210186
211187
<!--
212-
If the tunnel is operating and you use `kubectl` with a context that uses this cluster, you can interact with your cluster through that proxy. For example:
188+
Once you have created the tunnel via the ssh command mentioned earlier, and defined either the environment variable or
189+
the `proxy-url` attribute, you can interact with your cluster through that proxy. For example:
213190
-->
214-
如果隧道能够正常工作,并且你调用 `kubectl` 时使用此集群的上下文
215-
则可以通过该代理与你的集群交互。例如:
191+
一旦你通过前面提到的 SSH 命令创建了隧道,并定义了环境变量或 `proxy-url` 属性
192+
你就可以通过该代理与你的集群交互。例如:
216193

217194
```shell
218195
kubectl get pods
@@ -223,6 +200,39 @@ NAMESPACE NAME READY STATUS RESTA
223200
kube-system coredns-85cb69466-klwq8 1/1 Running 0 5m46s
224201
```
225202

203+
{{< note >}}
204+
<!--
205+
- Before `kubectl` 1.24, most `kubectl` commands worked when using a socks proxy, except `kubectl exec`.
206+
- `kubectl` supports both `HTTPS_PROXY` and `https_proxy` environment variables. These are used by other
207+
programs that support SOCKS, such as `curl`. Therefore in some cases it
208+
will be better to define the environment variable on the command line:
209+
-->
210+
- 在 `kubectl` 1.24 之前,大多数 `kubectl` 命令在使用 socks 代理时都有效,除了 `kubectl exec`。
211+
- `kubectl` 支持读取 `HTTPS_PROXY` 和 `https_proxy` 环境变量。 这些被其他支持 SOCKS 的程序使用,例如 `curl`。
212+
因此在某些情况下,在命令行上定义环境变量会更好:
213+
```shell
214+
HTTPS_PROXY=socks5://localhost:1080 kubectl get pods
215+
```
216+
<!--
217+
- When using `proxy-url`, the proxy is used only for the relevant `kubectl` context,
218+
whereas the environment variable will affect all contexts.
219+
-->
220+
- 使用 `proxy-url` 时,代理仅用于相关的 `kubectl` 上下文,而环境变量将影响所有上下文。
221+
<!--
222+
- The k8s API server hostname can be further protected from DNS leakage by using the `socks5h` protocol name
223+
instead of the more commonly known `socks5` protocol shown above. In this case, `kubectl` will ask the proxy server
224+
(such as an ssh bastion) to resolve the k8s API server domain name, instead of resolving it on the system running
225+
`kubectl`. Note also that with `socks5h`, a k8s API server URL like `https://localhost:6443/api` does not refer
226+
to your local client computer. Instead, it refers to `localhost` as known on the proxy server (eg the ssh bastion).
227+
-->
228+
- 通过使用 `socks5h` 协议名称而不是上面显示的更广为人知的 `socks5` 协议,
229+
可以进一步保护 k8s API 服务器主机名免受 DNS 泄漏影响。
230+
这种情况下,`kubectl` 将要求代理服务器(例如 SSH 堡垒机)解析 k8s API 服务器域名,
231+
而不是在运行 `kubectl` 的系统上进行解析。
232+
另外还要注意,使用 `socks5h` 时,像 `https://localhost:6443/api` 这样的 k8s API 服务器 URL 并不是指你的本地客户端计算机。
233+
相反,它指向的是代理服务器(例如 SSH 堡垒机)上已知的 `localhost`。
234+
{{</ note >}}
235+
226236
<!--
227237
## Clean up
228238

@@ -244,4 +254,3 @@ Type `unset https_proxy` in a terminal to stop forwarding http traffic through t
244254
## 进一步阅读
245255

246256
* [OpenSSH 远程登录客户端](https://man.openbsd.org/ssh)
247-

0 commit comments

Comments
 (0)