天天看點

Cluster Setup - GUI Elements GUI儀表盤

1. 前言

https://cloud.tencent.com/act?from=10680

https://cloud.tencent.com/act/season?from=14065

https://cloud.tencent.com/?from=10680

(照舊加幾個騰訊雲連接配接)

這部分主要講了kubernetes的Gui工具 dashboard。

1. 關于 GUI元素的通路控制

1. GUI元素和儀表盤

2. 外部通路儀表盤的方法

3. 通路的限制

2. GUI元素和儀表盤遵循的原則

1. 隻在需要時向外部公開服務

2. 叢集内部服務/儀表闆也可以使用kubectl port-forward端口轉發通路。

3. 需要開啟rbac權限控制,否則蔣導緻權限過大

4. 對外暴露不是必須的

Cluster Setup - GUI Elements GUI儀表盤
Cluster Setup - GUI Elements GUI儀表盤

2. 代理的方式

1. 關于 Kubectl porxy方式

1. create a proxy server between localhost and the kubernetes api server   在               localhost和kubernetes api伺服器之間建立代理伺服器
2. uses connection as configured in the kubeconfig  使用kubeconfig中配置的連接配接
3. allows to access api locally just over http and without authentication  允許通過HTTP本地通路api,無需身份驗證           

複制

Cluster Setup - GUI Elements GUI儀表盤

2. 關于kubectl port-forward

1. 将本地主機端口的連接配接轉發到pod端口
2. 比使用kubectl代理更為通用
3. 可以用于所有tcp通信而不僅僅是http           

複制

Cluster Setup - GUI Elements GUI儀表盤
Cluster Setup - GUI Elements GUI儀表盤

3. ingress代理的方式,ingress-nginx traefik等等都可以

Cluster Setup - GUI Elements GUI儀表盤

3. 安裝和登陸dashboard gui

1.安裝dashboard

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

複制

Cluster Setup - GUI Elements GUI儀表盤

2. 使dashboard對外暴露(使用http的方式,在生産中這是禁止的)

Cluster Setup - GUI Elements GUI儀表盤
Cluster Setup - GUI Elements GUI儀表盤
Cluster Setup - GUI Elements GUI儀表盤
Cluster Setup - GUI Elements GUI儀表盤
root@cks-master:~/work/dashboard# kubectl get pod,svc -n kubernetes-dashboard
NAME                                             READY   STATUS    RESTARTS   AGE
pod/dashboard-metrics-scraper-79c5968bdc-mbgk7   1/1     Running   0          19m
pod/kubernetes-dashboard-6568c7684c-9n6vp        1/1     Running   3          3m41s

NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/dashboard-metrics-scraper   ClusterIP   10.97.159.164   <none>        8000/TCP         19m
service/kubernetes-dashboard        NodePort    10.97.34.204    <none>        9090:32740/TCP   19m           

複制

NodePort端口可以用master或者work節點任意一IP+端口方式通路

Cluster Setup - GUI Elements GUI儀表盤

4. 練習-用于儀表闆的RBAC

Cluster Setup - GUI Elements GUI儀表盤

我覺得關于rolebinding clusterrolebinding兩個的差別有必要強調一下啊,一個是針對于命名空間的,另外一個是針對所有空間的。

#針對與一個命名空間
kubectl -n kubernetes-dashboard create rolebinding insecure --serviceaccount kubernetes-dashboard:kubernetes-dashboard --clusterrole view 


#針對于所有空間
kubectl create clusterrolebinding insecure --serviceaccount kubernetes-dashboard:kubernetes-dashboard --clusterrole view           

複制

Cluster Setup - GUI Elements GUI儀表盤

5. so正常的部署方式

#部署
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml
#修改網絡類型NodePort
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard           

複制

Cluster Setup - GUI Elements GUI儀表盤

https方式登陸

Cluster Setup - GUI Elements GUI儀表盤

擷取token

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

Cluster Setup - GUI Elements GUI儀表盤

将token複制進去 oK登陸成功

Cluster Setup - GUI Elements GUI儀表盤

至于kuberconfig的方式就不去試了,因為config裡面都設定的内網ip。apiserver沒有對外暴露

Cluster Setup - GUI Elements GUI儀表盤

4. 總結:

  1. 盡在你需要的時候對外暴露,并且要保障足夠的安全
  2. 棄用RBAC限制
  3. 實施使用者認證
  4. 憑據要經常更改
Cluster Setup - GUI Elements GUI儀表盤