k8s 安装 dashboard
编辑于 2021-08-19 17:30:45 阅读 2379
在 master 节点执行
本例 k8s 是 v1.22.0,对应的 dashboard 是 – 这个版本,具体去这里查看对应的版本 https://github.com/kubernetes/dashboard/releases
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
# 创建 pod
kubectl apply -f recommended.yaml
[root@master vagrant]# kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-856586f554-4xbht 1/1 Running 0 24m
kubernetes-dashboard-67484c44f6-5m6h6 1/1 Running 0 24m
dashboard 默认的服务的类型是ClusterIP,不便于我们通过浏览器访问,因此需要改成NodePort型的
[root@master vagrant]# kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 114m
kube-system kube-dns ClusterIP 10.1.0.10 <none> 53/UDP,53/TCP,9153/TCP 113m
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.1.112.227 <none> 8000/TCP 3m39s
kubernetes-dashboard kubernetes-dashboard ClusterIP 10.1.2.145 <none> 443/TCP 3m40s
# 删除
kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard
创建配置文件
vim dashboard-svc.yaml
# 内容
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
# 执行
kubectl apply -f dashboard-svc.yaml
想要访问dashboard服务,就要有访问权限,创建kubernetes-dashboard管理员角色
vi dashboard-svc-account.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dashboard-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
# 执行
kubectl apply -f dashboard-svc-account.yaml
获取 token
[root@master1 ~]# kubectl get secret -n kube-system |grep admin|awk '{print $1}'
dashboard-admin-token-bwgjv
# 复制下面的 token,后面登陆的时候要用到
[root@master1 ~]# kubectl describe secret dashboard-admin-token-bwgjv -n kube-system|grep '^token'|awk '{print $2}'
访问
https://192.168.10.90:31315/