docs: uses mostly kubectl to demonstrate (#11699)

Simplify to run `kubectl` to obtain the desired values from resources

Changes: access-cluster-api.md
This commit is contained in:
Raul Gonzales 2019-01-02 19:19:21 +00:00 committed by Kubernetes Prow Robot
parent bcaef52219
commit 578b006360
1 changed files with 7 additions and 3 deletions

View File

@ -81,9 +81,13 @@ It is possible to avoid using kubectl proxy by passing an authentication token
directly to the API server, like this: directly to the API server, like this:
``` shell ``` shell
$ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ") # Check all possible clusters, as you .KUBECONFIG may have multiple contexts
$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t') $ kubectl config view -o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
$ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure # Point to the API server refering the cluster name
$ APISERVER=$(kubectl config view -o jsonpath='{.clusters[?(@.name=="$CLUSTER_NAME")].cluster.server}')
# Gets the token value
$ TOKEN=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 -d)
$ curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
{ {
"kind": "APIVersions", "kind": "APIVersions",
"versions": [ "versions": [