kubernetes折腾了好久,终于把Dashboard安装成功,其过程踩坑、排错苦不堪言,网上的教程也是百家杂谈,哈哈~,小编也写一下关于图形化管理工具的杂谈,希望能尽快帮助小伙伴们出坑。 轻松几步搞定
注意:安装版本,可以前往GitHub上查询稳定发行版以及与kubernetes兼容;小编安装的最新版本V2.5.0,因为小编的kubernetes版本是V1.23.4;
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
[root@VM-4-8-centos kubernetes]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
1、新建dashboard.yaml文件,目录自定义
2、将文件内容粘贴到该文件中
再次执行以下命令安装
kubectl apply -f dashboard.yaml
将type: ClusterIP改成NodePort,便于通过Node端口访问
命令kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
其中edit 和vim编辑模式一样
1、输入 /type
查找关键字
2、将ClusterIP
改成NodePort
,保存退出;
命令:kubectl get svc -A | grep kubernetes-dashboard
[root@VM-4-8-centos ~]# kubectl get svc -A | grep kubernetes-dashboard
kube-system kubernetes-dashboard NodePort 10.96.105.127 <none> 443:30987/TCP 5h12m
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.96.120.46 <none> 8000/TCP 59m
kubernetes-dashboard kubernetes-dashboard NodePort 10.96.62.77 <none> 443:30412/TCP 59m
服务器上部署dashboard,防火墙或者安全组要开放相关端口,例如小编需要释放30412
端口;
浏览器输入https://服务器公网IP:30412
进入登录页面;
vim dashboard-account.yaml
文件位置建议统一放在kubernetes目录下,方便后期自己管理;
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
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: kubernetes-dashboard
主要内容是创建admin-user账户,并授予集群管理权限;
kubectl apply -y dashboard-account.yaml
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
复制token,登录dashboard即可,进入之后可以管理各个namespace