1. 创建 dashboard YAML文件
# 拉取文件 $ wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml # 修改 dashboard 文件的 service类型为 NodePort kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: ports: - port: 443 targetPort: 8443 nodePort: 30001 selector: k8s-app: kubernetes-dashboard type: NodePort
2. 部署 Dashboard
# 创建 [root@k8s-master01 opt]# kubectl apply -f kubernertes-dashboard.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
3. 验证创建成功
# 查看 POD [root@k8s-master01 opt]# kubectl get pods -n kubernetes-dashboard NAME READY STATUS RESTARTS AGE dashboard-metrics-scraper-7b59f7d4df-j9cls 1/1 Running 0 69s kubernetes-dashboard-5dbf55bd9d-tb28p 1/1 Running 0 69s
浏览器访问验证
4. 获取Token 登录
# 创建用户 $ kubectl create serviceaccount dashboard-admin -n kube-system # 用户授权 $ kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin # 获取用户Token $ kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
5. 登录成功
TIPS : kubectl 命令补全
# 安装 bash completion [root@k8s-master01 ~]# yum install bash-completion # 使得配置生效 [root@k8s-master01 ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc [root@k8s-master01 ~]# source ~/.bashrc