9、kubernetes组件——dashboard
kubernetes组件——dashboard
Kubernetes Dashboard 是 Kubernetes 的官方 Web UI。使用 Kubernetes Dashboard,您可以:
- 向 Kubernetes 集群部署容器化应用
- 诊断容器化应用的问题
- 管理集群的资源
- 查看集群上所运行的应用程序
- 创建、修改Kubernetes 上的资源(例如 Deployment、Job、DaemonSet等)
- 展示集群上发生的错误
安装
下载模板文件
root@k8s-deploy-01:/opt/soft# mkdir dashboard-v2.6.0
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
root@k8s-deploy-01:/opt/soft/dashbard-v2.6.0# mv recommended.yaml dashboard-v2.6.0.yaml
下载镜像
下载安装所需的镜像到本地harbor
root@k8s-deploy-01:~# docker pull kubernetesui/dashboard:v2.6.0
root@k8s-deploy-01:~# docker pull kubernetesui/metrics-scraper:v1.0.8
root@k8s-deploy-01:~# docker tag kubernetesui/dashboard:v2.6.0 xmtx.harbor.com/baseimages/dashboard:v2.6.0
root@k8s-deploy-01:~# docker tag kubernetesui/metrics-scraper:v1.0.8 xmtx.harbor.com/baseimages/metrics-scraper:v1.0.8
root@k8s-deploy-01:~# docker push xmtx.harbor.com/baseimages/dashboard:v2.6.0
root@k8s-deploy-01:~# docker push xmtx.harbor.com/baseimages/metrics-scraper:v1.0.8
修改配置
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# vim dashboard-v2.6.0.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
nodePort: 30001 #对外暴露30001端口端口号要符合NODE_PORT_RANGE范围
selector:
k8s-app: kubernetes-dashboard
containers:
- name: kubernetes-dashboard
image: xmtx.harbor.com/baseimages/dashboard:v2.6.0 #使用本地harbor下载
imagePullPolicy: Always
ports:
- containerPort: 8443
protocol: TCP
args:
- --auto-generate-certificates
- --namespace=kubernetes-dashboard
containers:
- name: dashboard-metrics-scraper
image: xmtx.harbor.com/baseimages/metrics-scraper:v1.0.8 #使用本地harbor下载
ports:
- containerPort: 8000
protocol: TCP
创建dashboard
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# kubectl apply -f dashboard-v2.6.0.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
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kubernetes-dashboard dashboard-metrics-scraper-5f4bd76744-vlxvq 1/1 Running 0 16s
kubernetes-dashboard kubernetes-dashboard-797bd5c6d7-pfhm8 1/1 Running 0 16s
使用Token登录
#admin-secret.yaml 文件
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# cat admin-secret.yaml
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: dashboard-admin-user
namespace: kubernetes-dashboard
annotations:
kubernetes.io/service-account.name: "admin-user"
#admin-user.yaml 文件
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# cat admin-user.yaml
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
#创建用户
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# kubectl apply -f admin-user.yaml
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
#创建secret
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# kubectl apply -f admin-secret.yaml
secret/dashboard-admin-user created
#获取
root@k8s-deploy-01:/opt/soft/dashboard-v2.6.0# kubectl describe secrets dashboard-admin-user -n kubernetes-dashboard