当前位置:网站首页>基於 KubeSphere 的分級管理實踐
基於 KubeSphere 的分級管理實踐
2022-06-25 07:03:00 【KubeSphere】
作者:許偉,航天網信研發工程師
K8s 是容器編排和分布式應用部署領域的領導者,在 K8s 環境中,我們只需要關心應用的業務邏輯,减輕了我們服務器網絡以及存儲等方面的管理負擔。對於一個用戶而言,K8s 是一個很複雜的容器編排平臺,學習成本非常高。KubeSphere 抽象了底層的 K8s,並進行了高度的產品化,構建了一個全棧的多租戶容器雲平臺,為用戶提供了一個健壯、安全、功能豐富、具備極致體驗的 Web 控制臺,解决了 K8s 使用門檻高和雲原生生態工具龐雜等痛點,使我們可以專注於業務的快速迭代,其多維度的數據監控,對於問題的定比特,提供了很大的幫助。
為什麼要在 KuberSphere 上實現分級管理
在 KubeSphere 中,資源可以在租戶之間共享,根據分配的不同角色,可以對各種資源進行操作。租戶與資源之間、資源與資源之間的自由度很高,權限粒度也比較大。在我們的系統中,資源是有權限等級的,像是低等級用戶可以通過邀請、賦予權限等操作來操作高等級資源,或者像是低等級項目中的 Pod 可以調度到高等級的節點上,對資源。諸如此類跨等級操作資源等問題,我們在 KubeSphere 基礎上來實現了分級管理。
什麼是分級體系
分級,顧名思義就是按照既定的標准對整體進行分解、分類。我們將其抽象成一個金字塔模型,從地基到塔頂會有很多個層級,我們將公共資源作為金字塔的地基,擁有最高權限的 admin 作為塔頂,其他資源按照權限等級劃分成不同等級。低層級資源是不能訪問高等級資源,高等級資源可以獲取它等級之下的所有資源,構建了這樣一個權益遞减、層級間隔離的分級體系。

如何實現分級管理
我們定義了一個代錶等級的標簽 kubernetes.io/level。以一個多節點的集群為例,首先我們會給用戶、企業空間、節點等資源打上代錶等級的標簽。在邀請用戶加入企業空間或者項目時,要求加入的企業空間或者項目的等級不得高於用戶的等級,同樣項目在綁定企業空間時,也要求項目的等級不得高於企業空間的等級,才能對資源進行納管;我們認為同一項目下的資源的等級是相同的,基於項目創建的負載、Pod、服務等資源的等級跟項目保持一致;同時 Pod 中加入節點親和性,以使 Pod 調度到不高於其權限等級的節點上。

例如這裏,我們創建了一個權限等級是 3 的用戶 demo-user,他可以加入權限等級不高於3的企業空間或者項目中。
kind: UserapiVersion: iam.kubesphere.io/v1alpha2metadata: name: demo-user labels: kubernetes.io/level: 3spec: email: [email protected]創建一個權限等級是 2 的項目 demo-ns,那麼基於項目創建的負載、Pod、存儲等資源的權限等級也是 2。
apiVersion: v1kind: Namespacemetadata: name: demo-ns labels: kubernetes.io/level: 2基於 demo-ns 項目創建了一個nginx 的 Pod,他的權限等級也是 2,同時加入節點親和性,要求其調度到權限等級不高於 2 的節點上。
apiVersion: apps/v1kind: Podmetadata: labels: kubernetes.io/level: 2 name: nginxspec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent ports: - containerPort: 80 protocol: TCP affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/level operator: Lt values: - 2 - matchExpressions: - key: kubernetes.io/level operator: In values: - 2如何實現資源的昇降級
在分級管理體系中,支持等級的無限劃分,只需要定義一個中間值,就可以在兩個等級之間插入一個新的等級,無需操作其他資源;在對資源進行昇降級時,只需要修改對應資源的 label 標簽,就可以對資源進行昇降級操作。當然,在對資源進行昇降級的時候,我們需要對資源進行檢測,保證昇級時,其上層資源的權限等級不得低於目標等級;同時,降級時,其下層資源的權限等級不得高於目標等級。在不滿足昇降級操作條件時,需要將對應資源也做相應調整才可以。

不同層級間 Pod 的網絡隔離
在分級體系中,我們要求高等級的 Pod 能訪問低等級的 Pod,但是低等級的 Pod 不能訪問高等級的 Pod,那我們需要如何保證不同層級間 Pod 的網絡通信呢。
項目在不開啟網絡隔離的情况下,Pod 間的網絡是互通的,所以這裏會新增一個黑名單的網絡策略。
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: deny-all namespace: demo-ns labels: kubernetes.io/level: 2spec: podSelector: {} policyTypes: - IngresspodSelector:{} 作用於項目中所有 Pod,阻止所有流量的流入。
然後放行標簽等級大於目標等級(這裏是 2)的流量流入(我們對 Ingress 流量沒有做限制)。
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: level-match-network-policy namespace: demo-ns labels: kubernetes.io/level: 2spec: podSelector: matchExpressions: - key: kubernetes.io/level operator: Gt values: - 2 policyTypes: - Ingress總結
KubeSphere 解决了用戶構建、部署、管理和可觀測性等方面的痛點,它的資源可以在多個租戶之間共享。但是在資源有權限等級的場景中,低等級資源可以操作高等級資源,造成資源越權管理的問題。為解决這一問題,我們在 KubeSphere 的基礎上進行了改造,以適應租戶與資源之間和資源與資源之間的分級管理,同時在項目的網絡策略中,增加黑名單和白名單策略,增强了項目間的網絡隔離,讓資源的管理更安全。
本文由博客一文多發平臺 OpenWrite 發布!
边栏推荐
- Derivation of COS (a+b) =cosa*cosb-sina*sinb
- How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
- 爱情️终结者
- Acwing2013. three lines
- Difference between rest and WebServices
- The significance and proof of weak large number theorem
- Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
- Message queue table structure for storing message data
- ACWING/2004. 错字
- Shandong finds clean energy that can be used by China for 3800 years? You should know the truth first
猜你喜欢

百度地图——入门教程

原子Alpha开发板--SD卡和emmc烧录工具

sin(a-b)=sina*cosb-sinb*cosa的推导过程

2022 biological fermentation Exhibition (Jinan), which is a must read before the exhibition. The most comprehensive exhibition strategy will take you around the "fermentation circle"

Direct select sort and quick sort

Want to self-study SCM, do you have any books and boards worth recommending?

Sophomores majoring in mechanics build a manipulator by hand -- full of compromise

Americo technology launches professional desktop video editing solution

We cannot activate inspection type for article master in transaction code MM41?

sin(a+b)=sina*cosb+sinb*cosa的推导过程
随机推荐
有能力的人从不抱怨大环境!
Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
ACWING/2004. Misspelling
Blue Bridge Cup SCM module code (timer) (code + comments)
Jameswebb Space Telescope goes into operation to help study interstellar objects
Solar orbiter captured the full picture of the largest prominence eruption in history
keil debug查看变量提示not in scope
Cs8683 (120W mono class D power amplifier IC)
Introduction to sap ui5 tools
How to realize hierarchical management of application and hardware in embedded projects
Are you still doing the dishes yourself? Teach you how to make dishwasher controller with single chip microcomputer
[learn shell programming easily]-5. Plan tasks
【一起上水硕系列】Day 5
Want to self-study SCM, do you have any books and boards worth recommending?
Query process of MySQL secondary index
Torchserve pit avoidance Guide
Kubernetes cluster dashboard & kuboard installation demo
fastadmin 联级清空数据
【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
Americo technology launches professional desktop video editing solution