- 生成证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout kube-dashboard.key -out kube-dashboard.crt -subj "/CN=dashboard.kube.com/O=kubernetes.dashboard.domain.com"
kubectl create secret tls dashboard-tls --key kube-dashboard.key --cert kube-dashboard.crt -n kubernetes-dashboard
kubectl get secret -n kubernetes-dashboard
- 执行一下命令
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
- 执行一下命令
apiVersion: v1
kind: ServiceAccount
metadata:name: admin-usernamespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: admin-user
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects:
- kind: ServiceAccountname: admin-usernamespace: kubernetes-dashboard
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: dashboard-ingressnamespace: kubernetes-dashboardannotations:nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:ingressClassName: "nginx"tls:- hosts: - kubernetes.dashboard.domain.comsecretName: dashboard-tlsrules:- host: kubernetes.dashboard.domain.comhttp:paths:- path: /pathType: Prefixbackend:service:name: kubernetes-dashboardport:number: 443
- 配置本机域名访问
127.0.0.1 kubernetes.dashboard.domain.com
- 访问地址
https://kubernetes.dashboard.domain.com/#/workloads?namespace=default
- 生成token
```bash
jiangzhongzhou@ZBMac-C02CW08SM kubelet-dashbord % kubectl -n kubernetes-dashboard create token admin-usereyJhbGciOiJSUzI1NiIsImtpZCI6Iks3dExUb1pMZDA2MGJnMy1xQ0JLSy1PZnNfaEVtSzZ6N2Q0NU81ald2ZGsifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzE2MjY0OTIxLCJpYXQiOjE3MTYyNjEzMjEsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiYWQ5ZmIwNmItZmM4MS00ZWJhLWFiODktMTJmY2I1MTEzZjE4In19LCJuYmYiOjE3MTYyNjEzMjEsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.09b9KFzDRDBezgLMj3CmWHHCDmW5bQumKQRq49o22ly-mtx6U15kP31gwz1XfW-_faQAPnf4enYICnw1dFKUhJFp7X-oX0Pdwc5Nv-rBAPFWOIksccc0720LZOCoITpd7uICV9_qstpZkgZj5_pm0uI1SfbzD4QyJEJZGO89-RUvut6beGVXL1dkL4iSyvrthiZWOiBFK7K_kCGNp0hIobrktAbxyfKAhw39VWL9QcueaimdliEZwqELMtwxXsXofwGqEBoFawVUlBMgR9Is1cwn31PfK-NSEI_VH_kt43w_-UlQ_JlFDKLZixa9RK_kKRGSzBtFCt-m0NpL_mBW5g
在浏览器页面填写进token即可