kubernetes官方提供的可视化界面
https://github.com/kubernetes/dashboard

安装

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

国外地址访问比较慢,使用 https://site.ip138.com/ 解析raw.githubusercontent.com的ip地址,再添加到hosts中

vi /etc/hosts
#增加一行
185.199.109.133 raw.githubusercontent.com

参考:
解决githubusercontent打不开的问题

再次执行

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

#查看dashboard是否安装完成
kubectl get pods -A

设置访问端口

kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard

#type: ClusterIP 改为 type: NodePort


#查看dashboard访问端口
kubectl get svc -A |grep kubernetes-dashboard

#返回类似数据,浏览器的访问地址是:https://192.168.99.200:30147
kubernetes-dashboard   kubernetes-dashboard        NodePort    10.96.4.117     <none>        443:30147/TCP            7m29s


创建访问账号

创建访问账号,vi dash.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

执行

kubectl apply -f dash.yaml

获取访问令牌

kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"

#如:
eyJhbGciOiJSUzI1NiIsImtpZCI6InFUOXJhLU5GVVJ0X1hUbkcyZUtENEV1a2czQ0tGWjVSdW1IT21adS1lWTgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXo0MmR2Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIxZWFhMTI5OC1kZDg4LTQ3ZjgtODQ4MS03NTljMzdjOWQ4MDEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.TkhEpwoyZt2xAQrRyCFLQfTTLVph_dzutZV4BonLIe17-3P7UnnnEM1EtnNCXPgLQ2rofFmyKndAkTtzhF7a8fP3k9r901aFvNONdkDJjhKeF_Zunml5d6RrurjVe41Cxl-HRZCgXqwNcM7XawTBlgrwy7wy-fLdBDP6S9V9MMXdoeJN3OULe_eV7mpU2bM7puDLr9XWhjXYg4WfG-x42QJblBa6WxmJXfbFb07vbU-YWRaboyIvKC6Ka-Rr7_Yof4fTpcSFpxu0S0v1hu9R5alnN2j7vtU-P3LHOnNMJc6N8NplHwg-pV1RcaYYIvh1hl_oL9jx6Sew36J6rQVMTg

使用生成的token登录

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐