# 使用kubectl proxy代理kubectl proxy --port=8080 &curl http://localhost:8080/api/ # 使用token# Check all possible clusters, as your .KUBECONFIG may have multiple contexts:kubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}' # Select name of cluster you want to interact with from above output:export CLUSTER_NAME="some_server_name" # Point to the API server referring the cluster nameAPISERVER=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$CLUSTER_NAME\")].cluster.server}") # Create a secret to hold a token for the default service accountkubectl apply -f - <<EOFapiVersion: v1kind: Secretmetadata: name: default-token annotations: kubernetes.io/service-account.name: defaulttype: kubernetes.io/service-account-tokenEOF # Wait for the token controller to populate the secret with a token:while ! kubectl describe secret default-token | grep -E '^token' >/dev/null; do echo "waiting for token..." >&2 sleep 1done # Get the token valueTOKEN=$(kubectl get secret default-token -o jsonpath='{.data.token}' | base64 --decode) # Explore the API with TOKENcurl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure