Pages - Menu

2023年3月27日 星期一

[Kubernetes]kubernetes Dashboard

碎碎念

以前GKE用習慣了,現在變成自建的k8s,只能用lens管,
雖然說不上有哪不足,但總是怪怪的。
今天查資料看到有這個UI,就架來看看了。


正文

本機訪問

官方檔案,安裝下去就好了

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

執行轉發來連到dashboard

kubectl proxy

kubectl 會使得 Dashboard 可以通過 http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ 訪問。

登入畫面如下


再來就需要產生一組token來做登入了。

首先建立一組serviceAccount

cat <<EOF | kubectl create -f -  
apiVersion: v1  
kind: ServiceAccount  
metadata:  
  name: admin
  namespace: kube-system  
EOF

綁定serviceAccount 與 角色

cat <<EOF | kubectl create -f -  
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
  namespace: kube-system  
EOF

Service Account建立完後,Kubernetes Token Controller 就會自動的為其產生一個 secret resource(名稱為 [SERVICE_ACCOUNT_NAME]-token-[RANDOM_STRING])

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin | awk '{print $1}')




這邊取得的token即可在 Dashboard 上登入。

ref. 佈署 & 存取 Kubernetes Dashboard

外部訪問

更改service 內的 kubernetes-dashboard.kubenetes-dashboards
將cluster改成NodePort ,然後看對應的port多少就能登入了。
記得用https



ref. accessing-dashboard

沒有留言:

張貼留言