MutatingWebhookConfiguration
apiVersion: admissionregistration.k8s.io/v1
import "k8s.io/api/admissionregistration/v1"
MutatingWebhookConfiguration
MutatingWebhookConfiguration 描述了接受或拒绝并可能更改对象的准入 Webhook 的配置。
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata (ObjectMeta)
标准对象元数据;更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
webhooks ([]MutatingWebhook)
补丁策略:在键
name
上合并Webhooks 是 Webhook 列表以及受影响的资源和操作。
MutatingWebhook 描述了准入 Webhook 以及它应用于的资源和操作。
webhooks.admissionReviewVersions ([]string), required
AdmissionReviewVersions 是 Webhook 期望的
AdmissionReview
版本的排序列表。API 服务器将尝试使用列表中它支持的第一个版本。如果列表中指定的版本都不受 API 服务器支持,则此对象的验证将失败。如果持久化的 Webhook 配置指定了允许的版本,但未包含 API 服务器已知的任何版本,则对 Webhook 的调用将失败并受失败策略的影响。webhooks.clientConfig (WebhookClientConfig), required
ClientConfig 定义了如何与挂钩通信。必需
WebhookClientConfig 包含与 Webhook 建立 TLS 连接的信息
webhooks.clientConfig.caBundle ([]byte)
caBundle
是一个 PEM 编码的 CA 捆绑包,它将用于验证 Webhook 的服务器证书。如果未指定,则使用 apiserver 上的系统信任根。webhooks.clientConfig.service (ServiceReference)
service
是对该 Webhook 服务的引用。必须指定service
或url
。如果 Webhook 在集群内运行,则应使用
service
。ServiceReference 包含对 Service.legacy.k8s.io 的引用
webhooks.clientConfig.service.name (string), required
name
是服务的名称。必需webhooks.clientConfig.service.namespace (string), required
namespace
是服务的命名空间。必需webhooks.clientConfig.service.path (string)
path
是一个可选的 URL 路径,它将在对该服务的任何请求中发送。webhooks.clientConfig.service.port (int32)
如果指定,则为托管 Webhook 的服务上的端口。默认值为 443,以保持向后兼容性。
port
应为有效的端口号(1-65535,含)。
webhooks.clientConfig.url (string)
url
提供了 Webhook 的位置,以标准 URL 形式(scheme://host:port/path
)。必须指定url
或service
中的其中一个。host
不应引用在集群中运行的服务;请改用service
字段。主机可能通过某些 apiserver 中的外部 DNS 解析(例如,kube-apiserver
无法解析集群内 DNS,因为这将是分层违规)。host
也可能是一个 IP 地址。请注意,除非您非常小心地在所有运行可能需要调用此 Webhook 的 apiserver 的主机上运行此 Webhook,否则使用
localhost
或127.0.0.1
作为host
是有风险的。此类安装可能不可移植,即不容易在新集群中启动。方案必须为“https”;URL 必须以“https://”开头。
路径是可选的,如果存在,可以是 URL 中允许的任何字符串。您可以使用路径将任意字符串传递给 Webhook,例如集群标识符。
尝试使用用户或基本身份验证,例如“user:password@”是不允许的。片段(“#...”)和查询参数(“?...”)也不允许。
webhooks.name (string), required
准入 Webhook 的名称。名称应为完全限定的,例如 imagepolicy.kubernetes.io,其中“imagepolicy”是 Webhook 的名称,kubernetes.io 是组织的名称。必需。
webhooks.sideEffects (string), required
SideEffects 指示此 Webhook 是否具有副作用。可接受的值为:None、NoneOnDryRun(通过 v1beta1 创建的 Webhook 也可能指定 Some 或 Unknown)。具有副作用的 Webhook 必须实现一个协调系统,因为请求可能会被准入链中的未来步骤拒绝,因此需要撤消副作用。如果请求具有 dryRun 属性,并且与 sideEffects == Unknown 或 Some 的 Webhook 匹配,则该请求将被自动拒绝。
webhooks.failurePolicy (string)
FailurePolicy 定义了如何处理来自准入端点的无法识别的错误 - 允许的值为 Ignore 或 Fail。默认为 Fail。
webhooks.matchConditions ([]MatchCondition)
补丁策略:在键
name
上合并Map:在合并期间将保留键名称上的唯一值
MatchConditions 是一个条件列表,必须满足这些条件才能将请求发送到此 Webhook。匹配条件会过滤掉已经通过规则、namespaceSelector 和 objectSelector 匹配的请求。空匹配条件列表匹配所有请求。
确切的匹配逻辑(按顺序)为
- 如果任何 matchCondition 评估为 FALSE,则跳过 Webhook。
- 如果所有 matchCondition 评估为 TRUE,则调用 Webhook。
- 如果任何 matchCondition 评估为错误(但没有一个为 FALSE)
- 如果 failurePolicy=Fail,则拒绝请求
- 如果 failurePolicy=Ignore,则忽略错误并跳过 Webhook
这是一个测试版功能,由 AdmissionWebhookMatchConditions 功能门控管理。
MatchCondition 表示一个条件,必须满足该条件才能将请求发送到 Webhook。
webhooks.matchConditions.expression (string), required
Expression 表示将由 CEL 评估的表达式。必须评估为 bool。CEL 表达式可以访问 AdmissionRequest 和 Authorizer 的内容,这些内容被组织到 CEL 变量中
'object' - 来自传入请求的对象。对于 DELETE 请求,该值为 null。'oldObject' - 现有对象。对于 CREATE 请求,该值为 null。'request' - 准入请求的属性(/pkg/apis/admission/types.go#AdmissionRequest)。'authorizer' - CEL 授权器。可用于对请求的委托人(用户或服务帐户)执行授权检查。请参阅 https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 'authorizer.requestResource' - 从 'authorizer' 构造的 CEL ResourceCheck,并使用请求资源进行配置。有关 CEL 的文档:https://kubernetes.ac.cn/docs/reference/using-api/cel/
必需。
webhooks.matchConditions.name (string), required
Name 是此匹配条件的标识符,用于 MatchConditions 的策略性合并,以及提供日志记录目的的标识符。一个好的名称应该描述相关的表达式。Name 必须是一个限定名称,由字母数字字符、'-’、‘_’ 或 ‘.’ 组成,并且必须以字母数字字符开头和结尾(例如 ‘MyName’ 或 ‘my.name’ 或 ‘123-abc’,用于验证的正则表达式为 ‘([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]’),并带有一个可选的 DNS 子域前缀和 ‘/’(例如 ‘example.com/MyName’)
必需。
webhooks.matchPolicy (string)
matchPolicy 定义了如何使用“rules”列表来匹配传入请求。允许的值为“Exact”或“Equivalent”。
Exact:仅当请求与指定的规则完全匹配时才匹配请求。例如,如果部署可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改,但“rules”仅包含
apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]
,则对 apps/v1beta1 或 extensions/v1beta1 的请求将不会发送到 Webhook。Equivalent:如果修改了 rules 中列出的资源,即使通过另一个 API 组或版本,也会匹配请求。例如,如果部署可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改,但“rules”仅包含
apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]
,则对 apps/v1beta1 或 extensions/v1beta1 的请求将转换为 apps/v1 并发送到 Webhook。
默认为“Equivalent”
webhooks.namespaceSelector (LabelSelector)
NamespaceSelector 决定是否根据该对象所属的命名空间是否与选择器匹配来在对象上运行 Webhook。如果对象本身是一个命名空间,则在 object.metadata.labels 上执行匹配。如果对象是另一个集群范围的资源,则它永远不会跳过 Webhook。
例如,要对任何命名空间不与“runlevel”为“0”或“1”关联的对象运行 Webhook,您将按如下方式设置选择器:“namespaceSelector”:{“matchExpressions”:[ {“key”:“runlevel”,“operator”:“NotIn”,“values”:[“0”,“1”] } ] }
如果您希望仅对任何命名空间与“environment”为“prod”或“staging”关联的对象运行 Webhook,您将按如下方式设置选择器:“namespaceSelector”:{“matchExpressions”:[ {“key”:“environment”,“operator”:“In”,“values”:[“prod”,“staging”] } ] }
有关标签选择器的更多示例,请参阅 https://kubernetes.ac.cn/docs/concepts/overview/working-with-objects/labels/。
默认情况下为空的 LabelSelector,它匹配所有内容。
webhooks.objectSelector (LabelSelector)
ObjectSelector 根据对象是否具有匹配的标签来决定是否运行 Webhook。objectSelector 会针对将发送到 Webhook 的 oldObject 和 newObject 进行评估,如果任一对象与选择器匹配,则认为匹配。空对象(在创建情况下为 oldObject,在删除情况下为 newObject)或无法拥有标签的对象(如 DeploymentRollback 或 PodProxyOptions 对象)不被认为是匹配的。仅当 Webhook 是选择加入时才使用对象选择器,因为最终用户可以通过设置标签来跳过准入 Webhook。默认情况下为空的 LabelSelector,它匹配所有内容。
webhooks.reinvocationPolicy (string)
reinvocationPolicy 指示此 Webhook 是否应在单个准入评估中多次调用。允许的值为“Never”和“IfNeeded”。
Never:Webhook 在单个准入评估中不会被调用超过一次。
IfNeeded:如果在初始 Webhook 调用后,被准入的对象被其他准入插件修改,Webhook 将在准入评估中至少被额外调用一次。指定此选项的 Webhook 必须是幂等的,能够处理它们之前已准入的对象。注意:* 额外调用的次数不保证正好为一次。* 如果额外调用导致对对象进行进一步修改,则不保证再次调用 Webhook。* 使用此选项的 Webhook 可能会被重新排序以最大限度地减少额外调用的次数。* 要在所有变异完成后验证对象,请使用验证准入 Webhook。
默认为“Never”。
webhooks.rules ([]RuleWithOperations)
Rules 描述了 Webhook 关注哪些资源/子资源上的哪些操作。如果 Webhook 与任何Rule 匹配,则它关注某个操作。但是,为了防止 ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks 将集群置于无法恢复的状态(除非完全禁用插件),ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks 永远不会在针对 ValidatingWebhookConfiguration 和 MutatingWebhookConfiguration 对象的准入请求上调用。
RuleWithOperations 是 Operations 和 Resources 的元组。建议确保所有元组扩展都是有效的。
webhooks.rules.apiGroups ([]string)
Atomic:将在合并期间被替换
APIGroups 是资源所属的 API 组。“*”表示所有组。如果存在“*”,则切片的长度必须为 1。必需。
webhooks.rules.apiVersions ([]string)
Atomic:将在合并期间被替换
APIVersions 是资源所属的 API 版本。“*”表示所有版本。如果存在“*”,则切片的长度必须为 1。必需。
webhooks.rules.operations ([]string)
Atomic:将在合并期间被替换
Operations 是准入钩子关注的操作 - CREATE、UPDATE、DELETE、CONNECT 或 * 表示所有这些操作以及将来添加的任何准入操作。如果存在“*”,则切片的长度必须为 1。必需。
webhooks.rules.resources ([]string)
Atomic:将在合并期间被替换
Resources 是此规则适用的资源列表。
例如:“pods”表示 pods。“pods/log”表示 pods 的 log 子资源。“*”表示所有资源,但不包括子资源。“pods/*”表示 pods 的所有子资源。“*/scale”表示所有 scale 子资源。“*/*”表示所有资源及其子资源。
如果存在通配符,则验证规则将确保资源不会相互重叠。
根据封闭对象,子资源可能不被允许。必需。
webhooks.rules.scope (string)
scope 指定此规则的范围。有效值为“Cluster”、“Namespaced”和“*”。“Cluster”表示只有集群范围的资源将匹配此规则。命名空间 API 对象是集群范围的。“Namespaced”表示只有命名空间范围的资源将匹配此规则。“*”表示没有范围限制。子资源匹配其父资源的范围。默认值为“*”。
webhooks.timeoutSeconds (int32)
TimeoutSeconds 指定此 Webhook 的超时时间。超时时间过后,Webhook 调用将被忽略,或者根据失败策略,API 调用将失败。超时值必须介于 1 到 30 秒之间。默认为 10 秒。
MutatingWebhookConfigurationList
MutatingWebhookConfigurationList 是 MutatingWebhookConfiguration 的列表。
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfigurationList
metadata (ListMeta)
标准列表元数据。更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
items ([]MutatingWebhookConfiguration), required
MutatingWebhookConfiguration 列表。
Operations
get
读取指定的 MutatingWebhookConfiguration
HTTP 请求
GET /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string, required
MutatingWebhookConfiguration 的名称
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
401: Unauthorized
list
列出或观察 MutatingWebhookConfiguration 类型的对象
HTTP 请求
GET /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
参数
allowWatchBookmarks (在查询中): boolean
continue (在查询中): string
fieldSelector (在查询中): string
labelSelector (在查询中): string
limit (在查询中): integer
pretty (在查询中): string
resourceVersion (在查询中): string
resourceVersionMatch (在查询中): string
sendInitialEvents (在查询中): boolean
timeoutSeconds (在查询中): integer
watch (在查询中): boolean
响应
200 (MutatingWebhookConfigurationList): OK
401: Unauthorized
create
创建 MutatingWebhookConfiguration
HTTP 请求
POST /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
参数
body: MutatingWebhookConfiguration, required
dryRun (在查询中): string
fieldManager (在查询中): string
fieldValidation (在查询中): string
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
202 (MutatingWebhookConfiguration): Accepted
401: Unauthorized
update
替换指定的 MutatingWebhookConfiguration
HTTP 请求
PUT /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string, required
MutatingWebhookConfiguration 的名称
body: MutatingWebhookConfiguration, required
dryRun (在查询中): string
fieldManager (在查询中): string
fieldValidation (在查询中): string
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: Unauthorized
patch
部分更新指定的 MutatingWebhookConfiguration
HTTP 请求
PATCH /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string, required
MutatingWebhookConfiguration 的名称
body: Patch, required
dryRun (在查询中): string
fieldManager (在查询中): string
fieldValidation (在查询中): string
force (在查询中): boolean
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: Unauthorized
delete
删除 MutatingWebhookConfiguration
HTTP 请求
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string, required
MutatingWebhookConfiguration 的名称
body: DeleteOptions
dryRun (在查询中): string
gracePeriodSeconds (在查询中): integer
pretty (在查询中): string
propagationPolicy (在查询中): string
响应
200 (Status): OK
202 (Status): Accepted
401: Unauthorized
deletecollection
删除 MutatingWebhookConfiguration 集合
HTTP 请求
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
参数
body: DeleteOptions
continue (在查询中): string
dryRun (在查询中): string
fieldSelector (在查询中): string
gracePeriodSeconds (在查询中): integer
labelSelector (在查询中): string
limit (在查询中): integer
pretty (在查询中): string
propagationPolicy (在查询中): string
resourceVersion (在查询中): string
resourceVersionMatch (在查询中): string
sendInitialEvents (在查询中): boolean
timeoutSeconds (在查询中): integer
响应
200 (Status): OK
401: Unauthorized
此页面是自动生成的。
如果您打算报告此页面的问题,请在您的问题描述中提及此页面是自动生成的。修复可能需要在 Kubernetes 项目中的其他地方进行。