Kubernetes Dashboard 是 Kubernetes 集群的 Web UI,用于可视化管理集群
准备配置文件
到github 下载配置文件recommended.yaml,参考地址如下:
https://github.com/kubernetes/dashboard/tree/v2.1.0/aio/deploy/recommended.yaml
创建dashboard服务
eric@server1:/usr/local/kubernetes/cluster$ kubectl create -f recommended.yaml
eric@server1:/usr/local/kubernetes/cluster$ kubectl get service -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d15h
default mysql-myshop LoadBalancer 10.104.140.183 <pending> 3306:32036/TCP 104m
default tomcat-http LoadBalancer 10.98.183.59 <pending> 8080:32168/TCP 7d3h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7d15h
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.98.128.165 <none> 8000/TCP 62m
kubernetes-dashboard kubernetes-dashboard ClusterIP 10.109.217.122 <none> 443/TCP 62m
暴露服务并访问
可以看到默认采用ClusterIP模式,外部无法访问,修改为NodePort类型,如下:
eric@server1:/usr/local/kubernetes/cluster$ kubectl patch svc kubernetes-dashboard -p '{"spec":{"type":"NodePort"}}' -n kubernetes-dashboard
service/kubernetes-dashboard patched
eric@server1:/usr/local/kubernetes/cluster$ kubectl get service -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d15h
default mysql-myshop LoadBalancer 10.104.140.183 <pending> 3306:32036/TCP 109m
default tomcat-http LoadBalancer 10.98.183.59 <pending> 8080:32168/TCP 7d3h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7d15h
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.98.128.165 <none> 8000/TCP 67m
kubernetes-dashboard kubernetes-dashboard NodePort 10.109.217.122 <none> 443:30423/TCP 67m
通过master节点的 30423端口访问如下(由于安全设置 谷歌浏览器无法访问,使用火狐浏览器访问即可):
创建Token
准备配置文件 dashborduser.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
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
创建token
eric@server1:/usr/local/kubernetes/cluster$ kubectl create -f dashborduser.yaml
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
打印token
eric@server1:/usr/local/kubernetes/cluster$ kubectl -n kube-system describe secret $(![请添加图片描述](https://img-blog.csdnimg.cn/b2c125da3be04071bf1c32e848647932.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW5neG1fcXo=,size_16,color_FFFFFF,t_70)
| grep admin-user | awk '{print $1}')
Name: admin-user-token-bxb7f
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: 8c54db0e-031b-11ec-9d95-000c298dac9c
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1025 bytes
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWJ4YjdmIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4YzU0ZGIwZS0wMzFiLTExZWMtOWQ5NS0wMDBjMjk4ZGFjOWMiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.tir4SfGGYjJKC7BOee3zel-AiHS9f1itw-bwdhoDUJpnw8w0ZiNslZaXYMsjPuZGJZlexILSavluhS-ITslWxDpiFekAQ6st5TGa5HTX7NsYYmDpuBzKe8pbe8YIoAY9QJR5PKc1Oo50ZGRPfHqgjP_wfTuqKlpRzM5pTTG6HJtBiS8cwrBdKT7mgYI_nEly5-lMPPSXftD-NSF7eR3tvVxRxd27b6s6BKZULBlVBRHRWAjgmHWkftghcTEWBBWwbDLg2CQVeAYmAsiQ_j_V6nZEQtaIts2hRwl96w7K53qvnIx8ZWAEJGoo9B6Yo49KzwdORt1hpv8jY4-kFrvxdQ
登录dashboard
将上述token输入浏览器,并点击登录,进入dashboard界面,如下图:如下图: