zh-trans: Add jsonpath approach for apiserver query (#12351)
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
ca4f474235
commit
d83bcfe033
@@ -133,6 +133,8 @@ In Kubernetes version 1.3 or later, `kubectl config view` no longer displays the
|
|||||||
|
|
||||||
在 Kubernetes 1.3 或更高版本中,`kubectl config view` 不再显示 token。使用 `kubectl describe secret ...` 来获取默认服务帐户的 token,如下所示:
|
在 Kubernetes 1.3 或更高版本中,`kubectl config view` 不再显示 token。使用 `kubectl describe secret ...` 来获取默认服务帐户的 token,如下所示:
|
||||||
|
|
||||||
|
`grep/cut` 方法实现:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
|
$ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
|
||||||
$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
|
$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
|
||||||
@@ -151,6 +153,26 @@ $ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`jsonpath` 方法实现:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ APISERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
|
||||||
|
$ TOKEN=$(kubectl get secret $(kubectl get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
|
||||||
|
$ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
|
||||||
|
{
|
||||||
|
"kind": "APIVersions",
|
||||||
|
"versions": [
|
||||||
|
"v1"
|
||||||
|
],
|
||||||
|
"serverAddressByClientCIDRs": [
|
||||||
|
{
|
||||||
|
"clientCIDR": "0.0.0.0/0",
|
||||||
|
"serverAddress": "10.0.1.149:443"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
The above examples use the `--insecure` flag. This leaves it subject to MITM
|
The above examples use the `--insecure` flag. This leaves it subject to MITM
|
||||||
attacks. When kubectl accesses the cluster it uses a stored root certificate
|
attacks. When kubectl accesses the cluster it uses a stored root certificate
|
||||||
|
|||||||
Reference in New Issue
Block a user