How to sign in kubernetes dashboard?

后端 未结 9 2161
清酒与你
清酒与你 2020-12-07 07:01

I just upgraded kubeadm and kubelet to v1.8.0. And install the dashboard following the official document.

$ kubectl apply -f https://raw.githubusercontent.co         


        
相关标签:
9条回答
  • 2020-12-07 07:27

    Combining two answers: 49992698 and 47761914 :

    # Create service account
    kubectl create serviceaccount cluster-admin-dashboard-sa
    
    # Bind ClusterAdmin role to the service account
    kubectl create clusterrolebinding cluster-admin-dashboard-sa \
      --clusterrole=cluster-admin \
      --serviceaccount=default:cluster-admin-dashboard-sa
    
    # Parse the token
    TOKEN=$(kubectl describe secret $(kubectl -n kube-system get secret | awk '/^cluster-admin-dashboard-sa-token-/{print $1}') | awk '$1=="token:"{print $2}')
    
    0 讨论(0)
  • 2020-12-07 07:27

    The skip login has been disabled by default due to security issues. https://github.com/kubernetes/dashboard/issues/2672

    in your dashboard yaml add this arg

    - --enable-skip-login
    

    to get it back

    0 讨论(0)
  • 2020-12-07 07:31

    You need to follow these steps before the token authentication

    1. Create a Cluster Admin service account

      kubectl create serviceaccount dashboard -n default
      
    2. Add the cluster binding rules to your dashboard account

      kubectl create clusterrolebinding dashboard-admin -n default --clusterrole=cluster-admin --serviceaccount=default:dashboard
      
    3. Get the secret token with this command

      kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode
      
    4. Choose token authentication in the Kubernetes dashboard login page

    5. Now you can able to login

    0 讨论(0)
  • 2020-12-07 07:38

    A self-explanatory simple one-liner to extract token for kubernetes dashboard login.

    kubectl describe secret -n kube-system | grep deployment -A 12
    

    Copy the token and paste it on the kubernetes dashboard under token sign in option and you are good to use kubernetes dashboard

    0 讨论(0)
  • 2020-12-07 07:40

    TL;DR

    To get the token in a single oneliner:

    kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | awk '/^deployment-controller-token-/{print $1}') | awk '$1=="token:"{print $2}'
    

    This assumes that your ~/.kube/config is present and valid. And also that kubectl config get-contexts indicates that you are using the correct context (cluster and namespace) for the dashboard you are logging into.

    Explanation

    I derived this answer from what I learned from @silverfox's answer. That is a very informative write up. Unfortunately it falls short of telling you how to actually put the information into practice. Maybe I've been doing DevOps too long, but I think in shell. It's much more difficult for me to learn or teach in English.

    Here is that oneliner with line breaks and indents for readability:

    kubectl -n kube-system describe secret $(
      kubectl -n kube-system get secret | \
      awk '/^deployment-controller-token-/{print $1}'
    ) | \
    awk '$1=="token:"{print $2}'
    

    There are 4 distinct commands and they get called in this order:

    • Line 2 - This is the first command from @silverfox's Token section.
    • Line 3 - Print only the first field of the line beginning with deployment-controller-token- (which is the pod name)
    • Line 1 - This is the second command from @silverfox's Token section.
    • Line 5 - Print only the second field of the line whose first field is "token:"
    0 讨论(0)
  • 2020-12-07 07:43

    If you don't want to grant admin permission to dashboard service account, you can create cluster admin service account.

    $ kubectl create serviceaccount cluster-admin-dashboard-sa
    $ kubectl create clusterrolebinding cluster-admin-dashboard-sa \
      --clusterrole=cluster-admin \
      --serviceaccount=default:cluster-admin-dashboard-sa
    

    And then, you can use the token of just created cluster admin service account.

    $ kubectl get secret | grep cluster-admin-dashboard-sa
    cluster-admin-dashboard-sa-token-6xm8l   kubernetes.io/service-account-token   3         18m
    $ kubectl describe secret cluster-admin-dashboard-sa-token-6xm8l
    

    I quoted it from giantswarm guide - https://docs.giantswarm.io/guides/install-kubernetes-dashboard/

    0 讨论(0)
提交回复
热议问题