How to sign in kubernetes dashboard?

后端 未结 9 2169
清酒与你
清酒与你 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: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:"

提交回复
热议问题