k8s-dashboard布署
- Kubernetes dashboard作用
- 获取Kubernetes dashboard资源清单文件
- 修改并部署kubernetes dashboard资源清单文件
- 访问Kubernetes dashboard
Kubernetes dashboard作用
- 通过dashboard能够直观了解Kubernetes集群中运行的资源对象
- 通过dashboard可以直接管理(创建、删除、重启等操作)资源对象
获取Kubernetes dashboard资源清单文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
修改并部署kubernetes dashboard资源清单文件
直接将该资源清单文件下载下来,对其进行修改即可。
为了方便在容器主机上访问,下面的service需要添加NodePort类型及端口。
---
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: 30000
selector:
k8s-app: kubernetes-dashboard
为了防止权限不够,在 ClusterRoleBinding
处需要修改登录kubernetes dashboard后用户的身份,不然无法显示资源情况。
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kubernetes-dashboard
修改完成之后使用命令让其生效。
布署
kubectl apply -f recommended.yaml
访问Kubernetes dashboard
当在浏览器中输入IP:port
时会提示:Client sent an HTTP request to an HTTPS server.
只需要在IP前面加上https://
便可成功访问。
登录需要获取token,用命令的方式来获取即可。
先
kubectl get secret -n kubernetes-dashboard
NAME TYPE DATA AGE
default-token-w2s7j kubernetes.io/service-account-token 3 29m
kubernetes-dashboard-certs Opaque 0 29m
kubernetes-dashboard-csrf Opaque 1 29m
kubernetes-dashboard-key-holder Opaque 2 29m
kubernetes-dashboard-token-t4qdp kubernetes.io/service-account-token 3 29m
再来查看token
kubectl describe secret kubernetes-dashboard-token-t4qdp -n kubernetes-dashboard
##命令
Name: kubernetes-dashboard-token-t4qdp
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: kubernetes-dashboard
kubernetes.io/service-account.uid: e204650e-df62-46c8-810d-47d8fd98a4c1
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1367 bytes
namespace: 20 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6InpaRW5OczVSZ19RYTIzcUVOb2c5V25fVkY2YW1aT2NOWlFzVFRCbUkzUlEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC10b2tlbi10NHFkcCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImUyMDQ2NTBlLWRmNjItNDZjOC04MTBkLTQ3ZDhmZDk4YTRjMSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.QocuobfL-pUwFJgqIVOIvq9rkGQsJ5f4undVJmqi6mZRYTCSSMpp0QC-Po05fH1Hp1_2llEUcwC0rUSALw7aX5Y3qwdGxxc0oV1C1lm2K-I67NMYLU4IcLrjhRRV9x0cnc3pk8i_k1fA5FwYhtP1_U6c0Q0e1nSOKJFy-SQFDvCV4OcFxGA2bua4ul-IUG91fZEDYNNp64uDuhrnGC8DSAyE0-N52t9mOr3Azng_1r15_b2mfA36B4lLUSUMuG9AkIThE4ggqe1fc2PqQyeoDUzRysvF3PMgRiq-B-IkEMJvVU7umkySDV2jm9wdF-UPs-M9zwd49HQKH8flBH8fxA
使用token登入之后结果如下图所示: