前言

首次登录dashboard界面的时候需要获取token,但如果每次都要在服务器上抓去token会很麻烦,影响用户体验.那么就需要使用常用的用户名密码形式

dashboard安装方式 :

1. 在所有master节点生成一个存放用户密码的文件

用户, 密码 需保持一致, 否则会报错, ID需要唯一

  1. [root@hdss7-21 ~]# mkdir /opt/kubernetes/pki
  2. -- 创建admin用户
  3. [root@hdss7-21 ~]# echo "admin,admin,1" >> /opt/kubernetes/pki/basic_auth_file
  4. -- 创建test用户 (实验未用)
  5. [root@hdss7-21 ~]# echo "test,test,2" >> /opt/kubernetes/pki/basic_auth_file

2. apiserver启动文件添加参数basic-auth-file

  1. [root@hdss7-21 ~]# vim /opt/kubernetes/server/bin/kube-apiserver-startup.sh
  2. /opt/kubernetes/server/bin/kube-apiserver \
  3. ...
  4. ...
  5. --basic-auth-file=/opt/kubernetes/pki/basic_auth_file
  6. [root@hdss7-21 ~]# supervisorctl restart kube-apiserver-7-21

3. 对dashboard资源配置清单修改

新增:

  • -authentication-mode=basic,token 新增basic验证方式,即用户密码验证
  • —token-ttl=43200 token登录超时时间 (可忽略)
  • – –auto-generate-certificates
  • – –namespace=kubernetes-dashboard
    1. containers:
    2. - name: kubernetes-dashboard
    3. image: kubernetesui/dashboard:v2.0.1
    4. imagePullPolicy: Always
    5. ports:
    6. - containerPort: 8443
    7. protocol: TCP
    8. args:
    9. - --auto-generate-certificates
    10. - --namespace=kubernetes-dashboard
    11. # Uncomment the following line to manually specify Kubernetes API server Host
    12. # If not specified, Dashboard will attempt to auto discover the API server and connect
    13. # to it. Uncomment only if the default does not work.
    14. # - --apiserver-host=http://my-address:port
    15. - --auto-generate-certificates
    16. - --namespace=kubernetes-dashboard
    17. - --token-ttl=43200
    18. - --authentication-mode=basic,token
    19. volumeMounts:
    20. - name: kubernetes-dashboard-certs

4. 更新配置信息

[root@hdss7-21 ~]# kubectl apply -f dashboard/dashboard.yaml

5. 将用户和权限绑定

[root@hdss7-21 ~]# kubectl create clusterrolebinding  login-on-dashboard-with-cluster-admin  –clusterrole=cluster-admin –user=admin

[root@hdss7-21 ~]# kubectl get clusterrolebinding login-on-dashboard-with-cluster-admin
NAME                                    AGE
login-on-dashboard-with-cluster-admin   6d18h

6. 查看dashboard界面

使用admin账号登录

image.png