Skip to content

四、部署dashboard

1、官方文档

https://kubernetes.io/zh/docs/tasks/access-application-cluster/web-ui-dashboard/

https://github.com/kubernetes/dashboard

2、下载yaml

sh
# 不要直接安装,还需要修改配置
#kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml

# 下载
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
# 需要在下载来的文件中改这个
sh
type: NodePort

1619274681271

sh
# 加一个 type: NodePort
kubectl apply -f recommended.yaml
kubectl get pod -A

image-20210725231628736

image-20210725231715602

3、获取令牌

sh
https://139.198.16.160:30891/

#访问测试 每次访问都需要令牌
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

image-20210725231859418

image-20210725231955051

4、赋予权限

sh
# 发现这里没有可以显示的
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/README.md
yaml
### 运行这个给个权限
vi dashboard-admin.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: kubernetes-dashboard
    namespace: kubernetes-dashboard
sh
# 如有报错
The ClusterRoleBinding "kubernetes-dashboard" is invalid: roleRef: Invalid value: rbac.RoleRef{APIGroup:"rbac.authorization.k8s.io", Kind:"ClusterRole", Name:"cluster-admin"}: cannot change roleRef

kubectl delete -f dashboard-admin.yaml
kubectl apply -f dashboard-admin.yaml

image-20210725233242151