Web 界面 (Dashboard)
Dashboard 是基于網頁的 Kubernetes 使用者界面。你可以使用 Dashboard 将容器應用部署到 Kubernetes 叢集中,也可以對容器應用排錯,還能管理叢集資源。你可以使用 Dashboard 擷取運作在叢集中的應用的概覽資訊,也可以建立或者修改 Kubernetes 資源 (如 Deployment,Job,DaemonSet 等等)。例如,你可以對 Deployment 實作彈性伸縮、發起滾動更新、重新開機 Pod 或者使用向導建立新的應用。
Dashboard 同時展示了 Kubernetes 叢集中的資源狀态資訊和所有報錯資訊。
部署 Dashboard UI
檢視目前叢集node
[root@master01 k8s-dashboard]# kubectl get node
NAME STATUS ROLES AGE VERSION
172.19.64.35 Ready node 2d16h v1.18.0
172.19.64.36 Ready node 2d16h v1.18.0
172.19.64.37 Ready node 2d16h v1.18.0
172.19.64.38 Ready node 2d16h v1.18.0
172.19.64.39 Ready node 2d16h v1.18.0
172.19.64.40 Ready,SchedulingDisabled master 2d16h v1.18.0
172.19.64.41 Ready,SchedulingDisabled master 2d16h v1.18.0
[root@master01 k8s-dashboard]#
複制
因為我的叢集是1.18.10版本,是以dashboard選擇2.0.3版。
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml
複制
修改dashboard的yaml檔案
修改service部分,預設service是ClusterIP類型,這裡改稱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: 30012
selector:
k8s-app: kubernetes-dashboard
複制
執行yaml檔案
[root@master01 k8s-dashboard]# kubectl apply -f recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
[root@master01 k8s-dashboard]#
複制
檢視服務狀态
[root@master01 k8s-dashboard]# kubectl get all -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-6b4884c9d5-tdw2m 1/1 Running 0 39s
pod/kubernetes-dashboard-7d8574ffd9-rbfwm 1/1 Running 0 39s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.0.0.110 <none> 8000/TCP 39s
service/kubernetes-dashboard NodePort 10.0.0.17 <none> 443:30012/TCP 39s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/dashboard-metrics-scraper 1/1 1 1 39s
deployment.apps/kubernetes-dashboard 1/1 1 1 39s
NAME DESIRED CURRENT READY AGE
replicaset.apps/dashboard-metrics-scraper-6b4884c9d5 1 1 1 39s
replicaset.apps/kubernetes-dashboard-7d8574ffd9 1 1 1 39s
[root@master01 k8s-dashboard]#
複制
可以看到pod 服務已經是running狀态
通路叢集IP:30012端口可以通路web管理界面
點選進階,繼續通路。
建立登入使用者資訊
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin
namespace: kubernetes-dashboard
複制
執行到叢集
kubectl apply -f admin.yaml
複制
檢視kubernetes-dashboard下面的secret
[root@master01 k8s-dashboard]# kubectl get secret -n kubernetes-dashboard
NAME TYPE DATA AGE
default-token-7c4nd kubernetes.io/service-account-token 3 8m28s
kubernetes-dashboard-certs Opaque 0 8m28s
kubernetes-dashboard-csrf Opaque 1 8m28s
kubernetes-dashboard-key-holder Opaque 2 8m28s
kubernetes-dashboard-token-wdtbk kubernetes.io/service-account-token 3 8m28s
複制
檢視登入token
[root@master01 k8s-dashboard]# kubectl describe secret kubernetes-dashboard-token-wdtbk -n kubernetes-dashboard
Name: kubernetes-dashboard-token-wdtbk
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: kubernetes-dashboard
kubernetes.io/service-account.uid: 1f51d545-91a8-4b27-9f22-e15791dff4eb
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1363 bytes
namespace: 20 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjVkdnktMnVLRTU2UGN2SlRBWXEyM0hrSXRZdS0ya20yNkNGeGloWENwTzQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC10b2tlbi13ZHRiayIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjFmNTFkNTQ1LTkxYTgtNGIyNy05ZjIyLWUxNTc5MWRmZjRlYiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.GnhMhTC76Ty4YMnkE8L5L9pQgn2DTa3bJQSTkLOV8sCo9RlGjnGPgCcyrXVMfMQb4O0Qc7TAhcwxqmICI_uHXzLX6JNc0Vvmw6_lzbkUlxRg_qdX8Zlol7wYlxb01cex4SL4JCyxbPbZ1ChXP75fsKl3nxIGWntdie8fpH_DuHH4XjosOTnkx-GBhYoarXvcRtu_kzwKJw2dCULNhOycyFsC9ufQV1tcF89yWCw2XcNzRqGWPUDbhEJ4NtsHA_UbZ6FGTyHQ7RfLWnIDN63u-uH8v2y-oX19gd0IrK6rDyYchpx4Wp4uqdmcHEgHH0eQN-ImDMyqVj2xHSkzYcMHMA
[root@master01 k8s-dashboard]#
複制
登陸dashboard
檢視叢集pod資訊
檢視叢集service
檢視叢集node節點資訊
檢視叢集Deployments