Skip to content

Instantly share code, notes, and snippets.

@roberthamel
Last active November 7, 2019 14:48
Show Gist options
  • Save roberthamel/342718c6a378dfafbbe4ac19ded9341f to your computer and use it in GitHub Desktop.
Save roberthamel/342718c6a378dfafbbe4ac19ded9341f to your computer and use it in GitHub Desktop.

Access Kubenetes Dashboard with Credentails

Kubernetes dashboard comes pre-installed on each PKS cluster. The following instructions are for how create credentials and obtain the access token. If there is an easier way, please let me know.

Install a Cluster Role Binding:

This command only needs to be run once.

cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-dashboard
  labels:
    k8s-app: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: kubernetes-dashboard
  namespace: kube-system
EOF

Access the Dashboard

  1. Display the access token:
name=$(kubectl -n kube-system get secret | grep kubernetes-dashboard-token | cut -c1-32)
kubectl -n kube-system describe secret $name | grep token
  1. Copy the access token to the clipboard.

  2. Run kubectl proxy.

  3. Access the dashboard at http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

  4. Select token and paste the token you have saved in the clipboard

  5. The dashboard can be used now.

  6. When finished, Press CTRL-C to stop the proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment