Dashboard是Kubernetes官方的一个ui组件,可以在web查看操作Kubernetes

下载yaml文件

下载官方提供的Dashboard组件的yaml

1
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

修改yaml文件里镜像源

可以科学上网的可以跳过这一步 关于怎么配置科学上网参考科学上网一文

VNVxNn.jpg

如果不能科学上网,就将 k8s.gcr.io  改为 registry.cn-hangzhou.aliyuncs.com/google_containers 后面的涉及地址的可以做相同的修改

修改yaml文件中的Dashboard Service

VyGfYQ.jpg

修改为

VyG5Ss.jpg

启动Dashboard

1
kubectl apply -f kubernetes-dashboard.yaml

访问Dashboard

访问https://<your:ip>:30001

会显示以下界面

VyJnXt.jpg

创建能够访问Dashboard的用户

创建account.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system

创建对应的用户

1
kubectl apply -f account.yaml

获取登录的令牌(Token)

1
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

显示以下输出:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[root@test ~]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Name:         admin-user-token-qqtfl
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: eeab7b78-8412-11e9-9ac2-005056906ecd

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJ...............

将token的值输入上

面板如下

VyrI1K.jpg