安装 Kubernetes Dashboard
安装 Dashbaord⌗
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
身份验证⌗
创建账户:
cat <<EOF | sudo tee ~/dashboard-adminuser.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
kubectl apply -f dashboard-adminuser.yaml
创建集群角色绑定配置文件:
cat <<EOF | sudo tee ~/dashboard-adminrole.yaml
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
EOF
kubectl apply -f dashboard-adminrole.yaml
设置 Dashboard 暴露方式⌗
使用如下命令编辑配置信息,找到 type: ClusterIP
并将 ClusterIP 替换为 NodePort
:
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
然后使用如下命令查看暴露的端口:
kubectl get svc -A | grep kubernetes-dashboard
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.96.201.72 <none> 8000/TCP 26m
kubernetes-dashboard kubernetes-dashboard NodePort 10.96.6.126 <none> 443:32675/TCP 26m
获取 Token⌗
在 Kubernetes Master 节点上使用如下命令获取 Bearer Token:
kubectl -n kubernetes-dashboard create token admin-user
访问 Dashboard⌗
使用集群的任意节点 IP,如 https://10.0.8.81:32675 访问 Dashboard,会看到如下页面:
选择 Token 认证方式,并将之前生成的 Token 复制到这里,然后就可以看到 Dashboard 了。
I hope this is helpful, Happy hacking…