Kubernetes Admission Controller(插件)和 Admission Webhook 之间有什么区别?

What's the difference between a Kubernetes Admission Controller (Plugin) and an Admission Webhook?

Admission Controllers(插件)和 Admission Webhooks 表面上看起来非常相似。实际的功能差异是什么?

Admission Controllers 被专家甚至 official documentation 合并为 Admission Plugins 和 Admission Webhooks。 我将它们称为 Admission Plugins 和 Admission Webhooks 以防止混淆。

准入插件不是API资源。它们不能由集群管理员创建。他们是hardcoded into the Kubernetes source code.

具体来说,Admission Plugins 是一个功能无限的工具。由于他们被融入 kube-apiserver,他们有能力 simply request for resources without authentication. 他们使用这种能力来实施 DefaultStorageClass 准入插件,该插件检查所有 StorageClasses 以找到一个应用了默认注释。

另一方面,Admission Webhook 实际上 an implementation of an Admission Plugin, with the extra power removed. Note how a Webhook.Validator does not have the ability to access any resources 除了当时正在验证的确切对象之外。 Admission Webhooks are API resources, and are usually the first thing recommended when implementing a validator for a Kubernetes Operator, or a CRD in general. Despite this, signed certificates are required,可以让你放弃整个想法。

这对普通开发人员意味着什么?

要编写依赖于检查集群中现有对象的验证程序,您需要使用 Kubernetes Golang Client API 执行额外的步骤,这依赖于应用正确 RBAC 的服务帐户令牌。

您也可以update your object with a Status instead,解释验证失败的原因。如果你正在写一个 Kubernetes Operator,那可以写在协调循环中。

如果您为自定义资源编写了一个花哨的 UI,您应该能够读取这些状态并以更好的方式将它们公开给用户。不幸的是,OpenShift 4.X 用户无法向 OpenShift Web 控制台添加花哨的 UIs,并且将不得不满足于公开 Routes。