Skip to content

Commit

Permalink
zh-trans: Add jsonpath approach for apiserver query (kubernetes#12351)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenrui333 authored and k8s-ci-robot committed Jan 28, 2019
1 parent ca4f474 commit d83bcfe
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions content/zh/docs/tasks/access-application-cluster/access-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,如下所示:

`grep/cut` 方法实现:

```shell
$ 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')
Expand All @@ -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
attacks. When kubectl accesses the cluster it uses a stored root certificate
Expand Down

0 comments on commit d83bcfe

Please sign in to comment.