Certified Kubernetes是CNCF基金會在2018年推出的Kubernetes一致性認證計劃宇植。它由CNCF基金會提供的一套診斷測試工具(Sonobuoy)并運行在Kubernetes中泥兰。各云廠商如果需要將自己產品納入到Certified Kubernetes當中此疹,就需要按照操作指導進行自身測試臼闻,并將測試結果上傳給CNCF社區(qū)琅束,當報告審核通過搏屑,交付一定的費用(CNCF Members免費)后西剥,就會得到CNCF基金會給企業(yè)頒發(fā)一個Certified Kubernetes的認證。也就是說得到認證后企業(yè)就能在自己的產品宣傳上使用CNCF基金會的Certified Kubernetes商標和在產品中使用帶Kubernetes字樣的名稱译暂。Certified Kubernetes Logo大概長這個樣子抠忘。
Certified Kubernetes好處
-
一致性
只要獲得了一致性認證,用戶在對任何Kubernetes廠商發(fā)行版進行安裝或交互時外永,得到的和原生Kuberentes功能幾乎一致的體驗
-
及時更新
為了保持認證崎脉,CNCF基金會要求廠商需要每年或更頻繁地提供對最版本的Kubernetes支持。通常情況下來說伯顶,廠商提交的產品適配的版本囚灼,為官方最新的次要發(fā)型版本(x.y)以及最近的兩個發(fā)行版(x.y-1 和 x.y-2)
例子骆膝。在Kubernetes v1.23發(fā)布后,新的合格產品最初可以針對Kubernetes v1.23灶体、v1.22或v1.21進行自我認證阅签,但不能針對v1.20再進行測試。
了解Kubernetes的同學都知道蝎抽,K8S幾乎每年會以3-4個大版本進行迭代政钟,這樣就等于讓各大廠商必須跟這個K8S的迭代進行適配。也側面上加強了社區(qū)對于各大廠商的控制
-
可確認性
任何終端用戶都可以通過運行用于認證的相同的開源一致性應用程序(Sonobuoy)來確認他們的發(fā)行版或平臺仍然符合要求樟结,以免用戶被廠商鎖定养交。
Sonobuoy
Sonobuoy 是一個診斷工具,通過它我們可以訪問且以非破壞性的方式運行一組插件(其中包括Kubernetes一致性認證的測試)使我們更輕松地了解 Kubernetes 集群的狀態(tài)瓢宦。同時Sonobuoy 也是一種可定制碎连、可擴展和黑盒的方式生成有關Kubernetes集群的相關報告工具。
我們可以用Sonobuoy來對Kubernetes內的資源做如下用例測試:
- 集成的端到端 (e2e) 一致性測試
- 工作負載調試
- 擴展插件來采集自定義數據
環(huán)境準備
在使用Sonobuoy之前我們需要準備好如下環(huán)境:
- 一個可以正常訪問的Kubernetes集群
- 擁有被測試Kubernetes集群的ADMIN權限驮履,以及它的kubeconfig文件
- kubectl命令(某些告警場景會用鱼辙,Certified Kubernetes不需要)
- sonobuoy的docker鏡像
- 本地的私有化鏡像倉庫
(強烈建議要有!C蹈洹5瓜贰)
安裝
在下述鏈接中下載最新版本的Sonobuoy二進制文件,將它解壓后摘悴,并把可執(zhí)行文件sonobuoy路徑添加到系統的PATH環(huán)境變量下即可峭梳。
https://github.com/vmware-tanzu/sonobuoy/releases
運行測試
標準的一致性測試集目前是由 kubernetes e2e套件中的 [Conformance] 標簽定義的。所以我們需要使用如下命令進行部署蹂喻。
$ sonobuoy run --mode=certified-conformance
INFO[0000] created object name=sonobuoy namespace= resource=namespaces
INFO[0000] created object name=sonobuoy-serviceaccount namespace=sonobuoy resource=serviceaccounts
INFO[0001] created object name=sonobuoy-serviceaccount-sonobuoy namespace= resource=clusterrolebindings
INFO[0001] created object name=sonobuoy-serviceaccount-sonobuoy namespace= resource=clusterroles
INFO[0001] created object name=sonobuoy-config-cm namespace=sonobuoy resource=configmaps
INFO[0001] created object name=sonobuoy-plugins-cm namespace=sonobuoy resource=configmaps
INFO[0001] created object name=sonobuoy namespace=sonobuoy resource=pods
INFO[0001] created object name=plugin-e2e-cm namespace=sonobuoy resource=configmaps
INFO[0001] created object name=sonobuoy-aggregator namespace=sonobuoy resource=services
當sonobuoy容器正常運后葱椭,它就會開始創(chuàng)建e2e容器和systemd-log容器開始進行相關的測試和日志收集。
$ kubectl get pod -n sonobuoy
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sonobuoy 1/1 Running 0 31s 192.169.15.126 k8s-master3-123 <none> <none>
sonobuoy-e2e-job-23d08735503942f5 2/2 Running 0 27s 192.169.15.86 k8s-master3-123 <none> <none>
sonobuoy-systemd-logs-daemon-set-c7fe30c923a848d5-c7wvz 2/2 Running 0 27s 172.16.23.123 k8s-master3-123 <none> <none>
sonobuoy-systemd-logs-daemon-set-c7fe30c923a848d5-d28gr 2/2 Running 0 27s 172.16.23.122 k8s-master2-122 <none> <none>
sonobuoy-systemd-logs-daemon-set-c7fe30c923a848d5-q25t8 2/2 Running 0 27s 172.16.23.124 k8s-node1-124 <none> <none>
sonobuoy-systemd-logs-daemon-set-c7fe30c923a848d5-wkd4f 2/2 Running 0 27s 172.16.23.125 k8s-node2-125 <none> <none>
sonobuoy-systemd-logs-daemon-set-c7fe30c923a848d5-z829h 2/2 Running 0 27s 172.16.23.121 k8s-master1-121 <none> <none>
在測試的進行過程中口四,我們可以使用sonobuoy status
命令進行查看當前任務的執(zhí)行狀態(tài)孵运,可以用sonobuoy logs
來查看用例的執(zhí)行日志。
提示:certified-conformance測試通常會跑1 - 2個小時
當我們用sonobuoy status
發(fā)現狀態(tài)都為completed
時蔓彩,就代表一致性測試運行完成治笨。
定制鏡像(可選)
如果你的Kubernetes網絡足夠科學可以跳過此步驟。
眾所周知赤嚼,Docker Hub在今年開啟了對Pull鏡像的請求限制旷赖,而我們運行sonobuoy是,有大量用例都會從Docker Hub或者gcr.io上去拉取鏡像更卒,如果網絡不穩(wěn)定的話等孵,整個測試時間會被拉的非常長,且極容易出現用例執(zhí)行超時失敗的現象蹂空。所以我們需要將線上鏡像離線到本地鏡像倉庫俯萌,以加速鏡像的下載果录。
好在sonobuoy提供了修改插件鏡像地址的方式來讓我們配置。
私有測試用例鏡像倉庫
- 下載測試用例所需的鏡像列表
$ sonobuoy images pull
INFO[0000] e2e image to be used: k8s.gcr.io/conformance:v1.18.16
INFO[0005] Pulling image: gcr.io/authenticated-image-pulling/alpine:3.7 ...
ERRO[0010] failed with following error after 1 retries:
ERRO[0010] Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
INFO[0014] Pulling image: invalid.com/invalid/alpine:3.1 ...
ERRO[0016] failed with following error after 1 retries:
ERRO[0016] Error response from daemon: Get https://invalid.com/v2/: remote error: tls: handshake failure
INFO[0017] Pulling image: gcr.io/authenticated-image-pulling/windows-nanoserver:v1 ...
ERRO[0020] failed with following error after 1 retries:
ERRO[0020] Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
INFO[0023] Pulling image: gcr.io/k8s-authenticated-test/agnhost:2.6 ...
ERRO[0027] failed with following error after 1 retries:
ERRO[0027] Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
ERRO[0027] couldn't pull image: gcr.io/authenticated-image-pulling/alpine:3.7: exec: already started
ERRO[0027] couldn't pull image: invalid.com/invalid/alpine:3.1: exec: already started
ERRO[0027] couldn't pull image: gcr.io/authenticated-image-pulling/windows-nanoserver:v1: exec: already started
ERRO[0027] couldn't pull image: gcr.io/k8s-authenticated-test/agnhost:2.6: exec: already started
在運行上述命令時咐熙,可能會看到一些類似
鏡像不存在
或者無權限pull鏡像
的錯誤弱恒。這是正常的,因為有些鏡像被一些端到端測試所引用棋恼,但不被一致性測試所引用返弹。
- 創(chuàng)建鏡像倉庫列表
$ sonobuoy gen default-image-config > custom-repo-config.yaml
$ cat ./custom-repo-config.yaml
dockerLibraryRegistry: docker.io/library
e2eRegistry: gcr.io/kubernetes-e2e-test-images
gcRegistry: k8s.gcr.io
googleContainerRegistry: gcr.io/google-containers
sampleRegistry: gcr.io/google-samples
- 修改custom-repo-config.yaml為你的本地倉庫
$ cat ./custom-repo-config.yaml
dockerLibraryRegistry: xxx.yyy.zzz/library
e2eRegistry: xxx.yyy.zzz/library
gcRegistry: xxx.yyy.zzz/library
googleContainerRegistry: xxx.yyy.zzz/library
sampleRegistry: xxx.yyy.zzz/library
- 推送鏡像到本地倉庫
sonobuoy images push --e2e-repo-config <path/to/custom-repo-config.yaml>
私有Sonobuoy鏡像
Sonobuoy提供幾個參數讓我們來制定私有鏡像啟動
--systemd-logs-image #指定日志采集鏡像
--sonobuoy-image # 指定Sonobuoy鏡像
--e2e-repo-config # 指定Sonobuoy用例鏡像配置
那么最后我們可以用如下命令就能在自己私有化環(huán)境里面進行測試了
$ sonobuoy run \
--mode=certified-conformance \
--sonobuoy-image=xxx.yyy.zzz/library/sonobuoy:v0.53.2 \
--kubernetes-version=v1.18.16 \
--systemd-logs-image=xxx.yyy.zzz/library/systemd-logs:v0.3 \
--e2e-repo-config conformance-image-config.yaml
提取結果
運行命令sonobuoy retrieve
就會把當前跑完的測試結果以tar包的方式保存在當前目錄,對它進行解壓就得到了類似如下目錄結構的文件
$ tree -L 2
.
├── 202108180508_sonobuoy_ff7aa0c1-34cb-4375-a09e-153235a96d34.tar.gz
├── hosts
│ ├── k8s-master1-121
│ ├── k8s-master2-122
│ ├── k8s-master3-123
│ ├── k8s-node1-124
│ └── k8s-node2-125
├── meta
│ ├── config.json
│ ├── info.json
│ ├── query-time.json
│ └── run.log
├── plugins
│ ├── e2e
│ └── systemd-logs
├── podlogs
│ └── sonobuoy
├── resources
│ ├── cluster
│ └── ns
├── servergroups.json
└── serverversion.json
需要提交給CNCF社區(qū)的兩個文件就位于plugins/e2e/results/global/{e2e.log,junit_01.xml}
上傳結果
在Github上Fork社區(qū)的[cncf/k8s-conformance]到自己的倉庫蘸泻,并在指定的Kubernetes目錄下創(chuàng)建一個目錄琉苇。目錄要求是一個簡短的產品名稱。同時將e2e.log
和junit_01.xml
兩個文件伙同產品描述文件(PRODUCT.yaml)
一起保存在目錄下悦施。
PRODUCT.yaml的內容描述
字段 | Description |
---|---|
vendor |
認證的法律實體的名稱。該實體必須有一份在CNCF備案的參與表格去团。 |
name |
被Certified Kubernetes認證的產品名稱 |
version |
被Certified Kubernetes認證的產品版本(非Kubernetes版本) |
website_url |
產品介紹地址 |
repo_url |
如果產品是開源的抡诞,就必須指向包含源代碼的主要GitHub repo地址。也是可以接受Docker鏡像地址土陪≈绾梗可選的 |
documentation_url |
產品文檔地址 |
product_logo_url |
產品Logo地址(必須是 SVG、AI 或者 EPS 格式鬼雀,且需包含產品名稱)顷窒,如果沒有則使用公司的Logo |
type |
產品類型,包含三種 發(fā)行版( product a distribution), 托管平臺(hosted platform) 或者安裝器(installer) |
description |
一句話的產品描述文字 |
如下就是一個樣例
vendor: Yoyodyne
name: Turbo Encabulator
version: v1.7.4
website_url: https://yoyo.dyne/turbo-encabulator
repo_url: https://github.com/yoyo.dyne/turbo-encabulator
documentation_url: https://yoyo.dyne/turbo-encabulator/docs
product_logo_url: https://yoyo.dyne/assets/turbo-encabulator.svg
type: distribution
description: 'The Yoyodyne Turbo Encabulator is a superb Kubernetes distribution for all of your Encabulating needs.'
接下來我們就可以提交一個PR來讓CNCF社區(qū)人員來進行復核了源哩,通常情況下會在提交后的3個工作日內回復鞋吉。
清理環(huán)境
運行sonobuoy delete
命令即可完成整個測試過程中產生的K8S資源。
不過如果sonobuoy的測試用例執(zhí)行失敗后不會自動清除励烦,需要用戶執(zhí)行清理殘留資源
總結
本文主要講述了小白對CNCF社區(qū)對Kubernetes一致性認證的理解谓着,以及如何利用Sonobuoy工具來對自己的Kubernetes集群做集成測試。Sonobuoy是一個非常好的集成測試工具坛掠,它除了能做Kubernetes一致性測試外赊锚,還能做性能測試、存儲測試以及廠商自定義的測試屉栓。同時舷蒲,本文還對提交Certified Kubernetes做了一個簡單的流程說明。如果有讀者的公司正在做相關的工作的話友多,希望能夠幫到你牲平。