Kubernetes
  • 序言
  • 基礎入門
    • Kubernetes 簡介
    • Kubernetes 基本概念
    • Kubernetes 101
    • Kubernetes 201
    • Kubernetes 集群
  • 核心原理
    • 核心原理
    • 架構原理
    • 設計理念
    • 核心組件
      • etcd
      • kube-apiserver
      • kube-scheduler
      • kube-controller-manager
      • kubelet
      • kube-proxy
      • kube-dns
      • Federation
      • kubeadm
      • hyperkube
      • kubectl
    • 資源對象
      • Autoscaling
      • ConfigMap
      • CronJob
      • CustomResourceDefinition
      • DaemonSet
      • Deployment
      • Ingress
      • Job
      • LocalVolume
      • Namespace
      • NetworkPolicy
      • Node
      • PersistentVolume
      • Pod
      • PodPreset
      • ReplicaSet
      • Resource Quota
      • Secret
      • SecurityContext
      • Service
      • ServiceAccount
      • StatefulSet
      • Volume
  • 部署配置
    • 部署指南
    • kubectl 安裝
    • 單機部署
    • 特性開關
    • 最佳配置
    • 版本支持
    • 集群部署
      • kubeadm
      • kops
      • Kubespray
      • Azure
      • Windows
      • LinuxKit
      • kubeasz
    • 附加組件
      • Addon-manager
      • DNS
      • Dashboard
      • 監控
      • 日誌
      • Metrics
      • GPU
      • Cluster Autoscaler
      • ip-masq-agent
    • Kubernetes-The-Hard-Way
      • 準備部署環境
      • 安裝必要工具
      • 創建計算資源
      • 配置創建證書
      • 配置生成配置
      • 配置生成密鑰
      • 部署 Etcd 群集
      • 部署控制節點
      • 部署計算節點
      • 配置 Kubectl
      • 配置網絡路由
      • 部署 DNS 擴展
      • 煙霧測試
      • 刪除集群
  • 插件擴展
    • API 擴展
      • Aggregation
      • CustomResourceDefinition
    • 訪問控制
      • 認證
      • RBAC 授權
      • 准入控制
    • Scheduler 擴展
    • 網絡插件
      • CNI
      • Flannel
      • Calico
      • Weave
      • Cilium
      • OVN
      • Contiv
      • SR-IOV
      • Romana
      • OpenContrail
      • Kuryr
    • 運行時插件 CRI
      • CRI-tools
      • Frakti
    • 存儲插件
      • 容器存儲接口 CSI
      • FlexVolume
      • glusterfs
    • 網絡策略
    • Ingress Controller
      • Ingress + Letsencrypt
      • minikube Ingress
      • Traefik Ingress
      • Keepalived-VIP
    • Cloud Provider 擴展
    • Device 插件
  • 服務治理
    • 服務治理
      • 一般準則
      • 滾動升級
      • Helm
      • Operator
      • Service Mesh
      • Linkerd
      • Linkerd2
    • Istio
      • 安裝
      • 流量管理
      • 安全管理
      • 策略管理
      • 度量管理
      • 排錯
      • 社區
    • Devops
      • Draft
      • Jenkins X
      • Spinnaker
      • Kompose
      • Skaffold
      • Argo
      • Flux GitOps
  • 實踐案例
    • 實踐概覽
    • 資源控制
    • 集群高可用
    • 應用高可用
    • 調試
    • 端口映射
    • 端口轉發
    • 用戶管理
    • GPU
    • HugePage
    • 安全
    • 審計
    • 備份恢復
    • 證書輪換
    • 大規模集群
    • 大數據與機器學習
      • Spark
      • Tensorflow
    • Serverless
  • 排錯指南
    • 排錯概覽
    • 集群排錯
    • Pod 排錯
    • 網絡排錯
    • PV 排錯
      • AzureDisk
      • AzureFile
    • Windows 排錯
    • 雲平臺排錯
      • Azure
    • 排錯工具
  • 社區貢獻
    • 開發指南
    • 單元測試和集成測試
    • 社區貢獻
  • 附錄
    • 生態圈
    • 學習資源
    • 國內鏡像
    • 如何貢獻
    • 參考文檔
Powered by GitBook
On this page
  • 何時使用 Aggregation
  • 開啓 API Aggregation
  • 創建擴展 API
  • 示例
  1. 插件擴展
  2. API 擴展

Aggregation

PreviousAPI 擴展NextCustomResourceDefinition

Last updated 1 year ago

API Aggregation 允許在不修改 Kubernetes 核心代碼的同時擴展 Kubernetes API,即將第三方服務註冊到 Kubernetes API 中,這樣就可以通過 Kubernetes API 來訪問外部服務。

備註:另外一種擴展 Kubernetes API 的方法是使用 。

何時使用 Aggregation

滿足以下條件時使用 API Aggregation
滿足以下條件時使用獨立 API

You want your new types to be readable and writable using kubectl.

kubectl support is not required

You want to view your new types in a Kubernetes UI, such as dashboard, alongside built-in types.

Kubernetes UI support is not required.

You are developing a new API.

You already have a program that serves your API and works well.

You need to have specific REST paths to be compatible with an already defined REST API.

Your resources are naturally scoped to a cluster or to namespaces of a cluster.

Cluster or namespace scoped resources are a poor fit; you need control over the specifics of resource paths.

You don’t need those features.

開啓 API Aggregation

kube-apiserver 增加以下配置

--requestheader-client-ca-file=<path to aggregator CA cert>
--requestheader-allowed-names=aggregator
--requestheader-extra-headers-prefix=X-Remote-Extra-
--requestheader-group-headers=X-Remote-Group
--requestheader-username-headers=X-Remote-User
--proxy-client-cert-file=<path to aggregator proxy cert>
--proxy-client-key-file=<path to aggregator proxy key>

如果 kube-proxy 沒有在 Master 上面運行,還需要配置

--enable-aggregator-routing=true

創建擴展 API

  1. 確保開啓 APIService API(默認開啓,可用 kubectl get apiservice 命令驗證)

  2. 創建 RBAC 規則

  3. 創建一個 namespace,用來運行擴展的 API 服務

  4. 創建 CA 和證書,用於 https

  5. 創建一個存儲證書的 secret

  6. 創建一個部署擴展 API 服務的 deployment,並使用上一步的 secret 配置證書,開啓 https 服務

  7. 創建一個 ClusterRole 和 ClusterRoleBinding

  8. 創建一個非 namespace 的 apiservice,注意設置 spec.caBundle

  9. 運行 kubectl get <resource-name>,正常應該返回 No resources found.

# 初始化項目
$ cd GOPATH/src/github.com/my-org/my-project
$ apiserver-boot init repo --domain <your-domain>
$ apiserver-boot init glide

# 創建資源
$ apiserver-boot create group version resource --group <group> --version <version> --kind <Kind>

# 編譯
$ apiserver-boot build executables
$ apiserver-boot build docs

# 本地運行
$ 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

示例

Your API is .

Your API does not fit the model.

You are willing to accept the format restriction that Kubernetes puts on REST resource paths, such as API Groups and Namespaces. (See the .)

You want to reuse .

可以使用 工具自動化上面的步驟。

見 和 。

CustomResourceDefinition (CRD)
apiserver-builder
sample-apiserver
apiserver-builder/example
Declarative
Declarative
API Overview
Kubernetes API support features