How to sign in kubernetes dashboard?

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

    Download https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/alternative/kubernetes-dashboard.yaml

    add

    type: NodePort for the Service
    

    And then run this command:

    kubectl apply -f kubernetes-dashboard.yaml
    

    Find the exposed port with the command :

    kubectl get services -n kube-system
    

    You should be able to get the dashboard at http://hostname:exposedport/ with no authentication

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

    As of release 1.7 Dashboard supports user authentication based on:

    • Authorization: Bearer <token> header passed in every request to Dashboard. Supported from release 1.6. Has the highest priority. If present, login view will not be shown.
    • Bearer Token that can be used on Dashboard login view.
    • Username/password that can be used on Dashboard login view.
    • Kubeconfig file that can be used on Dashboard login view.

    — Dashboard on Github

    Token

    Here Token can be Static Token, Service Account Token, OpenID Connect Token from Kubernetes Authenticating, but not the kubeadm Bootstrap Token.

    With kubectl, we can get an service account (eg. deployment controller) created in kubernetes by default.

    $ kubectl -n kube-system get secret
    # All secrets with type 'kubernetes.io/service-account-token' will allow to log in.
    # Note that they have different privileges.
    NAME                                     TYPE                                  DATA      AGE
    deployment-controller-token-frsqj        kubernetes.io/service-account-token   3         22h
    
    $ kubectl -n kube-system describe secret deployment-controller-token-frsqj
    Name:         deployment-controller-token-frsqj
    Namespace:    kube-system
    Labels:       <none>
    Annotations:  kubernetes.io/service-account.name=deployment-controller
                  kubernetes.io/service-account.uid=64735958-ae9f-11e7-90d5-02420ac00002
    
    Type:  kubernetes.io/service-account-token
    
    Data
    ====
    ca.crt:     1025 bytes
    namespace:  11 bytes
    token:      eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkZXBsb3ltZW50LWNvbnRyb2xsZXItdG9rZW4tZnJzcWoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVwbG95bWVudC1jb250cm9sbGVyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNjQ3MzU5NTgtYWU5Zi0xMWU3LTkwZDUtMDI0MjBhYzAwMDAyIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRlcGxveW1lbnQtY29udHJvbGxlciJ9.OqFc4CE1Kh6T3BTCR4XxDZR8gaF1MvH4M3ZHZeCGfO-sw-D0gp826vGPHr_0M66SkGaOmlsVHmP7zmTi-SJ3NCdVO5viHaVUwPJ62hx88_JPmSfD0KJJh6G5QokKfiO0WlGN7L1GgiZj18zgXVYaJShlBSz5qGRuGf0s1jy9KOBt9slAN5xQ9_b88amym2GIXoFyBsqymt5H-iMQaGP35tbRpewKKtly9LzIdrO23bDiZ1voc5QZeAZIWrizzjPY5HPM1qOqacaY9DcGc7akh98eBJG_4vZqH2gKy76fMf0yInFTeNKr45_6fWt8gRM77DQmPwb3hbrjWXe1VvXX_g
    

    Kubeconfig

    The dashboard needs the user in the kubeconfig file to have either username & password or token, but admin.conf only has client-certificate. You can edit the config file to add the token that was extracted using the method above.

    $ kubectl config set-credentials cluster-admin --token=bearer_token

    Alternative (Not recommended for Production)

    Here are two ways to bypass the authentication, but use for caution.

    Deploy dashboard with HTTP

    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/alternative/kubernetes-dashboard.yaml
    

    Dashboard can be loaded at http://localhost:8001/ui with kubectl proxy.

    Granting admin privileges to Dashboard's Service Account

    $ cat <<EOF | kubectl create -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
    

    Afterwards you can use Skip option on login page to access Dashboard.

    If you are using dashboard version v1.10.1 or later, you must also add --enable-skip-login to the deployment's command line arguments. You can do so by adding it to the args in kubectl edit deployment/kubernetes-dashboard --namespace=kube-system.

    Example:

          containers:
          - args:
            - --auto-generate-certificates
            - --enable-skip-login            # <-- add this line
            image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
    
    0 讨论(0)
  • 2020-12-07 07:48

    All the previous answers are good to me. But a straight forward answer on my side would come from https://github.com/kubernetes/dashboard/wiki/Creating-sample-user#bearer-token. Just use kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}'). You will have many values for some keys (Name, Namespace, Labels, ..., token). The most important is the token that corresponds to your name. copy that token and paste it in the token box. Hope this helps.

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