MutatingWebhookConfiguration
apiVersion: admissionregistration.k8s.io/v1
import "k8s.io/api/admissionregistration/v1"
MutatingWebhookConfiguration
MutatingWebhookConfiguration 描述了一个可变的准入 webhook 的配置,该 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 定义了如何与 hook 通信。必需
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
以标准 URL 格式(scheme://host:port/path
)给出 webhook 的位置。必须指定url
或service
中的一个。host
不应指向集群内运行的服务;请改用service
字段。在某些 apiserver 中,host 可能通过外部 DNS 解析(例如,kube-apiserver
无法解析集群内 DNS,因为这将是一个层级违规)。host
也可能是一个 IP 地址。请注意,使用
localhost
或127.0.0.1
作为host
是有风险的,除非您非常小心地在运行可能需要调用此 webhook 的所有 apiserver 的主机上运行此 webhook。此类安装可能不具有可移植性,即在新的集群中不容易启用。方案必须是“https”;URL 必须以“https://”开头。
path 是可选的,如果存在,可以是 URL 中允许的任何字符串。您可以使用 path 向 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 必须实现一个协调系统,因为一个请求可能会被准入链中的后续步骤拒绝,因此需要撤销副作用。对于副作用等于 Unknown 或 Some 的 webhook,带有 dryRun 属性的请求将被自动拒绝。
webhooks.failurePolicy (string)
FailurePolicy 定义了如何处理来自准入端点的无法识别的错误 - 允许值为 Ignore 或 Fail。默认为 Fail。
webhooks.matchConditions ([]MatchCondition)
补丁策略:在键
name
上合并映射:合并时将保留键名上的唯一值
MatchConditions 是发送请求到此 webhook 必须满足的条件列表。匹配条件过滤已由 rules、namespaceSelector 和 objectSelector 匹配的请求。一个空的 matchConditions 列表匹配所有请求。最多允许 64 个匹配条件。
确切的匹配逻辑是(按顺序)
- 如果 *任何* matchCondition 求值为 FALSE,则跳过 webhook。
- 如果 *所有* matchConditions 都求值为 TRUE,则调用 webhook。
- 如果任何 matchCondition 评估为错误(但没有一个为 FALSE)
- 如果 failurePolicy=Fail,则拒绝请求
- 如果 failurePolicy=Ignore,则忽略错误并跳过 webhook
MatchCondition 表示 Webhook 必须满足才能发送请求的条件。
webhooks.matchConditions.expression (string), required
Expression 表示将由 CEL 评估的表达式。必须评估为布尔值。CEL 表达式可以访问 AdmissionRequest 和 Authorizer 的内容,这些内容组织成 CEL 变量
'object' - 来自入站请求的对象。对于 DELETE 请求,值为 null。'oldObject' - 现有对象。对于 CREATE 请求,值为 null。'request' - 准入请求的属性(/pkg/apis/admission/types.go#AdmissionRequest)。'authorizer' - CEL 授权器。可用于执行请求的principal(用户或服务帐户)的授权检查。请参阅 https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 'authorizer.requestResource' - 一个 CEL ResourceCheck,由 'authorizer' 构建并配置了请求资源。有关 CEL 的文档:https://kubernetes.ac.cn/docs/reference/using-api/cel/
必需。
webhooks.matchConditions.name (string), required
Name 是此匹配条件的标识符,用于 MatchConditions 的战略合并,以及提供日志记录标识符。一个好的名称应该能够描述相关的表达式。名称必须是包含字母数字字符、'-'、'_' 或 '.' 的限定名称,并且必须以字母数字字符开头和结尾(例如,'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: 仅当请求完全匹配指定的规则时才匹配。例如,如果 deployments 可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 进行修改,但 "rules" 只包含
apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]
,那么对 apps/v1beta1 或 extensions/v1beta1 的请求将不会发送到 webhook。Equivalent: 如果请求修改了规则中列出的资源,即使是通过另一个 API 组或版本,也会匹配。例如,如果 deployments 可以通过 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 是选择加入的(opt-in)时才使用对象选择器,因为最终用户可以通过设置标签来跳过准入 webhook。默认为空的 LabelSelector,它匹配所有内容。
webhooks.reinvocationPolicy (string)
reinvocationPolicy 指示此 webhook 在单个准入评估中是否应被调用多次。允许值为 "Never" 和 "IfNeeded"。
Never: 在单个准入评估中,webhook 不会被调用超过一次。
IfNeeded: 如果被准入的对象在初始 webhook 调用后被其他准入插件修改,则 webhook 在本次准入评估中至少会再调用一次。指定此选项的 webhook 必须是幂等的,能够处理它们之前已准入的对象。注意:* 其他调用的次数不保证正好为一次。* 如果额外的调用导致对象进一步修改,则不保证会再次调用 webhook。* 使用此选项的 webhook 可能会被重新排序以最小化额外调用的次数。* 在所有修改都保证完成后验证一个对象,请改用验证准入 webhook。
默认为 "Never"。
webhooks.rules ([]RuleWithOperations)
原子性:在合并期间将被替换
Rules 描述了 webhook 关注的对哪些资源/子资源的操作。如果操作匹配 *任何* Rule,则 webhook 关注该操作。但是,为了防止 ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks 将集群置于无法恢复的状态(除非完全禁用插件),永远不会在对 ValidatingWebhookConfiguration 和 MutatingWebhookConfiguration 对象的准入请求上调用 ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks。
RuleWithOperations 是 Operations 和 Resources 的元组。建议确保所有元组的展开都是有效的。
webhooks.rules.apiGroups ([]string)
原子性:在合并期间将被替换
APIGroups 是资源所属的 API 组。'' 表示所有组。如果存在 '',则切片的长度必须为 1。必需。
webhooks.rules.apiVersions ([]string)
原子性:在合并期间将被替换
APIVersions 是资源所属的 API 版本。'' 表示所有版本。如果存在 '',则切片的长度必须为 1。必需。
webhooks.rules.operations ([]string)
原子性:在合并期间将被替换
Operations 是准入钩子关心的操作 - CREATE、UPDATE、DELETE、CONNECT 或 * 表示所有这些操作以及将来添加的任何准入操作。如果存在 '*',则切片的长度必须为 1。必需。
webhooks.rules.resources ([]string)
原子性:在合并期间将被替换
Resources 是此规则适用的资源列表。
例如:'pods' 表示 pods。'pods/log' 表示 pods 的 log 子资源。'*' 表示所有资源,但不包括子资源。'pods/*' 表示 pods 的所有子资源。'*/*' 表示所有资源及其子资源。
如果存在通配符,则验证规则将确保资源彼此不重叠。
根据包围对象,可能不允许子资源。必需。
webhooks.rules.scope (string)
scope 指定此规则的范围。有效值为 "Cluster"、"Namespaced" 和 "*"。"Cluster" 意味着只有集群范围的资源将匹配此规则。Namespace 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 列表。
操作
get
读取指定的 MutatingWebhookConfiguration
HTTP 请求
GET /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string,必填
MutatingWebhookConfiguration 的名称
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
401: 未授权
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: 未授权
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: 未授权
update
替换指定的 MutatingWebhookConfiguration
HTTP 请求
PUT /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string,必填
MutatingWebhookConfiguration 的名称
body: MutatingWebhookConfiguration, required
dryRun (在查询中): string
fieldManager (在查询中): string
fieldValidation (在查询中): string
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: 未授权
patch
部分更新指定的 MutatingWebhookConfiguration
HTTP 请求
PATCH /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string,必填
MutatingWebhookConfiguration 的名称
body: Patch,必需
dryRun (在查询中): string
fieldManager (在查询中): string
fieldValidation (在查询中): string
force (在查询中): boolean
pretty (在查询中): string
响应
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: 未授权
delete
删除一个 MutatingWebhookConfiguration
HTTP 请求
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
参数
name (在路径中): string,必填
MutatingWebhookConfiguration 的名称
body: DeleteOptions
dryRun (在查询中): string
gracePeriodSeconds (在查询中): integer
ignoreStoreReadErrorWithClusterBreakingPotential (在查询中): boolean
pretty (在查询中): string
propagationPolicy (在查询中): string
响应
200 (Status): OK
202 (Status): 已接受
401: 未授权
deletecollection
删除 MutatingWebhookConfiguration 的集合
HTTP 请求
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
参数
body: DeleteOptions
continue (在查询中): string
dryRun (在查询中): string
fieldSelector (在查询中): string
gracePeriodSeconds (在查询中): integer
ignoreStoreReadErrorWithClusterBreakingPotential (在查询中): boolean
labelSelector (在查询中): string
limit (在查询中): integer
pretty (在查询中): string
propagationPolicy (在查询中): string
resourceVersion (在查询中): string
resourceVersionMatch (在查询中): string
sendInitialEvents (在查询中): boolean
timeoutSeconds (在查询中): integer
响应
200 (Status): OK
401: 未授权
本页面是自动生成的。
如果你打算报告此页面存在的问题,请在问题描述中提及此页面是自动生成的。修复可能需要在 Kubernetes 项目的其他地方进行。