在master节点部署

2.1 下载yml文件,地址GitHub - kubernetes/dashboard: General-purpose web UI for Kubernetes clusters

#查看各版本与k8s的兼容,选择相应版本,v2.6.0只兼容k8s v1.24;v2.4.0兼容k8s v1.20和v1.21
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
#下载yml文件,可更换其中的v2.6.0版本(目前最新版)
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
wget https://github.com/kubernetes/dashboard/blob/v2.6.0/aio/deploy/recommended.yaml

2.2 修改yam文件,service改为NodePort类型

在kind: Service段的spec下加type: NodePort 和nodePort: 30000(注意对齐)

#或创建服务后再用命令修改
kubectl patch svc kubernetes-dashboard -p '{"spec":{"type":"NodePort"}}' -n kubernetes-dashboard

2.3 创建服务

kubectl create -f recommended.yaml
或
kubectl apply -f recommended.yaml 

2.4 查看端口

kubectl get svc -n kubernetes-dashboard

#或者如下查看和修改
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
service/kubernetes-dashboard edited

然后使用浏览器访问IP和端口

2.5 创建账号

wget https://raw.githubusercontent.com/cby-chen/Kubernetes/main/yaml/dashboard-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 
kubectl apply -f dashboard-user.yaml

创建token令牌

#查看令牌(v2.6.0查看不了)
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}}"
# token令牌如下是我的(v2.4.0长期有效,可复制保存好)
eyJhbGciOiJSUzI1NiIsImtpZCI6IjhTbVVHeHl1d3ZRVzNYYVVrZ1hQOWVEa3paaF80NzMzU05jWTNVMnhzNVEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWdteHB0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI5ZTAwMWQyNS04MjNlLTQ5NGItYWIxOS04OTM5ODM3NGNjNTYiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.SrNqh7cnVmSHCEo62G0RxyhRdKDjiUu3UqzMY_lyb8YIPRthS5vTzKTPEmAVlOUOpoKYKfExsNgjdSZntswZ7WmdgM1chrbXlSPnDH0m1H-B10Y5hm-t3MqDFeOm2E4FEUpY0byk0kUzqlp5Vn2AzDPujzmDP9JHvH1WCppTyIxQtVt3um2cjXMAWqrUEwtLzzxXq8BSCmM0m0kNlolU8HfWM7hjtrA2dnP1jpr8o1GgSkCWdeDtzWMs8UAK4txCiFYIdpF-CIQ02yrP02JSKhNI0PaC9f4szp1tbNZhKL7phcvBfbIJCM5e5-qfTxOQNjv5ruE09nFm2nfXOz9adw
#创建令牌(v2.6.0每次要创建)
kubectl -n kubernetes-dashboard create token admin-user #创建token
Logo

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

更多推荐