Aggregation
API Aggregation 允许在不修改 Kubernetes 核心代码的同时扩展 Kubernetes API,即将第三方服务注册到 Kubernetes API 中,这样就可以通过 Kubernetes API 来访问外部服务。
备注:另外一种扩展 Kubernetes API 的方法是使用 CustomResourceDefinition (CRD)。
何时使用 Aggregation
满足以下条件时使用 API Aggregation | 满足以下条件时使用独立 API |
---|---|
Your API is Declarative. | Your API does not fit the Declarative model. |
You want your new types to be readable and writable using |
|
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 are willing to accept the format restriction that Kubernetes puts on REST resource paths, such as API Groups and Namespaces. (See the API Overview.) | 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 want to reuse Kubernetes API support features. | You don’t need those features. |
开启 API Aggregation
kube-apiserver 增加以下配置
如果 kube-proxy
没有在 Master 上面运行,还需要配置
创建扩展 API
确保开启 APIService API(默认开启,可用
kubectl get apiservice
命令验证)创建 RBAC 规则
创建一个 namespace,用来运行扩展的 API 服务
创建 CA 和证书,用于 https
创建一个存储证书的 secret
创建一个部署扩展 API 服务的 deployment,并使用上一步的 secret 配置证书,开启 https 服务
创建一个 ClusterRole 和 ClusterRoleBinding
创建一个非 namespace 的 apiservice,注意设置
spec.caBundle
运行
kubectl get <resource-name>
,正常应该返回No resources found.
可以使用 apiserver-builder 工具自动化上面的步骤。
示例
最后更新于