Weitere ähnliche Inhalte Ähnlich wie Extend the Kubernetes API with CRD and Custom API Server (20) Mehr von inwin stack (20) Extend the Kubernetes API with CRD and Custom API Server1. Kyle bai
R&D @ inwinSTACK
www.inwinstack.com
Extend the Kubernetes API with CRD and
Custom API Server
2. Job
R&D @ inwinSTACK
Description
早期在校主要撰寫 java 與 objc 程式語⾔言,並專注於 iOS
Mobile 應⽤用程式開發,具備四年年開發經驗。次要研讀
Hadoop 與 Spark 資料運算框架,以及 Linux 相關技術。
研所與⼯工作期間則專注於 OpenStack、Ceph 與
Kubernetes 等雲原⽣生相關技術開源專案,閒暇之餘會參參加
相關專案社區及貢獻,並利利⽤用部落落格、GitHub 與 GitBook
進⾏行行筆記記錄。
Drink Coffee
Good!
Phone
#7727
Love
Buttocks
kairen(kyle.b@inwinstack.com)
https://kairen.github.io/
About Me
Kyle Bai
3. Kubernetes
47%
Containers remain the top emerging
technology of interest to users. Among
those currently deploying container
orchestration or platform services on
OpenStack, 47% are using Kubernetes.
Why Kubernetes?
Kubernetes API Server
Extend the Kubernetes with CRD
Extend the Kubernetes with apiserver-builder
Agenda
Today I will talk about
5. Kubernetes
Kubernetes 是 Google 開源的容器(Container)分散式管理理系統,是
Google Brog ⼗十幾年年以來來⼤大規模應⽤用容器技術的經驗累積和昇華的⼀一個
重要成果,是建於 Container(OCI容器標準)之上的容器叢集排程系統,
簡稱為K8s( )。
為 CNCF(Cloud Native Computing Foundation) 專案之⼀一。
Stars
25,830+
Commits
52,905+
Contributors
1,331+
16. Kubernetes API driven
Kubernetes API 是以 JSON 作為其主要序列列化模型的 HTTP API,且能夠⽀支
援協定快取區,並⽤用於叢集內部溝通使⽤用。
• 通過 API 完成節點之間溝通進⾏行行 CRUD 操作,或是授權、認證與註冊等。
• Kubernetes 有明確定義與規範 API。⽀支援 OpenAPI。
• 使⽤用 gRPC 進⾏行行 Remote Procedure Call。
• 可擴展的 API。
• CRD(Custom Resource Definitions)
• API server aggregation
• Custom resources and controllers
18. API Levels
在 Kubernetes 中,不同版本的 API 意味著不同層級穩定度與⽀支援度:
• Alpha level:在預設下是⼤大多情況禁⽌止使⽤用狀狀態,這些功能有可能隨時在下⼀一
版本被遺棄,因此只適⽤用於測試⽤用,Example: v1alpha1。
• Beta level: 在這級別⼀一般預設會啟⽤用,這表⽰示該功能已經過很好的測試項
⽬目,但是物件內容可能會在後續版本或穩定版本發⽣生變化。Example:
v1beta2。
• Stable level:在這級別表⽰示該功能已經穩定,會很長的時間⼀一直存在。
Example: v1。
20. API Terminology(2/2)
• API Group:是邏輯上相關的種類集合,如 Job 與 CronJob 都屬於批次處理理功能相
關。
• Version: 每個 API Group 存在多個版本,這些版本區分不同穩定度層級,⼀一般功能會
從 v1alpha1 升級到 v1beta1,然後在 v1 成為穩定版本。
• Resource: 資源是透過 HTTP 發送與檢索的系統實體,其以 JSON 來來表⽰示。可以是
單⼀一或者多個資源。
21. Request Flow and Processing(1/4)
https://github.com/kubernetes/apiserver/blob/master/pkg/server/config.go
• 在 DefaultBuildHandlerChain() 做
操作過濾處理理。
• 透過 Multiplexer 來來依據 HTTP 路路
徑將請求路路由到對應 Handlers。
• 利利⽤用 Routes 來來將 HTTP 路路徑與
Handlers 進⾏行行連接。
• Handlers 獲取 HTTP 請求與上下⽂文
( User, Auth 等),並從儲存中取得
物件實體。
22. Request Flow and Processing(2/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
23. Request Flow and Processing(3/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
24. Request Flow and Processing(4/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
26. Validation and Admission
• Admission:透過驗證叢集的全域約束來來檢查是否建立或更更新 API 物件,在
Kubernetes 中有很多這樣功能。幾個約束範例例:
• NamespaceLifecycle: 如果命名空間不存在,則拒絕該所有請求。
• ResourceQuota:為叢集的當前使⽤用者強制執⾏行行額度限制。
• Validation:檢查傳入的物件(建立與更更新過程)的格式是否符合。例例如:
• 檢查所有的字串串是否是有效的格式。
• 檢查是否有設定⽭矛盾欄欄位。
35. Operators
Operator 是 CoreOS 開發的框架,⽬目標是簡化複雜有狀狀態應⽤用的管理理,它能
夠達到應⽤用程式的狀狀態事件變化,並利利⽤用控制器來來透過擴展的 Kubernetes API
進⾏行行⾃自動建立、管理理與配置應⽤用程式容器實例例。
36. Use case - rook.io(1/3)
rook.io: ⼀一款⽀支援檔案系統、區塊儲存與物件儲存服務的雲原⽣生儲存系統。(Ceph 改良版
on Kubenretes)。
38. Use case - rook.io(3/3)
Rook 使⽤用 CRD 來來定義建立 Pool 與
Filesystem 資源,以提供 Rook
operator 存取並建立對應服務。
39. Use case - TensorFlow(1/3)
https://github.com/tensorflow/k8s
Kubernetes Custom Resource and Operator For TensorFlow jobs.
46. apiserver-builder cmd
# 初始化
$ cd GOPATH/src/github.com/my-org/my-project
$ apiserver-boot init repo --domain <your-domain>
# 建立資源
$ apiserver-boot create group version resource --group <group> --version <version> --kind <Kind>
# 編譯執⾏行行檔
$ apiserver-boot build executables
$ apiserver-boot build docs
# 在 local 執⾏行行
$ apiserver-boot run local
# 在叢集執⾏行行
$ apiserver-boot run in-cluster --name nameofservicetorun --namespace default --image gcr.io/myrepo/
myimage:mytag
$ kubectl create -f sample/<type>.yaml