Skip to content

Commit 1a0a6eb

Browse files
authored
[zh] Update access-cluster.md (#32178)
* [zh] Update access-cluster.md [zh] Update access-cluster.md * Update access-cluster.md * Update access-cluster.md
1 parent 74c9374 commit 1a0a6eb

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

content/zh/docs/tasks/access-application-cluster/access-cluster.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
title: 访问集群
33
weight: 20
44
content_type: concept
@@ -50,10 +50,10 @@ kubectl config view
5050

5151
<!--
5252
Many of the [examples](/docs/user-guide/kubectl-cheatsheet) provide an introduction to using
53-
kubectl and complete documentation is found in the [kubectl manual](/docs/user-guide/kubectl-overview).
53+
`kubectl` and complete documentation is found in the [kubectl reference](/docs/reference/kubectl/).
5454
-->
5555
有许多 [例子](/zh/docs/reference/kubectl/cheatsheet/) 介绍了如何使用 kubectl,
56-
可以在 [kubectl手册](/zh/docs/reference/kubectl/overview/) 中找到更完整的文档。
56+
可以在 [kubectl 参考](/zh/docs/reference/kubectl/overview/) 中找到更完整的文档。
5757

5858
<!--
5959
## Directly accessing the REST API
@@ -139,18 +139,47 @@ curl http://localhost:8080/api/
139139
<!--
140140
### Without kubectl proxy
141141
142-
In Kubernetes version 1.3 or later, `kubectl config view` no longer displays the token. Use `kubectl describe secret...` to get the token for the default service account, like this:
142+
In Kubernetes version 1.3 or later, `kubectl config view` no longer displays the token. Use `kubectl apply` and `kubectl describe secret...` to create a token for the default service account with grep/cut:
143+
144+
First, create the Secret, requesting a token for the default ServiceAccount:
145+
143146
-->
147+
144148
### 不使用 kubectl proxy
145149

146150
在 Kubernetes 1.3 或更高版本中,`kubectl config view` 不再显示 token。
147-
使用 `kubectl describe secret ...` 来获取默认服务帐户的 token,如下所示:
148-
151+
使用 `kubectl apply``kubectl describe secret ...` 及 grep 和剪切操作来为 default 服务帐户创建令牌,如下所示:
149152
`grep/cut` 方法实现:
153+
首先,创建 Secret,请求默认 ServiceAccount 的令牌:
154+
```shell
155+
kubectl apply -f - <<EOF
156+
apiVersion: v1
157+
kind: Secret
158+
metadata:
159+
name: default-token
160+
annotations:
161+
kubernetes.io/service-account.name: default
162+
type: kubernetes.io/service-account-token
163+
EOF
164+
```
165+
166+
<!--
167+
Next, wait for the token controller to populate the Secret with a token:
168+
169+
Capture and use the generated token:
170+
-->
171+
接下来,等待令牌控制器使用令牌填充 Secret:
172+
```shell
173+
while ! kubectl describe secret default-token | grep -E '^token' >/dev/null; do
174+
echo "waiting for token..." >&2
175+
sleep 1
176+
done
177+
```
150178

179+
捕获并使用生成的令牌:
151180
```shell
152181
APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
153-
TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d ' ')
182+
TOKEN=$(kubectl describe secret default-token | grep -E '^token' | cut -f2 -d':' | tr -d ' ')
154183
curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
155184
```
156185
```json
@@ -172,7 +201,7 @@ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
172201

173202
```shell
174203
APISERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
175-
TOKEN=$(kubectl get secret $(kubectl get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
204+
TOKEN=$(kubectl get secret default-token -o jsonpath='{.data.token}' | base64 --decode )
176205
curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
177206
```
178207

0 commit comments

Comments
 (0)