Helm部署 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ export KUBECONFIG=/etc/rancher/k3s/k3s.yamlhelm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard \ --create-namespace \ --namespace kubernetes-dashboard \ helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard \ --create-namespace \ --namespace kubernetes-dashboard \
配置远程访问 NodePort暴露端口 1 kubectl -n kubernetes-dashboard edit service kubernetes-dashboard-web
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 apiVersion: v1 ... name: kubernetes-dashboard namespace: kubernetes-dashboard resourceVersion: "343478" selfLink: /api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard uid: 8e48f478-993d-11e7-87e0-901b0e532516 spec: clusterIP: 10.100 .124 .90 externalTrafficPolicy: Cluster ports: - port: 443 protocol: TCP targetPort: 8443 selector: k8s-app: kubernetes-dashboard sessionAffinity: None type: NodePort status: loadBalancer: {}
Traefik Ingress反向代理 创建证书请求文件dashboard-cert-manager.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: k3s-chemmy-io namespace: default spec: secretName: k3s-chemmy-io-tls issuerRef: name: letsencrypt-staging kind: ClusterIssuer commonName: k3s.chemmy.io dnsNames: - k3s.sample.net
此配置文件是测试版,正式版参考K3s部署cert-manager
1 2 3 4 5 6 7 8 9 10 11 kubectl apply -f dashboard-cert-manager.yaml kubectl get certificates kubectl describe certificates k3s-chemmy-io kubectl delete certificates k3s-chemmy-io kubectl delete secrets k3s-chemmy-io-tls
配置账户 新建dashboard-admin.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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
新建用户
1 2 kubectl apply -f dashboard-admin.yaml
获取token
1 2 3 4 5 sudo k3s kubectl -n kubernetes-dashboard create token admin-usersudo k3s kubectl -n kubernetes-dashboard describe secret admin-user-token | grep '^token'
Kubectl部署 最新版本只支持Helm,旧版本v2.7支持Kubectl部署
下载 recommended.yaml
1 kubectl apply -f recommended.yaml
修改recommended.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... --- 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 --- ...
dashboard的默认webui证书是自动生成的,由于时间和名称存在问题,导致谷歌和ie浏览器无法打开登录界面,经过测试Firefox可以正常打开。解决证书问题参考Kubernetes Dashboard的安装与坑 - 简书 (jianshu.com)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 --- --- ... --- kind: Deployment apiVersion: apps/v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s-app: kubernetes-dashboard template: metadata: labels: k8s-app: kubernetes-dashboard spec: containers: - name: kubernetes-dashboard image: kubernetesui/dashboard:v2.1.0 imagePullPolicy: Always ports: - containerPort: 8443 protocol: TCP args: - --namespace=kubernetes-dashboard - --token-ttl=3600 - --bind-address=0.0.0.0 - --tls-cert-file=tls.crt - --tls-key-file=tls.key volumeMounts: - name: kubernetes-dashboard-certs mountPath: /certs - mountPath: /tmp name: tmp-volume livenessProbe: httpGet: scheme: HTTPS path: / port: 8443 initialDelaySeconds: 30 timeoutSeconds: 30 securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true runAsUser: 1001 runAsGroup: 2001 volumes: - name: kubernetes-dashboard-certs secret: secretName: kubernetes-dashboard-certs - name: tmp-volume emptyDir: {} serviceAccountName: kubernetes-dashboard nodeSelector: "kubernetes.io/os": linux tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule --- ...
生成证书文件 tls.crt,tls.csr,tls.key
1 2 3 4 5 6 7 8 9 openssl genrsa -out tls.key 2048 openssl req -new -out tls.csr -key tls.key -subj '/CN=0.0.0.0' openssl x509 -req -in tls.csr -signkey tls.key -out tls.crt kubectl create secret generic kubernetes-dashboard-certs --from-file=tls.crt --from-file=tls.key -n kubernetes-dashboard
subj子参数解释
缩写
翻译
英文对照
C
国家名称缩写
Country Name (2 letter code)
ST
州或省名称
State or Province Name (full name)
L
城市或区域称
Locality Name (eg, city)
O
组织名(或公司名)
Organization Name (eg, company)
OU
组织单位名称(或部门名)
Organizational Unit Name (eg, section)
CN
服务器域名/证书拥有者名称
Common Name (e.g. server FQDN or YOUR name)
emailAddress
邮件地址
Email
参考
k3s集群单节点部署与集群内DashBoard部署 - 知乎 (zhihu.com)
k3s集群搭建并安装kubernetes-dashboard - 东峰叵,com - 博客园 (cnblogs.com)
[K8S 快速入门(十九)通过Helm 安装 Kubernetes Dashboard_helm安装dashboard ingress-CSDN博客](https://blog.csdn.net/weixin_41947378/article/details/111661539#:~:text=通过Helm 安装 Kubernetes Dashboard 1 1. 下载 %23,外网访问 %23 将svc的ClusterIP改为NotePort,外网访问 … 5 5. 令牌方式登录仪表盘)
使用 traefik ingress暴露kubernetes-dashbord - HTTPS版本_svclb-traefik-CSDN博客
Kubernetes dashboardv2.7.0安装指南:从零开始搭建可视化界面 - 知乎