做者 | 悟鵬
來源 | 阿里巴巴雲原生公衆號node
《Kubernetes 穩定性保障手冊》系列文章:
git
穩定性保障是個複雜的話題,須要有效、可迭代、可持續保障集羣的穩定性,系統性的方法或許能夠解決該問題。
爲了造成系統性的方法,能夠梳理出穩定性保障複雜性的源頭,制定數據模型來對其進行描述,而後在數據模型的基礎上對集羣的穩定性保障進行數字化和可視化,以數據模型爲內核來持續迭代對穩定性保障的理解、實踐以及經驗的固化。
github
穩定性保障的複雜性源頭,通常會有以下維度:
json
總結下來,即:
api
能夠經過 4 張圖和 3 張表對洞察和預案進行數據模型的抽象:
安全
以下:
網絡
集羣的功能由集羣架構提供,功能組件基於集羣資源運行,故對於集羣穩定性的洞察,核心在於把握集羣架構和集羣資源的特徵。
數據結構
集羣架構一般能夠經過圖來表徵,其中節點表徵組件,邊表徵交互關係,經過圖結構能夠直觀把握集羣的架構,形以下圖:
架構
可經過形以下的數據結構描述:app
{ "nodes": [ { "_id": "0ce0e913f6e5516846c654dbd81db6ecab1f684e", "name": "kube-apiserver", "description": "XXX VPC 內", "type": "managed component", "dependencies": {} }, { "_id": "f0740d8bb67520857061a9b71d4a9e4fc50bfe3d", "name": "etcd", "description": "XXX VPC 內", "type": "managed component | storage", "dependencies": {} }, { "_id": "05952a825e91cb50a81cbaf23c6941d5c3bb2c89", "name": "eni-operator", "description": "XXX VPC 內,管理 ENI", "type": "component", "dependencies": { "serviceaccount": "enioperator", "clusterrole": "enioperator", "clusterrolebinding": "enioperator", "configmaps": ["eniconfig"], "secrets": ["enioperator"] } }, { "_id": "42699513a7561e89a5f99881d7b05653a1625c51", "name": "Network Service", "description": "提供 VPC/VSwitch 等雲網絡資源的管理服務", "type": "cloud service" } ], "edges": [ { "_id": "38bce9ca8a0cec6d8586d96298bd63b0523fc946", "source": "eni-operator", "target": "kube-apiserver", "description": "管理 ENI 請求" }, { "_id": "93f3c21247165f0be3a969fc80f72bc1a402e9f5", "source": "eni-operator", "target": "Network Service", "description": "訪問阿里雲 ECS OpenAPI,管理 VPC/VSwitch 等網絡資源" } ] }
集羣運行過程當中,組件及交互關係能夠經過外部觀測數據推測內部狀態,如 log/metrics/trace。與集羣架構圖結合,能夠在靜態架構的基礎上疊加動態的洞察數據,更直觀把握集羣的健康狀態,以下圖:
其中的數字表徵洞察數據,能夠是「異常數量」「請求流量」等。除了經過數字進行洞察,還可使用「顏色表徵健康狀態」「線條粗細表徵流量大小」等。
可經過形以下的數據結構描述:
{ "nodes": [ { "_id": "ea4538dc0625d06b0dc93579998e04288656050f", "name": "mutatehook", "deploy": { "type": "K8s:Deployment", "namespace": "kube-system", "replicas": 3 }, "insight": [ { "source": { "vendor": "cloud:aliyun:sls", "log_project": "xxx", "log_store": "mutatehook", "log_url": "https://sls.console.aliyun.com/lognext/project/xxx" }, "signal": { "exception": { "fuzzy": "fail OR Fail OR error OR Error" } } } ] } ], "edges": [ { "_id": "38bce9ca8a0cec6d8586d96298bd63b0523fc946", "source": "eni-operator", "target": "kube-apiserver", "insight":[ { "source": { "vendor": "cloud:aliyun:sls", "log_project": "xxx", "log_store": "xxx", "log_url": "https://sls.console.aliyun.com/lognext/project/xxx" }, "signal": { "exception": { "unauthorized": "Unauthorized", "throttling": "'Throttling' OR 'throttling'" } } } ] } ] }
資源管理是個複雜的話題,經過分析集羣中資源的構成關係,也能夠嘗試經過圖結構來表徵集羣的資源構成,節點表徵資源,邊表徵資源的從屬或綁定關係。
可經過形以下的數據結構描述:
{ "kinds": ["vpc", "vswitch", "securitygroup", "ecs", "clb", "rds", "nat", "eip"], "tags": { "cluster/product": "xxx", "cluster/id": "2736f42d4e882ad6825d6364545a3f1cb5136859", "cluster/name": "xxx", "cluster/env": "staging" }, "nodes": [ { "kind": "vpc", "nodes": [ { "_id": "c505f21871bac7385c1387988cf226310af0831e", "id": "vpc-xxx", "description": "", "ipv4": "xxx", "tags": { "resource/creator": "product", "resource/role": "" }, "url": "https://vpc.console.aliyun.com/vpc/xxx" } ] }, { "kind": "ecs", "nodes": [ { "_id": "47c4fe5cc2585a49f07798a0b8b69cda7f8d4a23", "id": "xxx", "az": "xxx", "interfaces": { "primary": { "ip": "xxx", "eni": "xxx", "mac": "xxx" } }, "instance-type-family": "xxx", "instance-type": "xxx", "tags": { "resource/creator": "product", "resource/role": "worker", "node/container-runtime": "xxx", "node/user-networking": "xxx", "node/system-networking": "xxx" }, "status": "", "condition": "", "url": "https://ecs.console.aliyun.com/#/server/xxx" } ] } ], "edges": [ { "_id": "a754c748b2723a25c017421dd0969d00df3c000b", "source": "vsw-xxx", "target": "vpc-xxx", "description": "" }, { "_id": "c34b164eba2897cfb2b574a576672d8aa441d709", "source": "eip-xxx", "target": "ngw-xxx", "description": "" } ] }
資源使用過程當中,也能夠對資源及資源間的關係經過外部觀測數據推測內部狀態,如 log/metrics/event。與資源構成圖結合,能夠在靜態資源的基礎上疊加動態的洞察數據,直觀把握集羣資源的使用狀態。
可經過形以下的數據結構描述:
{ "nodes": [ { "_id": "35103ac62d4ef0a314e2a5128f44c684205bea2f", "id": "vpc", "insight": [ { "source": { "vendor": "cloud:aliyun:vpc", "type": "OpenAPI" }, "signal": { "vpc/exist": "DescribeVpcs", "vswitch/count": "DescribeVSwitches" } }, { "source": { "vendor": "cloud:aliyun:ecs", "type": "OpenAPI" }, "signal": { "ecs/count": "DescribeInstances", "securitygroup/count": "DescribeSecurityGroups" } } ] }, { "_id": "6450e07dc67027f76f29fbfcb841e57200855196", "id": "ecs", "insight": [ { "source": { "vendor": "cloud:aliyun:ecs", "type": "OpenAPI" }, "signal": { "ecs/exist": "DescribeInstances", "ecs/count": "DescribeInstances", "ecs/usage": "DescribeInstanceMonitorData" } }, { "source": { "vendor": "cloud:aliyun:ecs", "type": "auto" }, "signal": { "ecs/state_change": "" } } ] } ], "edges": [ { "_id": "caa1e395c713f47766ca7bcfc20419c0be0f0803", "source": "i-xxx", "target": "sg-xxx", "insight": [ { "source": { "vendor": "cloud:aliyun:ecs", "type": "OpenAPI" }, "signal": { "exist": "DescribeInstances" } } ] }, { "_id": "537dc478d95714792b3694674d6164f72b361bb0", "source": "eip-xxx", "target": "ngw-xxx", "insight": [ { "source": { "vendor": "cloud:aliyun:vpc", "type": "OpenAPI" }, "signal": { "exist": "DescribeEipAddresses" } } ] } ] }
集羣出現異常是不可避免的,須要在出現異常時安全、有效處理。
異常能夠經過事件來表徵,安全、有效的操做是通過評審、演練過的操做,將異常與操做結合,由異常觸發操做,造成通過評審、演練的預案,能夠安全有效處理集羣異常。
集羣運行過程當中會產生須要關注的事件,事件自身的格式可基於社區 CloudEvents標準來使用:_https://github.com/cloudevent...
可經過形以下的數據結構描述:
{ "events": [ { "_id": "a1ab5b61857be35a5c5b203dd84b49248161c823", "description": "restart workload manually", "event": { "id": "restart-workload", "source": "xxx", "specversion": "1.0", "type": "com.aliyun.trigger.manual", "datacontenttype": "application/json", "data": "{\"NAMESPACE\": \"\", \"NAME\": \"\", \"TYPE\": \"\"}" } } ] }
爲了下降誤操做的可能性,同時避免異常發生時執行未經審覈、驗證的操做,須要定義集羣中能夠進行的操做列表。
可經過形以下的數據結構描述:
{ "actions": [ { "_id": "47abc5cd9d64018ebf96dc5b2d6a4fbd35a3cb6d", "name": "Action Restart Workload", "exec": "restart-workload", "env": [ "NAMESPACE", "NAME", "TYPE" ] } ] }
在事件列表和操做列表基礎上,能夠將事件和操做關聯起來,以事件驅動的方式處理異常,即預案。
可經過形以下的數據結構描述:
{ "plans": [ { "_id": "29a091c48d8992991ed69e8694b017a11abe3eec", "name": "Plan Restart Workload", "description": "重啓 workload", "event": "a1ab5b61857be35a5c5b203dd84b49248161c823", "actions": ["47abc5cd9d64018ebf96dc5b2d6a4fbd35a3cb6d"] } ] }
基於上述4 張圖和3 張表的數據模型,造成對集羣穩定性保障的洞察+預案的內核,能夠衍生出一種全局可視化的穩定性保障服務。
這樣的服務具備以下關鍵點:
這種服務基於兩種原理實現:
以平常生活中的交通圖爲例:
經過交通圖,能夠快速瞭解到一個區域的道路分佈和關鍵節點,約定俗成的紅黃綠顏色能夠直觀表達道路的擁堵情況。在更豐富的交通圖上,還會觀察到諸如修路、封路等重要事件。
這樣,基於可視化的方式,就能夠迅速理解一個區域的交通和地理狀況。
底層的數據模型是基礎,應用可視化的手段,使得數據的價值更易被髮揮。
根據穩定性保障的最佳實踐,將穩定性保障分爲以下幾個欄目:
運行鏈路圖:
部署架構圖
業務流程圖
數據分析:該欄目服務兩方面的數據需求
業務需求
穩定性保障需求
可觀測性管理
該欄目用管理可觀測性相關事宜,包括:
可控性管理
該欄目用於管理與控制相關的操做,包括:
系統正常運行期間:
在「可控性管理」欄目:
系統異常及恢復期間,在「運行鏈路圖」中:
問題跟蹤過程當中記錄的主要內容有:
數據模型是穩定性保障最佳實踐進行迭代、分享和應用的媒介,通用的洞察和預案能夠造成標準化的服務,個性化的洞察和預案可經過固定的結構來描述,而後使用通用的控制器來落地。
以數據模型造成洞察+預案的穩定性保障服務,技術核心爲:
洞察模型
關鍵問題:
數據模型
關鍵問題:
在技術核心的基礎上,能夠圍繞以下的競爭力進行迭代:
洞察
效率
先進性
經過 Spec 規範 7 種數據模型,咱們能夠基於結構化的描述來表徵洞察+預案。以此爲核心,不斷迭代對穩定性保障的實踐和理解,加速業務迭代。再擴展一步,也有可能基於該模型在發展方向反哺業務。若是你們感興趣,歡迎在留言區進行交流。