kubernetes提供了兩種機制供用戶擴展API
(1)使用CRD機制:複用Kubernetes的API Server,無需編寫額外的API Server,用戶只需要定義CRD,並且提供一個CRD控制器,就能通過Kubernetes的API管理自定義資源對象了,同時要求用戶的CRD對象符合APIServer的管理規範
1、創建CRD的定義
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: virtualservices.networking.istio.io
annotations:
"helm.sh/hook":crd-install
labels:
app: istio-pilot
spec:
group: networking.istio.io
scope: Namespaced
versions:
- name: v1alpha3
served: true
storage: true
names:
kind: VirtualService
listKind: VirtualServiceList
singular: virtualservice
plural: virtualservices
categories:
- istio-io
- networking-istio-io
2、基於CRD的定義創建自定義資源對象
下面是定義了一個類型爲VirtualService的資源對象
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: helloword
spec:
hosts:
- “*”
gateways:
- helloword-gateway
http:
- match:
- uri:
exact: /hello
route:
- destination:
host: helloword
port:
number: 5000
3、使用API聚合機制擴展API資源
API聚合機制的主要目標
1、增加API的擴展性
2、無須等待Kubernetes核心團隊的繁雜審查
3、支持實驗性新特性API開發
4、確保新的API遵循Kubernetes的規範
5、Metrics Server通過聚合API提供Pod和Node的資源使用數據,供HPA控制器,VPA控制器及kubectl top命令使用.
欲瞭解更多相關知識,請關注公衆號:架構師Plus