SlideShare a Scribd company logo
1 of 46
Download to read offline
Kyle bai
R&D @ inwinSTACK
www.inwinstack.com
Build your own Kubernetes apiserver
and resource type
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
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
Why Kubernetes?
Kubernetes
Kubernetes 是 Google 開源的容器(Container)分散式管理理系統,是
Google Brog ⼗十幾年年以來來⼤大規模應⽤用容器技術的經驗累積和昇華的⼀一個
重要成果,是建於 Container(OCI容器標準)之上的容器叢集排程系統,
簡稱為K8s( )。
為 CNCF(Cloud Native Computing Foundation) 專案之⼀一。
Stars
25,830+
Commits
52,905+
Contributors
1,331+
CNCF Landscape
CNCF Members
Container Management Platforms
Preferences
Kubernetes Pros
資源監控
Monitoring
滾動升級
Rolling-update
⾼高可靠性
High-availability
⾃自我修復
Self-healing
雲端⽀支援
Cloud Provider
持久性儲存
Persistent Volumes
組態檔案
Configmap
安全性
Secret
Kubernetes 管理理跨區域與主機的容器節點,提供基本部署、維運、管
理理,以及執⾏行行各項應⽤用程式,並具備多種特性。
Microservices
Kubernetes 架構設計非常適合在微服務(Microservices)軟體架構,透
過多個容器(Container)與負載平衡等來來組成系統。
Kubernetes Distributions
Kubernetes API Server
Kubernetes Architecture(1/2)
Kubernetes 屬於分散式架構系統,主要由兩兩種節點⾓角⾊色組成:
• Masters – 主要提供 API、管理理⼯工作節點與排程等,為主節點。
• Nodes(Minions) – 主要執⾏行行容器應⽤用的節點,上⾯面會執⾏行行許多
容器。
Kubernetes Architecture(2/2)
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
HTTP API spaces
由於其可擴展性, Kubernetes ⽀支援不同 API 路路徑版本,比如 /api/v1或/apis/
extensions/v1beta1。
API Levels
在 Kubernetes 中,不同版本的 API 意味著不同層級穩定度與⽀支援度:
• Alpha level:在預設下是⼤大多情況禁⽌止使⽤用狀狀態,這些功能有可能隨時在下⼀一
版本被遺棄,因此只適⽤用於測試⽤用,Example: v1alpha1。
• Beta level: 在這級別⼀一般預設會啟⽤用,這表⽰示該功能已經過很好的測試項
⽬目,但是物件內容可能會在後續版本或穩定版本發⽣生變化。Example:
v1beta2。
• Stable level:在這級別表⽰示該功能已經穩定,會很長的時間⼀一直存在。
Example: v1。
API Terminology(1/2)
• Kind:是⼀一個實體(Entity)的類型,每個
Kubernetes 物件都會有⼀一個欄欄位 Kind。
1. 物件表⽰示系統中的⼀一個持久實體,如 Pod
與 Namespace。
2. ⼀一個多種實體的資源集合列列表,如
PodLists, NodeLists。
3. 特殊⽤用途類型⽤用於物件與非持久實體的特
定操作,如 /binding, /status 這些⽤用來來取得
API Group 與 Resource 的錯誤狀狀態。
API Terminology(2/2)
• API Group:是邏輯上相關的種類集合,如 Job 與 CronJob 都屬於批次處理理功能相
關。
• Version: 每個 API Group 存在多個版本,這些版本區分不同穩定度層級,⼀一般功能會
從 v1alpha1 升級到 v1beta1,然後在 v1 成為穩定版本。
• Resource: 資源是透過 HTTP 發送與檢索的系統實體,其以 JSON 來來表⽰示。可以是
單⼀一或者多個資源。
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 等),並從儲存中取得
物件實體。
Request Flow and Processing(2/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
Request Flow and Processing(3/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
Request Flow and Processing(4/4)
https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
Cluster state in Etcd
Validation and Admission
• Admission:透過驗證叢集的全域約束來來檢查是否建立或更更新 API 物件,在
Kubernetes 中有很多這樣功能。幾個約束範例例:
• NamespaceLifecycle: 如果命名空間不存在,則拒絕該所有請求。
• ResourceQuota:為叢集的當前使⽤用者強制執⾏行行額度限制。
• Validation:檢查傳入的物件(建立與更更新過程)的格式是否符合。例例如:
• 檢查所有的字串串是否是有效的格式。
• 檢查是否有設定⽭矛盾欄欄位。
YAML file to define resource
Example resource:
Extend the Kubernetes with CRD
CustomResourceDefinitions(CRD)
CustomResourceDefinition(CRD) 是 v1.7+ 版本新加入的 Kubernetes API 擴
展機制,⽬目標是無需修改核⼼心程式碼就能對 Kubernetes 進⾏行行擴展,⽽而 CRD 更更
是 ThirdPartyResources(TPR) 的升級版。
• 使⽤用⾃自定義物件進⾏行行擴展 Kubernetes API.
• CRDs 能夠沿⽤用熟係的 UX ⼯工具,ex: kubectl.
• 能夠與 Controllers 進⾏行行結合.
• ⽀支援 SubResources(v1.9).
P.S. TPR 在 v1.8 版本已被遺棄。
CRD Example(1/2)
CRD Example(2/2)
Add Controller to Handle events
How CRD works internally(1/2)
Creating a CRD
How CRD works internally(2/2)
Creating a CustomResource
Use case - rook.io(1/2)
rook.io: ⼀一款⽀支援檔案系統、區塊儲存與物件儲存服務的雲原⽣生儲存系統。(Ceph 改良版
on Kubenretes)。
Use case - rook.io (2/2)
Rook 使⽤用 CRD 來來定義建立 Pool 與
Filesystem 資源,以提供 Rook
operator 存取並建立對應服務。
Use case - TensorFlow(1/3)
https://github.com/tensorflow/k8s
Kubernetes Custom Resource and Operator For TensorFlow jobs.
Use case - TensorFlow(2/3)
Use case - TensorFlow(3/3)
Refer projects
• code-generator
• crd-code-generation
• apiextensions-apiserver
• sample-apiserver
• sample-controller
• apimachinery
Extend the Kubernetes API with apiserver-builder
apiserver-builder
apiserver-builder 是⼀一個實作快速建構 Kubernetes apiserver 與⾃自定義資源類
型的⼯工具與函式庫,該⼯工具具備了了以下幾個特性:
• 能夠⼀一次建立新資源類型、控制器、測試函式與⽂文件。
• 能夠建構與執⾏行行於 Standalone, Minikube 與遠端叢集。
• 能夠簡單地從控制器(Controller)來來觀看與更更新 Kubernetes API 資源類型。
• 很簡單的加入新資源與⼦子資源。
• 為⼤大多數欄欄位提供預設值,且能夠被覆蓋。
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
apiserver-builder storage operations
Demo
Refer projects
• apiserver-builder/example
• kube-openapi
• service-catalog
46
有任何問題與想法,可以⼀一起討論唷。
Thank You!!

More Related Content

What's hot

Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)
Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)
Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)YIYANG Lin
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
AKS 與開發人員體驗 (Kubernetes 大講堂)
AKS 與開發人員體驗 (Kubernetes 大講堂)AKS 與開發人員體驗 (Kubernetes 大講堂)
AKS 與開發人員體驗 (Kubernetes 大講堂)Will Huang
 
企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養Philip Zheng
 
Cloudstack dev/user sharing
Cloudstack dev/user sharingCloudstack dev/user sharing
Cloudstack dev/user sharinggavin_lee
 
容器式軟體開發介紹
容器式軟體開發介紹容器式軟體開發介紹
容器式軟體開發介紹Philip Zheng
 
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)Will Huang
 
容器式基礎架構介紹
容器式基礎架構介紹容器式基礎架構介紹
容器式基礎架構介紹Philip Zheng
 
Docker open stack
Docker open stackDocker open stack
Docker open stackGuangya Liu
 
Windows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, KubernetesWindows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, KubernetesWill Huang
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShopPhilip Zheng
 
RxJS 6 新手入門
RxJS 6 新手入門RxJS 6 新手入門
RxJS 6 新手入門Will Huang
 
2019 Cloud Native Forum, Taipei
2019 Cloud Native Forum, Taipei2019 Cloud Native Forum, Taipei
2019 Cloud Native Forum, TaipeiYiDeWu1
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer TalkLarry Cai
 
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 TaiwanAzure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 TaiwanWill Huang
 
Docker集群管理 工具篇
Docker集群管理 工具篇Docker集群管理 工具篇
Docker集群管理 工具篇Guangya Liu
 
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽Will Huang
 
Wot2013云计算架构师峰会 -陈轶飞2
Wot2013云计算架构师峰会 -陈轶飞2Wot2013云计算架构师峰会 -陈轶飞2
Wot2013云计算架构师峰会 -陈轶飞2dotCloud
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Miles Chou
 

What's hot (20)

Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)
Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)
Kubeflow Machine Learning Toolkit for Kubernetes (SDN x Cloud Native Meetup #4)
 
微服務自己動手做
微服務自己動手做微服務自己動手做
微服務自己動手做
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
AKS 與開發人員體驗 (Kubernetes 大講堂)
AKS 與開發人員體驗 (Kubernetes 大講堂)AKS 與開發人員體驗 (Kubernetes 大講堂)
AKS 與開發人員體驗 (Kubernetes 大講堂)
 
企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養
 
Cloudstack dev/user sharing
Cloudstack dev/user sharingCloudstack dev/user sharing
Cloudstack dev/user sharing
 
容器式軟體開發介紹
容器式軟體開發介紹容器式軟體開發介紹
容器式軟體開發介紹
 
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
 
容器式基礎架構介紹
容器式基礎架構介紹容器式基礎架構介紹
容器式基礎架構介紹
 
Docker open stack
Docker open stackDocker open stack
Docker open stack
 
Windows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, KubernetesWindows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, Kubernetes
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShop
 
RxJS 6 新手入門
RxJS 6 新手入門RxJS 6 新手入門
RxJS 6 新手入門
 
2019 Cloud Native Forum, Taipei
2019 Cloud Native Forum, Taipei2019 Cloud Native Forum, Taipei
2019 Cloud Native Forum, Taipei
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer Talk
 
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 TaiwanAzure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
 
Docker集群管理 工具篇
Docker集群管理 工具篇Docker集群管理 工具篇
Docker集群管理 工具篇
 
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
 
Wot2013云计算架构师峰会 -陈轶飞2
Wot2013云计算架构师峰会 -陈轶飞2Wot2013云计算架构师峰会 -陈轶飞2
Wot2013云计算架构师峰会 -陈轶飞2
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
 

Viewers also liked

The Future of Apache Storm
The Future of Apache StormThe Future of Apache Storm
The Future of Apache StormP. Taylor Goetz
 
OVN: Scaleable Virtual Networking for Open vSwitch
OVN: Scaleable Virtual Networking for Open vSwitchOVN: Scaleable Virtual Networking for Open vSwitch
OVN: Scaleable Virtual Networking for Open vSwitchmestery
 
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Ambassador Labs
 
利用K8S實現高可靠應用
利用K8S實現高可靠應用利用K8S實現高可靠應用
利用K8S實現高可靠應用inwin stack
 
Network plugins for kubernetes
Network plugins for kubernetesNetwork plugins for kubernetes
Network plugins for kubernetesinwin stack
 
Virtualization inside kubernetes
Virtualization inside kubernetesVirtualization inside kubernetes
Virtualization inside kubernetesinwin stack
 
Cantainer CI/ CD with Kubernetes
Cantainer CI/ CD with KubernetesCantainer CI/ CD with Kubernetes
Cantainer CI/ CD with Kubernetesinwin stack
 
Distributed tensorflow on kubernetes
Distributed tensorflow on kubernetesDistributed tensorflow on kubernetes
Distributed tensorflow on kubernetesinwin stack
 
How to integrate Kubernetes in OpenStack: You need to know these project
How to integrate Kubernetes in OpenStack: You need to know these projectHow to integrate Kubernetes in OpenStack: You need to know these project
How to integrate Kubernetes in OpenStack: You need to know these projectinwin stack
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureP. Taylor Goetz
 
Microservices: Notes From The Field
Microservices: Notes From The FieldMicroservices: Notes From The Field
Microservices: Notes From The FieldApcera
 

Viewers also liked (11)

The Future of Apache Storm
The Future of Apache StormThe Future of Apache Storm
The Future of Apache Storm
 
OVN: Scaleable Virtual Networking for Open vSwitch
OVN: Scaleable Virtual Networking for Open vSwitchOVN: Scaleable Virtual Networking for Open vSwitch
OVN: Scaleable Virtual Networking for Open vSwitch
 
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
 
利用K8S實現高可靠應用
利用K8S實現高可靠應用利用K8S實現高可靠應用
利用K8S實現高可靠應用
 
Network plugins for kubernetes
Network plugins for kubernetesNetwork plugins for kubernetes
Network plugins for kubernetes
 
Virtualization inside kubernetes
Virtualization inside kubernetesVirtualization inside kubernetes
Virtualization inside kubernetes
 
Cantainer CI/ CD with Kubernetes
Cantainer CI/ CD with KubernetesCantainer CI/ CD with Kubernetes
Cantainer CI/ CD with Kubernetes
 
Distributed tensorflow on kubernetes
Distributed tensorflow on kubernetesDistributed tensorflow on kubernetes
Distributed tensorflow on kubernetes
 
How to integrate Kubernetes in OpenStack: You need to know these project
How to integrate Kubernetes in OpenStack: You need to know these projectHow to integrate Kubernetes in OpenStack: You need to know these project
How to integrate Kubernetes in OpenStack: You need to know these project
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm Architecture
 
Microservices: Notes From The Field
Microservices: Notes From The FieldMicroservices: Notes From The Field
Microservices: Notes From The Field
 

Similar to Build your own kubernetes apiserver and resource type

Langchain and Azure ML and Open AI
Langchain and Azure ML and Open AILangchain and Azure ML and Open AI
Langchain and Azure ML and Open AIKo Ko
 
ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享國昭 張
 
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0) 開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0) My own sweet home!
 
Ceph customize ap is for programmatic access with python
Ceph customize ap is for programmatic access with pythonCeph customize ap is for programmatic access with python
Ceph customize ap is for programmatic access with pythonBo-Yu Chen
 
Train.IO 【第六期-OpenStack 二三事】
Train.IO 【第六期-OpenStack 二三事】Train.IO 【第六期-OpenStack 二三事】
Train.IO 【第六期-OpenStack 二三事】inwin stack
 
Introduction to K8S Big Data SIG
Introduction to K8S Big Data SIGIntroduction to K8S Big Data SIG
Introduction to K8S Big Data SIGJazz Yao-Tsung Wang
 
北護大/FHIR 開發簡介與應用
北護大/FHIR 開發簡介與應用北護大/FHIR 開發簡介與應用
北護大/FHIR 開發簡介與應用Lorex L. Yang
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17twMVC
 
Hyper: 让Pod以VM为边界
Hyper: 让Pod以VM为边界Hyper: 让Pod以VM为边界
Hyper: 让Pod以VM为边界Xu Wang
 
99cloud openstack ci
99cloud openstack ci99cloud openstack ci
99cloud openstack ciLiang Bo
 
Elastic stack day-1
Elastic stack day-1Elastic stack day-1
Elastic stack day-1YI-CHING WU
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CDChen-Tien Tsai
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdfssuserd6c7621
 
Openstack document for apac v3
Openstack document for apac v3Openstack document for apac v3
Openstack document for apac v3OpenCity Community
 
51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundry51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundryHong Cai
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发topgeek
 
架設Hadoop叢集以及mapreduce開發環境
架設Hadoop叢集以及mapreduce開發環境架設Hadoop叢集以及mapreduce開發環境
架設Hadoop叢集以及mapreduce開發環境Phate334
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
离线应用分享
离线应用分享离线应用分享
离线应用分享gzterrytan
 

Similar to Build your own kubernetes apiserver and resource type (20)

Langchain and Azure ML and Open AI
Langchain and Azure ML and Open AILangchain and Azure ML and Open AI
Langchain and Azure ML and Open AI
 
ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享
 
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0) 開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
 
Ceph customize ap is for programmatic access with python
Ceph customize ap is for programmatic access with pythonCeph customize ap is for programmatic access with python
Ceph customize ap is for programmatic access with python
 
Train.IO 【第六期-OpenStack 二三事】
Train.IO 【第六期-OpenStack 二三事】Train.IO 【第六期-OpenStack 二三事】
Train.IO 【第六期-OpenStack 二三事】
 
Introduction to K8S Big Data SIG
Introduction to K8S Big Data SIGIntroduction to K8S Big Data SIG
Introduction to K8S Big Data SIG
 
北護大/FHIR 開發簡介與應用
北護大/FHIR 開發簡介與應用北護大/FHIR 開發簡介與應用
北護大/FHIR 開發簡介與應用
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17
 
Hyper: 让Pod以VM为边界
Hyper: 让Pod以VM为边界Hyper: 让Pod以VM为边界
Hyper: 让Pod以VM为边界
 
99cloud openstack ci
99cloud openstack ci99cloud openstack ci
99cloud openstack ci
 
Elastic stack day-1
Elastic stack day-1Elastic stack day-1
Elastic stack day-1
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CD
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf
 
Openstack document for apac v3
Openstack document for apac v3Openstack document for apac v3
Openstack document for apac v3
 
51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundry51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundry
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发
 
架設Hadoop叢集以及mapreduce開發環境
架設Hadoop叢集以及mapreduce開發環境架設Hadoop叢集以及mapreduce開發環境
架設Hadoop叢集以及mapreduce開發環境
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
Html5
Html5Html5
Html5
 
离线应用分享
离线应用分享离线应用分享
离线应用分享
 

More from inwin stack

Migrating to Cloud Native Solutions
Migrating to Cloud Native SolutionsMigrating to Cloud Native Solutions
Migrating to Cloud Native Solutionsinwin stack
 
Cloud Native 下的應用網路設計
Cloud Native 下的應用網路設計Cloud Native 下的應用網路設計
Cloud Native 下的應用網路設計inwin stack
 
當電子發票遇見 Google Cloud Function
當電子發票遇見 Google Cloud Function當電子發票遇見 Google Cloud Function
當電子發票遇見 Google Cloud Functioninwin stack
 
運用高效、敏捷全新平台極速落實雲原生開發
運用高效、敏捷全新平台極速落實雲原生開發運用高效、敏捷全新平台極速落實雲原生開發
運用高效、敏捷全新平台極速落實雲原生開發inwin stack
 
The last mile of digital transformation AI大眾化:數位轉型的最後一哩
The last mile of digital transformation AI大眾化:數位轉型的最後一哩The last mile of digital transformation AI大眾化:數位轉型的最後一哩
The last mile of digital transformation AI大眾化:數位轉型的最後一哩inwin stack
 
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案inwin stack
 
An Open, Open source way to enable your Cloud Native Journey
An Open, Open source way to enable your Cloud Native JourneyAn Open, Open source way to enable your Cloud Native Journey
An Open, Open source way to enable your Cloud Native Journeyinwin stack
 
維運Kubernetes的兩三事
維運Kubernetes的兩三事維運Kubernetes的兩三事
維運Kubernetes的兩三事inwin stack
 
Serverless framework on kubernetes
Serverless framework on kubernetesServerless framework on kubernetes
Serverless framework on kubernetesinwin stack
 
Web後端技術的演變
Web後端技術的演變Web後端技術的演變
Web後端技術的演變inwin stack
 
以 Kubernetes 部屬 Spark 大數據計算環境
以 Kubernetes 部屬 Spark 大數據計算環境以 Kubernetes 部屬 Spark 大數據計算環境
以 Kubernetes 部屬 Spark 大數據計算環境inwin stack
 
Setup Hybrid Clusters Using Kubernetes Federation
Setup Hybrid Clusters Using Kubernetes FederationSetup Hybrid Clusters Using Kubernetes Federation
Setup Hybrid Clusters Using Kubernetes Federationinwin stack
 
基於 K8S 開發的 FaaS 專案 - riff
基於 K8S 開發的 FaaS 專案 - riff基於 K8S 開發的 FaaS 專案 - riff
基於 K8S 開發的 FaaS 專案 - riffinwin stack
 
使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster 使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster inwin stack
 
利用K8S實現高可靠應用
利用K8S實現高可靠應用利用K8S實現高可靠應用
利用K8S實現高可靠應用inwin stack
 
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)inwin stack
 
Distributed tensorflow on kubernetes
Distributed tensorflow on kubernetesDistributed tensorflow on kubernetes
Distributed tensorflow on kubernetesinwin stack
 
Kubernetes 架構與虛擬化之差異
Kubernetes 架構與虛擬化之差異Kubernetes 架構與虛擬化之差異
Kubernetes 架構與虛擬化之差異inwin stack
 
容器革命的「利」與「必」
容器革命的「利」與「必」 容器革命的「利」與「必」
容器革命的「利」與「必」 inwin stack
 

More from inwin stack (19)

Migrating to Cloud Native Solutions
Migrating to Cloud Native SolutionsMigrating to Cloud Native Solutions
Migrating to Cloud Native Solutions
 
Cloud Native 下的應用網路設計
Cloud Native 下的應用網路設計Cloud Native 下的應用網路設計
Cloud Native 下的應用網路設計
 
當電子發票遇見 Google Cloud Function
當電子發票遇見 Google Cloud Function當電子發票遇見 Google Cloud Function
當電子發票遇見 Google Cloud Function
 
運用高效、敏捷全新平台極速落實雲原生開發
運用高效、敏捷全新平台極速落實雲原生開發運用高效、敏捷全新平台極速落實雲原生開發
運用高效、敏捷全新平台極速落實雲原生開發
 
The last mile of digital transformation AI大眾化:數位轉型的最後一哩
The last mile of digital transformation AI大眾化:數位轉型的最後一哩The last mile of digital transformation AI大眾化:數位轉型的最後一哩
The last mile of digital transformation AI大眾化:數位轉型的最後一哩
 
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案
整合Cloud Foundry 和 Kubernetes 技術打造企業級雲應用平台解決方案
 
An Open, Open source way to enable your Cloud Native Journey
An Open, Open source way to enable your Cloud Native JourneyAn Open, Open source way to enable your Cloud Native Journey
An Open, Open source way to enable your Cloud Native Journey
 
維運Kubernetes的兩三事
維運Kubernetes的兩三事維運Kubernetes的兩三事
維運Kubernetes的兩三事
 
Serverless framework on kubernetes
Serverless framework on kubernetesServerless framework on kubernetes
Serverless framework on kubernetes
 
Web後端技術的演變
Web後端技術的演變Web後端技術的演變
Web後端技術的演變
 
以 Kubernetes 部屬 Spark 大數據計算環境
以 Kubernetes 部屬 Spark 大數據計算環境以 Kubernetes 部屬 Spark 大數據計算環境
以 Kubernetes 部屬 Spark 大數據計算環境
 
Setup Hybrid Clusters Using Kubernetes Federation
Setup Hybrid Clusters Using Kubernetes FederationSetup Hybrid Clusters Using Kubernetes Federation
Setup Hybrid Clusters Using Kubernetes Federation
 
基於 K8S 開發的 FaaS 專案 - riff
基於 K8S 開發的 FaaS 專案 - riff基於 K8S 開發的 FaaS 專案 - riff
基於 K8S 開發的 FaaS 專案 - riff
 
使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster 使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster
 
利用K8S實現高可靠應用
利用K8S實現高可靠應用利用K8S實現高可靠應用
利用K8S實現高可靠應用
 
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
 
Distributed tensorflow on kubernetes
Distributed tensorflow on kubernetesDistributed tensorflow on kubernetes
Distributed tensorflow on kubernetes
 
Kubernetes 架構與虛擬化之差異
Kubernetes 架構與虛擬化之差異Kubernetes 架構與虛擬化之差異
Kubernetes 架構與虛擬化之差異
 
容器革命的「利」與「必」
容器革命的「利」與「必」 容器革命的「利」與「必」
容器革命的「利」與「必」
 

Build your own kubernetes apiserver and resource type

  • 1. Kyle bai R&D @ inwinSTACK www.inwinstack.com Build your own Kubernetes apiserver and resource type
  • 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+
  • 9. Kubernetes Pros 資源監控 Monitoring 滾動升級 Rolling-update ⾼高可靠性 High-availability ⾃自我修復 Self-healing 雲端⽀支援 Cloud Provider 持久性儲存 Persistent Volumes 組態檔案 Configmap 安全性 Secret Kubernetes 管理理跨區域與主機的容器節點,提供基本部署、維運、管 理理,以及執⾏行行各項應⽤用程式,並具備多種特性。
  • 13. Kubernetes Architecture(1/2) Kubernetes 屬於分散式架構系統,主要由兩兩種節點⾓角⾊色組成: • Masters – 主要提供 API、管理理⼯工作節點與排程等,為主節點。 • Nodes(Minions) – 主要執⾏行行容器應⽤用的節點,上⾯面會執⾏行行許多 容器。
  • 15. 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
  • 16. HTTP API spaces 由於其可擴展性, Kubernetes ⽀支援不同 API 路路徑版本,比如 /api/v1或/apis/ extensions/v1beta1。
  • 17. API Levels 在 Kubernetes 中,不同版本的 API 意味著不同層級穩定度與⽀支援度: • Alpha level:在預設下是⼤大多情況禁⽌止使⽤用狀狀態,這些功能有可能隨時在下⼀一 版本被遺棄,因此只適⽤用於測試⽤用,Example: v1alpha1。 • Beta level: 在這級別⼀一般預設會啟⽤用,這表⽰示該功能已經過很好的測試項 ⽬目,但是物件內容可能會在後續版本或穩定版本發⽣生變化。Example: v1beta2。 • Stable level:在這級別表⽰示該功能已經穩定,會很長的時間⼀一直存在。 Example: v1。
  • 18. API Terminology(1/2) • Kind:是⼀一個實體(Entity)的類型,每個 Kubernetes 物件都會有⼀一個欄欄位 Kind。 1. 物件表⽰示系統中的⼀一個持久實體,如 Pod 與 Namespace。 2. ⼀一個多種實體的資源集合列列表,如 PodLists, NodeLists。 3. 特殊⽤用途類型⽤用於物件與非持久實體的特 定操作,如 /binding, /status 這些⽤用來來取得 API Group 與 Resource 的錯誤狀狀態。
  • 19. API Terminology(2/2) • API Group:是邏輯上相關的種類集合,如 Job 與 CronJob 都屬於批次處理理功能相 關。 • Version: 每個 API Group 存在多個版本,這些版本區分不同穩定度層級,⼀一般功能會 從 v1alpha1 升級到 v1beta1,然後在 v1 成為穩定版本。 • Resource: 資源是透過 HTTP 發送與檢索的系統實體,其以 JSON 來來表⽰示。可以是 單⼀一或者多個資源。
  • 20. 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 等),並從儲存中取得 物件實體。
  • 21. Request Flow and Processing(2/4) https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
  • 22. Request Flow and Processing(3/4) https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
  • 23. Request Flow and Processing(4/4) https://www.slideshare.net/sttts/kubernetes-api-deep-dive-into-the-kubeapiserver
  • 25. Validation and Admission • Admission:透過驗證叢集的全域約束來來檢查是否建立或更更新 API 物件,在 Kubernetes 中有很多這樣功能。幾個約束範例例: • NamespaceLifecycle: 如果命名空間不存在,則拒絕該所有請求。 • ResourceQuota:為叢集的當前使⽤用者強制執⾏行行額度限制。 • Validation:檢查傳入的物件(建立與更更新過程)的格式是否符合。例例如: • 檢查所有的字串串是否是有效的格式。 • 檢查是否有設定⽭矛盾欄欄位。
  • 26. YAML file to define resource Example resource:
  • 28. CustomResourceDefinitions(CRD) CustomResourceDefinition(CRD) 是 v1.7+ 版本新加入的 Kubernetes API 擴 展機制,⽬目標是無需修改核⼼心程式碼就能對 Kubernetes 進⾏行行擴展,⽽而 CRD 更更 是 ThirdPartyResources(TPR) 的升級版。 • 使⽤用⾃自定義物件進⾏行行擴展 Kubernetes API. • CRDs 能夠沿⽤用熟係的 UX ⼯工具,ex: kubectl. • 能夠與 Controllers 進⾏行行結合. • ⽀支援 SubResources(v1.9). P.S. TPR 在 v1.8 版本已被遺棄。
  • 31. Add Controller to Handle events
  • 32. How CRD works internally(1/2) Creating a CRD
  • 33. How CRD works internally(2/2) Creating a CustomResource
  • 34. Use case - rook.io(1/2) rook.io: ⼀一款⽀支援檔案系統、區塊儲存與物件儲存服務的雲原⽣生儲存系統。(Ceph 改良版 on Kubenretes)。
  • 35. Use case - rook.io (2/2) Rook 使⽤用 CRD 來來定義建立 Pool 與 Filesystem 資源,以提供 Rook operator 存取並建立對應服務。
  • 36. Use case - TensorFlow(1/3) https://github.com/tensorflow/k8s Kubernetes Custom Resource and Operator For TensorFlow jobs.
  • 37. Use case - TensorFlow(2/3)
  • 38. Use case - TensorFlow(3/3)
  • 39. Refer projects • code-generator • crd-code-generation • apiextensions-apiserver • sample-apiserver • sample-controller • apimachinery
  • 40. Extend the Kubernetes API with apiserver-builder
  • 41. apiserver-builder apiserver-builder 是⼀一個實作快速建構 Kubernetes apiserver 與⾃自定義資源類 型的⼯工具與函式庫,該⼯工具具備了了以下幾個特性: • 能夠⼀一次建立新資源類型、控制器、測試函式與⽂文件。 • 能夠建構與執⾏行行於 Standalone, Minikube 與遠端叢集。 • 能夠簡單地從控制器(Controller)來來觀看與更更新 Kubernetes API 資源類型。 • 很簡單的加入新資源與⼦子資源。 • 為⼤大多數欄欄位提供預設值,且能夠被覆蓋。
  • 42. 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
  • 44. Demo
  • 45. Refer projects • apiserver-builder/example • kube-openapi • service-catalog