1 - FlowSchema

FlowSchema 定义一组流的模式。

apiVersion: flowcontrol.apiserver.k8s.io/v1

import "k8s.io/api/flowcontrol/v1"

FlowSchema

FlowSchema 定义一组流的模式。请注意,一个流由属性类似的一组入站 API 请求组成, 用一对字符串进行标识:FlowSchema 的名称和一个 “流区分项”。


  • apiVersion: flowcontrol.apiserver.k8s.io/v1

  • kind: FlowSchema

FlowSchemaSpec

FlowSchemaSpec 描述 FlowSchema 的规约看起来是怎样的。


  • distinguisherMethod (FlowDistinguisherMethod)

    distinguisherMethod 定义如何为匹配此模式的请求来计算流区分项。 nil 表示该区分项被禁用,且因此将始终为空字符串。

    FlowDistinguisherMethod 指定流区分项的方法。

    • distinguisherMethod.type (string),必需

      type 是流区分项的类型。支持的类型为 “ByUser” 和 “ByNamespace”。必需。

  • matchingPrecedence (int32)

    matchingPrecedence 用于选择与给定请求匹配的一个 FlowSchema。 选中的 FlowSchema 是某个 MatchingPrecedence 数值最小(我们视其为逻辑上最大)的 FlowSchema。 每个 MatchingPrecedence 值必须在 [1,10000] 的范围内。 请注意,如果未指定优先顺序,则其默认设为 1000。

  • priorityLevelConfiguration (PriorityLevelConfigurationReference),必需

    priorityLevelConfiguration 应引用集群中的 PriorityLevelConfiguration。 如果引用无法被解析,则忽略此 FlowSchema,并在其状态中将其标记为无效。必需。

    PriorityLevelConfigurationReference 包含指向正被使用的 “request-priority” 的信息。

    • priorityLevelConfiguration.name (string),必需

      name 是正被引用的优先级配置的名称。必需。

  • rules ([]PolicyRulesWithSubjects)

    原子性:将在合并期间被替换

    rules 描述哪些请求将与这个流模式匹配。只有当至少一条规则与请求匹配时, 才视为此 FlowSchema 与该请求匹配。如果字段值为空表,则 FlowSchema 不会与任何请求匹配。

    PolicyRulesWithSubjects 给出针对 API 服务器请求的一个测试。 该测试将检查发出请求的主体、所请求的动作和要操作的资源。 只有同时满足以下两个条件时,才表示此 PolicyRulesWithSubjects 与请求匹配: (a) 至少一个主体成员与请求匹配且 (b) 至少 resourceRules 或 nonResourceRules 的一个成员与请求匹配。

    • rules.subjects ([]Subject),必需

      原子性:将在合并期间被替换

      subjects 是此规则相关的普通用户、服务账号或组的列表。在这个列表中必须至少有一个成员。 同时包含 system:authenticated 和 system:unauthenticated 用户组的列表会与每个请求匹配。 此字段为必需。

      Subject 用来与匹配请求的发起方,请求的发起方由请求身份认证系统识别出来。 有三种方式来匹配一个发起方:按用户、按组或按服务账号。

      • rules.subjects.kind (string),必需

        kind 标示其他字段中的哪个字段必须非空。必需。

      • rules.subjects.group (GroupSubject)

        group 根据用户组名称进行匹配。

        GroupSubject 保存组类别主体的详细信息。

      • rules.subjects.serviceAccount (ServiceAccountSubject)

        serviceAccount 与 ServiceAccount 对象进行匹配。

        ServiceAccountSubject 保存服务账号类别主体的详细信息。

        • rules.subjects.serviceAccount.name (string),必需

          name 是要匹配的 ServiceAccount 对象的名称,可使用 * 匹配所有名称。必需。

        • rules.subjects.serviceAccount.namespace (string),必需

          namespace 是要匹配的 ServiceAccount 对象的名字空间。必需。

      • rules.subjects.user (UserSubject)

        user 根据用户名进行匹配。

        UserSubject 保存用户类别主体的详细信息。

        • rules.subjects.user.name (string),必需

          name 是要匹配的用户名,可使用 * 匹配所有用户名。必需。

    • rules.nonResourceRules ([]NonResourcePolicyRule)

      原子性:将在合并期间被替换

      nonResourceRules 是由 NonResourcePolicyRule 对象构成的列表, 根据请求的动作和目标非资源 URL 来识别匹配的请求。

      NonResourcePolicyRule 是根据请求的动作和目标非资源 URL 来匹配非资源请求的一种规则。 只有满足以下两个条件时,NonResourcePolicyRule 才会匹配一个请求: (a) 至少 verbs 的一个成员与请求匹配且 (b) 至少 nonResourceURLs 的一个成员与请求匹配。

      • rules.nonResourceRules.nonResourceURLs ([]string),必需

        集合:合并期间保留唯一值

        nonResourceURLs 是用户有权访问的一组 URL 前缀,不可以为空。 此字段为必需设置的字段。例如:

        • "/healthz" 是合法的
        • "/hea*" 是不合法的
        • "/hea" 是合法的但不会与任何项匹配
        • "/hea/*" 也不会与任何项匹配
        • "/healthz/*" 与所有组件自身的的健康检查路径匹配。 * 与所有非资源 URL 匹配。如果存在此字符,则必须是唯一的输入项。 必需。
      • rules.nonResourceRules.verbs ([]string),必需

        集合:在合并期间保留唯一值

        verbs 是与动作匹配的列表,不可以为空。* 与所有动作匹配。 如果存在此字符,则必须是唯一的输入项。必需。

    • rules.resourceRules ([]ResourcePolicyRule)

      原子性:将在合并期间被替换

      resourceRules 是 ResourcePolicyRule 对象的列表,根据请求的动作和目标资源识别匹配的请求。 resourceRulesnonResourceRules 两者必须至少有一个非空。

      ResourcePolicyRule 是用来匹配资源请求的规则,对请求的动作和目标资源进行测试。 只有满足以下条件时,ResourcePolicyRule 才会与某个资源请求匹配: (a) 至少 verbs 的一个成员与请求的动作匹配, (b) 至少 apiGroups 的一个成员与请求的 API 组匹配, (c) 至少 resources 的一个成员与请求的资源匹配, (d) 要么 (d1) 请求未指定一个名字空间(即,namespace=="")且 clusterScope 为 true, 要么 (d2) 请求指定了一个名字空间,且至少 namespaces 的一个成员与请求的名字空间匹配。

      • rules.resourceRules.apiGroups ([]string),必需

        集合:合并期间保留唯一值

        apiGroups 是与 API 组匹配的列表,不可以为空。* 表示与所有 API 组匹配。 如果存在此字符,则其必须是唯一的条目。必需。

      • rules.resourceRules.resources ([]string),必需

        集合:合并期间保留唯一值

        resources 是匹配的资源(即小写和复数)的列表,如果需要的话,还可以包括子资源。 例如 [ "services", "nodes/status" ]。此列表不可以为空。 * 表示与所有资源匹配。如果存在此字符,则必须是唯一的条目。必需。

      • rules.resourceRules.verbs ([]string),必需

        集合:合并期间保留唯一值

        verbs 是匹配的动作的列表,不可以为空。* 表示与所有动作匹配。 如果存在此字符,则必须是唯一的条目。必需。

      • rules.resourceRules.clusterScope (boolean)

        clusterScope 表示是否与未指定名字空间 (出现这种情况的原因是该资源没有名字空间或请求目标面向所有名字空间)的请求匹配。 如果此字段被省略或为 false,则 namespaces 字段必须包含一个非空的列表。

      • rules.resourceRules.namespaces ([]string)

        集合:合并期间保留唯一值

        namespaces 是限制匹配的目标的名字空间的列表。 指定一个目标名字空间的请求只会在以下某一个情况满足时进行匹配: (a) 此列表包含该目标名字空间或 (b) 此列表包含 *。 请注意,* 与所指定的任何名字空间匹配,但不会与未指定 名字空间的请求匹配 (请参阅 clusterScope 字段)。此列表可以为空,但前提是 clusterScope 为 true。

FlowSchemaStatus

FlowSchemaStatus 表示 FlowSchema 的当前状态。


  • conditions ([]FlowSchemaCondition)

    补丁策略:根据键 type 合并

    Map:合并期间保留根据键 type 保留其唯一值

    conditions 是 FlowSchema 当前状况的列表。

    FlowSchemaCondition 描述 FlowSchema 的状况。

    • conditions.lastTransitionTime (Time)

      lastTransitionTime 是状况上一次从一个状态转换为另一个状态的时间。

      Time 是对 time.Time 的封装。Time 支持对 YAML 和 JSON 进行正确封包。 为 time 包的许多函数方法提供了封装器。

    • conditions.message (string)

      message 是一条人类可读的消息,表示上一次转换有关的详细信息。

    • conditions.reason (string)

      reason 是状况上次转换原因的、驼峰格式命名的、唯一的一个词。

    • conditions.status (string)

      status 是状况的状态。可以是 True、False、Unknown。必需。

    • conditions.type (string)

      type 是状况的类型。必需。

FlowSchemaList

FlowSchemaList 是 FlowSchema 对象的列表。


  • apiVersion: flowcontrol.apiserver.k8s.io/v1

  • kind: FlowSchemaList

操作


get 读取指定的 FlowSchema

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

401: Unauthorized

get 读取指定 FlowSchema 的状态

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}/status

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

401: Unauthorized

list 列出或监视 FlowSchema 类别的对象

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas

参数

响应

200 (FlowSchemaList): OK

401: Unauthorized

create 创建 FlowSchema

HTTP 请求

POST /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas

参数

响应

200 (FlowSchema): OK

201 (FlowSchema): Created

202 (FlowSchema): Accepted

401: Unauthorized

update 替换指定的 FlowSchema

HTTP 请求

PUT /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • body: FlowSchema,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

201 (FlowSchema): Created

401: Unauthorized

update 替换指定的 FlowSchema 的状态

HTTP 请求

PUT /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}/status

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • body: FlowSchema,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

201 (FlowSchema): Created

401: Unauthorized

patch 部分更新指定的 FlowSchema

HTTP 请求

PATCH /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • body: Patch,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

201 (FlowSchema): Created

401: Unauthorized

patch 部分更新指定的 FlowSchema 的状态

HTTP 请求

PATCH /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}/status

参数

  • name (路径参数): string,必需

    FlowSchema 的名称。

  • body: Patch,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (FlowSchema): OK

201 (FlowSchema): Created

401: Unauthorized

delete 删除 FlowSchema

HTTP 请求

DELETE /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/{name}

参数

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 FlowSchema 的集合

HTTP 请求

DELETE /apis/flowcontrol.apiserver.k8s.io/v1/flowschemas

参数

响应

200 (Status): OK

401: Unauthorized

2 - LimitRange

LimitRange 设置名字空间中每个资源类别的资源用量限制。

apiVersion: v1

import "k8s.io/api/core/v1"

LimitRange

LimitRange 设置名字空间中每个资源类别的资源用量限制。


  • apiVersion: v1

  • kind: LimitRange

LimitRangeSpec

LimitRangeSpec 定义与类别匹配的资源的最小/最大使用限制。


  • limits ([]LimitRangeItem),必需

    原子:将在合并期间被替换

    limits 是强制执行的 LimitRangeItem 对象的列表。

    LimitRangeItem 定义与类别匹配的任意资源的最小/最大使用限制。

    • limits.type (string),必需

      此限制应用到的资源的类型。

    • limits.default (map[string]Quantity)

      资源限制被省略时按资源名称设定的默认资源要求限制值。

    • limits.defaultRequest (map[string]Quantity)

      defaultRequest 是资源请求被省略时按资源名称设定的默认资源要求请求值。

    • limits.max (map[string]Quantity)

      按资源名称针对这种类别的最大使用约束。

    • limits.maxLimitRequestRatio (map[string]Quantity)

      如果指定 maxLimitRequestRatio,则所指定的资源必须设置非零的请求和限制值, 且限制除以请求小于或等于这里列举的值;此属性用来表示所指定资源的最大突发用量。

    • limits.min (map[string]Quantity)

      按资源名称区分的,针对这种类别对象的最小用量约束。

LimitRangeList

LimitRangeList 是 LimitRange 项的列表。


  • apiVersion: v1

  • kind: LimitRangeList

操作


get 读取指定的 LimitRange

HTTP 请求

GET /api/v1/namespaces/{namespace}/limitranges/{name}

参数

  • name (路径参数): string,必需

    LimitRange 的名称。

  • namespace (路径参数): string,必需

    namespace

  • pretty (查询参数): string

    pretty

响应

200 (LimitRange): OK

401: Unauthorized

list 列出或监视 LimitRange 类别的对象

HTTP 请求

GET /api/v1/namespaces/{namespace}/limitranges

参数

响应

200 (LimitRangeList): OK

401: Unauthorized

list 列出或监视 LimitRange 类别的对象

HTTP 请求

GET /api/v1/limitranges

参数

响应

200 (LimitRangeList): OK

401: Unauthorized

create 创建 LimitRange

HTTP 请求

POST /api/v1/namespaces/{namespace}/limitranges

参数

响应

200 (LimitRange): OK

201 (LimitRange): Created

202 (LimitRange): Accepted

401: Unauthorized

update 替换指定的 LimitRange

HTTP 请求

PUT /api/v1/namespaces/{namespace}/limitranges/{name}

参数

  • name (路径参数): string,必需

    LimitRange 的名称。

  • namespace (路径参数): string,必需

    namespace

  • body: LimitRange,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • pretty (查询参数): string

    pretty

响应

200 (LimitRange): OK

201 (LimitRange): Created

401: Unauthorized

patch 部分更新指定的 LimitRange

HTTP 请求

PATCH /api/v1/namespaces/{namespace}/limitranges/{name}

参数

  • name (路径参数): string,必需

    LimitRange 的名称。

  • namespace (路径参数): string,必需

    namespace

  • body: Patch,必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (LimitRange): OK

201 (LimitRange): Created

401: Unauthorized

delete 删除 LimitRange

HTTP 请求

DELETE /api/v1/namespaces/{namespace}/limitranges/{name}

参数

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 LimitRange 的集合

HTTP 请求

DELETE /api/v1/namespaces/{namespace}/limitranges

参数

响应

200 (Status): OK

401: Unauthorized

3 - ResourceQuota

ResourceQuota 设置每个命名空间强制执行的聚合配额限制。

apiVersion: v1

import "k8s.io/api/core/v1"

ResourceQuota

ResourceQuota 设置每个命名空间强制执行的聚合配额限制。


ResourceQuotaSpec

ResourceQuotaSpec 定义为 Quota 强制执行所需的硬限制。


  • hard (map[string]Quantity)

    hard 是每种指定资源所需的硬性限制集合。 更多信息: https://kubernetes.io/docs/concepts/policy/resource-quotas/

  • scopeSelector (ScopeSelector)

    scopeSelector 也是一组过滤器的集合,和 scopes 类似, 必须匹配配额所跟踪的每个对象,但使用 ScopeSelectorOperator 结合可能的值来表示。 对于要匹配的资源,必须同时匹配 scopes 和 scopeSelector(如果在 spec 中设置了的话)。

    scope 选择算符表示的是由限定范围的资源选择算符进行逻辑与运算得出的结果。

    • scopeSelector.matchExpressions ([]ScopedResourceSelectorRequirement)

      **原子:将在合并期间被替换**
      

      按资源范围划分的范围选择算符需求列表。

      限定范围的资源选择算符需求是一种选择算符,包含值、范围名称和将二者关联起来的运算符。

      • scopeSelector.matchExpressions.operator (string),必需

        表示范围与一组值之间的关系。有效的运算符为 In、NotIn、Exists、DoesNotExist。

      • scopeSelector.matchExpressions.scopeName (string),必需

        选择器所适用的范围的名称。

      • scopeSelector.matchExpressions.values ([]string)

          **原子:将在合并期间被替换**
        

        字符串值数组。 如果操作符是 In 或 NotIn,values 数组必须是非空的。 如果操作符是 Exists 或 DoesNotExist,values 数组必须为空。 该数组将在策略性合并补丁操作期间被替换。

  • scopes ([]string)

    原子:将在合并期间被替换

    一个匹配被配额跟踪的所有对象的过滤器集合。 如果没有指定,则默认匹配所有对象。

ResourceQuotaStatus

ResourceQuotaStatus 定义硬性限制和观测到的用量。


ResourceQuotaList

ResourceQuotaList 是 ResourceQuota 列表。


操作


get 读取指定的 ResourceQuota

HTTP 请求

GET /api/v1/namespaces/{namespace}/resourcequotas/{name}

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

401: Unauthorized

get 读取指定的 ResourceQuota 的状态

HTTP 请求

GET /api/v1/namespaces/{namespace}/resourcequotas/{name}/status

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

401: Unauthorized

list 列出或监视 ResourceQuota 类别的对象

HTTP 请求

GET /api/v1/namespaces/{namespace}/resourcequotas

参数

响应

200 (ResourceQuotaList): OK

401: Unauthorized

list 列出或监视 ResourceQuota 类别的对象

HTTP 请求

GET /api/v1/resourcequotas

参数

响应

200 (ResourceQuotaList): OK

401: Unauthorized

create 创建一个 ResourceQuota

HTTP 请求

POST /api/v1/namespaces/{namespace}/resourcequotas

参数

响应

200 (ResourceQuota): OK

201 (ResourceQuota): Created

202 (ResourceQuota): Accepted

401: Unauthorized

update 更新指定的 ResourceQuota

HTTP 请求

PUT /api/v1/namespaces/{namespace}/resourcequotas/{name}

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • body: ResourceQuota, 必需

  • dryRun查询参数): string

    dryRun

  • fieldManager查询参数): string

    fieldManager

  • fieldValidation查询参数): string

    fieldValidation

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

201 (ResourceQuota): Created

401: Unauthorized

update 更新指定 ResourceQuota 的状态

HTTP 请求

PUT /api/v1/namespaces/{namespace}/resourcequotas/{name}/status

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • body: ResourceQuota, 必需

  • dryRun查询参数): string

    dryRun

  • fieldManager查询参数): string

    fieldManager

  • fieldValidation查询参数): string

    fieldValidation

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

201 (ResourceQuota): Created

401: Unauthorized

patch 部分更新指定的 ResourceQuota

HTTP 请求

PATCH /api/v1/namespaces/{namespace}/resourcequotas/{name}

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • body: Patch, 必需

  • dryRun查询参数): string

    dryRun

  • fieldManager查询参数): string

    fieldManager

  • fieldValidation查询参数): string

    fieldValidation

  • force查询参数): boolean

    force

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

201 (ResourceQuota): Created

401: Unauthorized

patch 部分更新指定 ResourceQuota 的状态

HTTP 请求

PATCH /api/v1/namespaces/{namespace}/resourcequotas/{name}/status

参数

  • name路径参数): string, 必需

    ResourceQuota 的名称。

  • namespace路径参数): string, 必需

    namespace

  • body: Patch, 必需

  • dryRun查询参数): string

    dryRun

  • fieldManager查询参数): string

    fieldManager

  • fieldValidation查询参数): string

    fieldValidation

  • force查询参数): boolean

    force

  • pretty查询参数): string

    pretty

响应

200 (ResourceQuota): OK

201 (ResourceQuota): Created

401: Unauthorized

delete 删除 ResourceQuota

HTTP 请求

DELETE /api/v1/namespaces/{namespace}/resourcequotas/{name}

参数

响应

200 (ResourceQuota): OK

202 (ResourceQuota): Accepted

401: Unauthorized

deletecollection 删除 ResourceQuota 的集合

HTTP 请求

DELETE /api/v1/namespaces/{namespace}/resourcequotas

参数

响应

200 (Status): OK

401: Unauthorized

4 - NetworkPolicy

NetworkPolicy 描述针对一组 Pod 所允许的网络流量。

apiVersion: networking.k8s.io/v1

import "k8s.io/api/networking/v1"

NetworkPolicy

NetworkPolicy 描述针对一组 Pod 所允许的网络流量。


NetworkPolicySpec

NetworkPolicySpec 定义特定 NetworkPolicy 所需的所有信息.


  • podSelector (LabelSelector),必需

    podSelector 选择此网络策略所适用的一组 Pod。一组 Ingress 入口策略将应用于此字段选择的所有 Pod。 多个网络策略可以选择同一组 Pod。 在这种情况下,这些列表条目的 Ingress 规则效果会被叠加。此字段不是可选的,并且遵循标准标签选择算符语义。 空值的 podSelector 匹配此命名空间中的所有 Pod。

  • policyTypes ([]string)

    原子:将在合并期间被替换

    policyTypes 是 NetworkPolicy 相关的规则类型列表。有效选项为 [“Ingress”][“Egress”][“Ingress”, “Egress”]。 如果不指定此字段,则默认值取决是否存在 Ingress 或 Egress 规则;规则里包含 Egress 部分的策略将会影响出站流量, 并且所有策略(无论它们是否包含 Ingress 部分)都将会影响 入站流量。 如果要仅定义出站流量策略,则必须明确指定 [ "Egress" ]。 同样,如果要定义一个指定拒绝所有出站流量的策略,则必须指定一个包含 Egress 的 policyTypes 值 (因为这样不包含 Egress 部分的策略,将会被默认为只有 [ "Ingress" ] )。此字段在 1.8 中为 Beta。

  • ingress ([]NetworkPolicyIngressRule)

    原子:将在合并期间被替换

    ingress 是应用到所选 Pod 的入站规则列表。在没有被任何 NetworkPolicy 选择到 Pod 的情况下(同时假定集群策略允许对应流量), 或者如果流量源是 Pod 的本地节点,或者流量与所有 NetworkPolicy 中的至少一个入站规则(Ingress) 匹配, 则进入 Pod 的流量是被允许的。如果此字段为空,则此 NetworkPolicy 不允许任何入站流量 (这种设置用来确保它所选择的 Pod 在默认情况下是被隔离的)。

    NetworkPolicyIngressRule 定义 NetworkPolicySpec 的 podSelector 所选 Pod 的入站规则的白名单列表, 流量必须同时匹配 ports 和 from。

    • ingress.from ([]NetworkPolicyPeer)

      原子:将在合并期间被替换

      from 是流量来源列表,列表中的来源可以访问被此规则选中的 Pod。此列表中的流量来源使用逻辑或操作进行组合。 如果此字段为空值或缺失(未设置), 则此规则匹配所有流量来源(也即允许所有入站流量)。如果此字段存在并且至少包含一项来源,则仅当流量与来自列表中的至少一项匹配时, 此规则才允许流量访问被选中的 Pod 集合。

      NetworkPolicyPeer 描述了允许进出流量的对等点。这个参数只允许某些字段组合。

      • ingress.from.ipBlock (IPBlock)

        ipBlock 针对特定 IPBlock 定义策略。如果设置了此字段,则不可以设置其他字段。

        IPBlock 定义一个特定的 CIDR 范围(例如 192.168.1.0/242001:db8::/64), 来自这个 IP 范围的流量来源将会被允许访问与 NetworkPolicySpec 的 podSelector 匹配的 Pod 集合。 except 字段则设置应排除在此规则之外的 CIDR 范围。

        • ingress.from.ipBlock.cidr (string),必需

          cidr 是表示 IP 组块的字符串,例如 "192.168.1.0/24""2001:db8::/64"

        • ingress.from.ipBlock.except ([]string)

          原子:将在合并期间被替换

          except 是一个由 CIDR 范围组成的列表,其中指定的 CIDR 都应排除在此 IP 区块范围之外。 例如 "192.168.1.0/24""2001:db8::/64"。 如果 except 字段的值超出 ipBlock.cidr 的范围则被视为无效策略。

      • ingress.from.namespaceSelector (LabelSelector)

        namespaceSelector 使用集群范围标签来选择特定的 Namespace。此字段遵循标准标签选择算符语义; 如果此字段存在但为空值,则会选择所有名字空间。

        如果 podSelector 也被定义了, 那么 NetworkPolicyPeer 将选择那些同时满足 namespaceSelector 所选名字空间下和 podSelector 规则匹配的 Pod。 反之选择 namespaceSelector 所选名字空间下所有的 Pod。

      • ingress.from.podSelector (LabelSelector)

        podSelector 是负责选择 Pod 的标签选择算符。该字段遵循标准标签选择算符语义;如果字段存在但为空值,则选择所有 Pod。

        如果 namespaceSelector 也被定义,那么 NetworkPolicyPeer 将选择那些同时满足 namespaceSelector 定义的名字空间下和 podSelector 规则匹配的 Pod。 反之会在策略所在的名字空间中选择与 podSelector 匹配的 Pod。

    • ingress.ports ([]NetworkPolicyPort)

      原子:将在合并期间被替换

      ports 是在此规则选中的 Pod 上应可访问的端口列表。此列表中的个项目使用逻辑或操作组合。如果此字段为空或缺失, 则此规则匹配所有端口(进入流量可访问任何端口)。 如果此字段存在并且包含至少一个有效值,则此规则仅在流量至少匹配列表中的一个端口时才允许访问。

      NetworkPolicyPort 定义可以连接的端口

      • ingress.ports.port (IntOrString)

        port 表示符合给定协议的端口。字段值可以是 Pod 上的数字或命名端口。如果未提供此字段,则匹配所有端口名和端口号。 如果定义了,则仅允许对给定的协议和端口的入口流量。

        IntOrString 是一种可以包含 int32 或字符串值的类型。在 JSON 或 YAML 编组和解组中使用时,它会生成或使用内部类型。 例如,这允许你拥有一个可以接受名称或数字的 JSON 字段。

      • ingress.ports.endPort (int32)

        endPort 表示如果设置了此字段,则策略应该允许 port 与 endPort 之间(包含二者)的所有端口。 如果未定义 port 或将 port 字段值为命名端口(字符串),则不可以使用 endPort。 endPort 必须等于或大于 port 值。

      • ingress.ports.protocol (string)

        protocol 表示流量必须匹配的网络协议(TCP、UDP 或 SCTP)。如果未指定,此字段默认为 TCP。

  • egress ([]NetworkPolicyEgressRule)

    原子:将在合并期间被替换

    egress 是应用到所选 Pod 的出站规则的列表。如果没有 NetworkPolicy 选中指定 Pod(并且其他集群策略也允许出口流量), 或者在所有通过 podSelector 选中了某 Pod 的 NetworkPolicy 中,至少有一条出站规则与出站流量匹配, 则该 Pod 的出站流量是被允许的。 如果此字段为空,则此 NetworkPolicy 拒绝所有出站流量(这策略可以确保它所选中的 Pod 在默认情况下是被隔离的)。 egress 字段在 1.8 中为 Beta 级别。

    NetworkPolicyEgressRule 针对被 NetworkPolicySpec 的 podSelector 所选中 Pod,描述其被允许的出站流量。 流量必须同时匹配 ports 和 to 设置。此类型在 1.8 中为 Beta 级别。

    • egress.to ([]NetworkPolicyPeer)

      原子:将在合并期间被替换

      to 是针对此规则所选择的 Pod 的出口流量的目的地列表。此列表中的目的地使用逻辑或操作进行组合。如果此字段为空或缺失, 则此规则匹配所有目的地(流量不受目的地限制)。如果此字段存在且至少包含一项目的地,则仅当流量与目标列表中的至少一个匹配时, 此规则才允许出口流量。

      NetworkPolicyPeer 描述允许进出流量的对等点。这个对象只允许某些字段组合。

      • egress.to.ipBlock (IPBlock)

        ipBlock 针对特定的 IP 区块定义策略。如果设置了此字段,则其他不可以设置其他字段。

        IPBlock 描述一个特定的 CIDR 范围(例如 192.168.1.0/242001:db8::/64), 与 NetworkPolicySpec 的 podSelector 匹配的 Pod 将被允许连接到这个 IP 范围,作为其出口流量目的地。 except 字段则设置了不被此规则影响的 CIDR 范围。

        • egress.to.ipBlock.cidr (string),必需

          cidr 是用来表达 IP 组块的字符串,例如 "192.168.1.0/24""2001:db8::/64"

        • egress.to.ipBlock.except ([]string)

          原子:将在合并期间被替换

          except 定义不应包含在 ipBlock 内的 CIDR 范围列表。例如 "192.168.1.0/24""2001:db8::/64"。 如果 except 的值超出 ipBlock.cidr 的范围则被拒绝。

      • egress.to.namespaceSelector (LabelSelector)

        namespaceSelector 使用集群范围标签来选择特定的名字空间。该字段遵循标准标签选择算符语义; 如果字段存在但为空值,那会选择所有名字空间。

        如果 podSelector 也被定义了, 那么 NetworkPolicyPeer 将选择那些同时满足 namespaceSelector 指定的名字空间下和 podSelector 规则匹配的 Pod。 反之选择 namespaceSelector 指定的名字空间下所有的 Pod。

      • egress.to.podSelector (LabelSelector)

        podSelector 是负责选择一组 Pod 的标签选择算符。该字段遵循标准标签选择算符语义; 如果字段存在但为空值,则选择所有 Pod。

        如果 egress.to.namespaceSelector 也被定义,则 NetworkPolicyPeer 将选择 namespaceSelector 所指定的名字空间下和 podSelector 规则匹配的 Pod。 反之会在策略所属的名字空间中选择与 podSelector 匹配的 Pod。

    • egress.ports ([]NetworkPolicyPort)

      原子:将在合并期间被替换

      ports 是出站流量目的地的端口列表。此列表中的各个项目使用逻辑或操作进行组合。如果此字段为空或缺失, 则此规则匹配所有端口(可访问出口流量目的地的任何端口)。如果此字段存在并且包含至少一个有效值, 则此规则仅在流量与列表中的至少一个端口匹配时才允许访问。

      NetworkPolicyPort 定义出口流量目的地的端口。

      • egress.ports.port (IntOrString)

        port 表示符合给定协议的端口。字段值可以是 Pod 上的数字或命名端口。如果未提供此字段,则匹配所有端口名和端口号。 如果定义此字段,则仅允许针对给定的协议和端口的出站流量。

        IntOrString 是一种可以包含 int32 或字符串值的类型。在 JSON 或 YAML 编组和解组中使用时,它会生成或使用内部类型。 例如,这允许你拥有一个可以接受名称或数字的 JSON 字段。

      - **egress.ports.endPort** (int32)
      

      如果设置了 endPort,则用来指定策略所允许的从 port 到 endPort 的端口范围(包含边界值)。 如果未设置 port 或 port 字段值为端口名称(字符串),则不可以指定 endPort。 endPort 必须等于或大于 port 值。

      • egress.ports.protocol (string)

        protocol 表示流量必须匹配的网络协议(TCP、UDP 或 SCTP)。如果未指定,此字段默认为 TCP。

NetworkPolicyList

NetworkPolicyList 是 NetworkPolicy 的集合。


  • apiVersion: networking.k8s.io/v1

  • kind: NetworkPolicyList

  • items ([]NetworkPolicy),必需

    items 是 NetworkPolicy 的列表。

操作


get 读取指定的 NetworkPolicy

HTTP 请求

GET /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}

参数

  • name (路径参数): string,必需

    NetworkPolicy 的名称。

  • namespace (路径参数): string,必需

    namespace

  • pretty (查询参数): string

    pretty

响应

200 (NetworkPolicy): OK

401: Unauthorized

list 列出或监视 NetworkPolicy 类型的对象

HTTP 请求

GET /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies

参数

  • namespace (路径参数): string,必需

    namespace

  • limit (查询参数): integer

    limit

  • pretty (查询参数): string

    pretty

  • watch (查询参数): boolean

    watch

响应

200 (NetworkPolicyList): OK

401: Unauthorized

list 列出或监视 NetworkPolicy 类

HTTP Request

GET /apis/networking.k8s.io/v1/networkpolicies

参数

  • limit (查询参数): integer

    limit

  • pretty (查询参数): string

    pretty

  • watch (查询参数): boolean

    watch

响应

200 (NetworkPolicyList): OK

401: Unauthorized

create 创建 NetworkPolicy

HTTP 请求

POST /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies

参数

  • namespace (路径参数): string,必需

  • body: NetworkPolicy,必需

响应

200 (NetworkPolicy): OK

201 (NetworkPolicy): Created

202 (NetworkPolicy): Accepted

401: Unauthorized

update 替换指定的 NetworkPolicy

HTTP 请求

PUT /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}

参数

  • name (路径参数): string,必需

    NetworkPolicy 的名称。

响应

200 (NetworkPolicy): OK

201 (NetworkPolicy): Created

401: Unauthorized

patch 部分更新指定的 NetworkPolicy

HTTP 请求

PATCH /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}

参数

  • name (路径参数): string,必需

    NetworkPolicy 的名称。

  • namespace (路径参数): string,必需

    namespace

  • body: Patch,必需

响应

200 (NetworkPolicy): OK

201 (NetworkPolicy): Created

401: Unauthorized

delete 删除 NetworkPolicy

HTTP 请求

DELETE /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}

参数

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 NetworkPolicy 的集合

HTTP 请求

DELETE /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies

参数

响应

200 (Status): OK

401: Unauthorized

5 - PodDisruptionBudget

PodDisruptionBudget 是一个对象,用于定义可能对一组 Pod 造成的最大干扰。

apiVersion: policy/v1

import "k8s.io/api/policy/v1"

PodDisruptionBudget

PodDisruptionBudget 是一个对象,用于定义可能对一组 Pod 造成的最大干扰。


  • apiVersion: policy/v1

  • kind: PodDisruptionBudget

PodDisruptionBudgetSpec

PodDisruptionBudgetSpec 是对 PodDisruptionBudget 的描述。


  • maxUnavailable (IntOrString)

    如果 “selector” 所选中的 Pod 中最多有 “maxUnavailable” Pod 在驱逐后不可用(即去掉被驱逐的 Pod 之后),则允许驱逐。 例如,可以通过将此字段设置为 0 来阻止所有自愿驱逐。此字段是与 “minAvailable” 互斥的设置。

    IntOrString 是一种可以包含 int32 或字符串数值的类型。在 JSON 或 YAML 编组和解组时, 会生成或使用内部类型。例如,此类型允许你定义一个可以接受名称或数字的 JSON 字段。

  • minAvailable (IntOrString)

    如果 “selector” 所选中的 Pod 中,至少 “minAvailable” 个 Pod 在驱逐后仍然可用(即去掉被驱逐的 Pod 之后),则允许驱逐。 因此,你可以通过将此字段设置为 “100%” 来禁止所有自愿驱逐。

    IntOrString 是一种可以包含 int32 或字符串数值的类型。在 JSON 或 YAML 编组和解组时, 会生成或使用内部类型。例如,此类型允许你定义一个可以接受名称或数字的 JSON 字段。

  • selector (LabelSelector)

    标签查询,用来选择其驱逐由干扰预算来管理的 Pod 集合。 选择算符为 null 时将不会匹配任何 Pod,而空 ({}) 选择算符将选中名字空间内的所有 Pod。

  • unhealthyPodEvictionPolicy (string)

    unhealthyPodEvictionPolicy 定义不健康的 Pod 应被考虑驱逐时的标准。 当前的实现将健康的 Pod 视为具有 status.conditions 项且 type="Ready"、status="True" 的 Pod。

    有效的策略是 IfHealthyBudget 和 AlwaysAllow。 如果没有策略被指定,则使用与 IfHealthyBudget 策略对应的默认行为。

    IfHealthyBudget 策略意味着正在运行(status.phase="Running")但还不健康的 Pod 只有在被守护的应用未受干扰(status.currentHealthy 至少等于 status.desiredHealthy) 时才能被驱逐。健康的 Pod 将受到 PDB 的驱逐。

    AlwaysAllow 策略意味着无论是否满足 PDB 中的条件,所有正在运行(status.phase="Running")但还不健康的 Pod 都被视为受干扰且可以被驱逐。这意味着受干扰应用的透视运行 Pod 可能没有机会变得健康。 健康的 Pod 将受到 PDB 的驱逐。

    将来可能会添加其他策略。如果客户端在该字段遇到未识别的策略,则做出驱逐决定的客户端应禁止驱逐不健康的 Pod。

PodDisruptionBudgetStatus

PodDisruptionBudgetStatus 表示有关此 PodDisruptionBudget 状态的信息。状态可能会反映系统的实际状态。


  • currentHealthy (int32),必需

    当前健康 Pod 的数量。

  • desiredHealthy (int32),必需

    健康 Pod 的最小期望值。

  • disruptionsAllowed (int32),必需

    当前允许的 Pod 干扰计数。

  • expectedPods (int32),必需

    此干扰预算计入的 Pod 总数

  • conditions ([]Condition)

    补丁策略:根据 type 键执行合并操作

    Map:键 type 的唯一值将在合并期间被保留

    conditions 包含 PDB 的状况。干扰控制器会设置 DisruptionAllowed 状况。 以下是 reason 字段的已知值(将来可能会添加其他原因):

    • SyncFailed:控制器遇到错误并且无法计算允许的干扰计数。因此不允许任何干扰,且状况的状态将变为 False。
    • InsufficientPods:Pod 的数量只能小于或等于 PodDisruptionBudget 要求的数量。 不允许任何干扰,且状况的状态将是 False。
    • SufficientPods:Pod 个数超出 PodDisruptionBudget 所要求的阈值。 此状况为 True 时,基于 disruptsAllowed 属性确定所允许的干扰数目。

    Condition 包含此 API 资源当前状态的一个方面的详细信息。

    • conditions.lastTransitionTime (Time),必需

      lastTransitionTime 是状况最近一次从一种状态转换到另一种状态的时间。 这种变化通常出现在下层状况发生变化的时候。如果无法了解下层状况变化,使用 API 字段更改的时间也是可以接受的。

      Time 是 time.Time 的包装器,它支持对 YAML 和 JSON 的正确编组。 time 包的许多工厂方法提供了包装器。

    • conditions.message (string),必需

      message 是一条人类可读的消息,指示有关转换的详细信息。它可能是一个空字符串。

    • conditions.reason (string),必需

      reason 包含一个程序标识符,指示状况最后一次转换的原因。 特定状况类型的生产者可以定义该字段的预期值和含义,以及这些值是否可被视为有保证的 API。 该值应该是 CamelCase 字符串。此字段不能为空。

    • conditions.status (string),必需

      状况的状态为 True、False、Unknown 之一。

    • conditions.type (string),必需

      CamelCase 或 foo.example.com/CamelCase 形式的状况类型。

    • conditions.observedGeneration (int64)

      observedGeneration 表示设置状况时所基于的 .metadata.generation。 例如,如果 .metadata.generation 当前为 12,但 .status.conditions[x].observedGeneration 为 9, 则状况相对于实例的当前状态已过期。

  • disruptedPods (map[string]Time)

    disruptedPods 包含有关 Pod 的一些信息,这些 Pod 的驱逐操作已由 API 服务器上的 eviction 子资源处理程序处理, 但尚未被 PodDisruptionBudget 控制器观察到。 从 API 服务器处理驱逐请求到 PDB 控制器看到该 Pod 已标记为删除(或超时后),Pod 将记录在此映射中。 映射中的键名是 Pod 的名称,键值是 API 服务器处理驱逐请求的时间。 如果删除没有发生并且 Pod 仍然存在,PodDisruptionBudget 控制器将在一段时间后自动将 Pod 从列表中删除。 如果一切顺利,此映射大部分时间应该是空的。映射中的存在大量条目可能表明 Pod 删除存在问题。

    Time 是 time.Time 的包装器,它支持对 YAML 和 JSON 的正确编组。 time 包的许多工厂方法提供了包装器。

  • observedGeneration (int64)

    更新此 PDB 状态时观察到的最新一代。 DisruptionsAllowed 和其他状态信息仅在 observedGeneration 等于 PDB 的对象的代数时才有效。

PodDisruptionBudgetList

PodDisruptionBudgetList 是 PodDisruptionBudget 的集合。


  • apiVersion: policy/v1

  • kind: PodDisruptionBudgetList

操作


get 读取指定的 PodDisruptionBudget

HTTP 请求

GET /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • namespace (路径参数): string,必需

    namespace

  • pretty (查询参数): string

    pretty

响应

200 (PodDisruptionBudget): OK

401: Unauthorized

get 读取指定 PodDisruptionBudget 的状态

HTTP 请求

GET /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}/status

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • namespace (路径参数): string,必需

    namespace

  • pretty (查询参数): string

    pretty

响应

200 (PodDisruptionBudget): OK

401: Unauthorized

list 列出或监视 PodDisruptionBudget 类型的对象

HTTP 请求

GET /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets

参数

  • namespace (路径参数): string,必需

    namespace

  • limit (查询参数): integer

    limit

  • pretty (查询参数): string

    pretty

  • watch (查询参数): boolean

    watch

响应

200 (PodDisruptionBudgetList): OK

401: Unauthorized

list 列出或监视 PodDisruptionBudget 类型的对象

HTTP 请求

GET /apis/policy/v1/poddisruptionbudgets

参数

  • limit (查询参数): integer

    limit

  • pretty (查询参数): string

    pretty

  • watch (查询参数): boolean

    watch

响应

200 (PodDisruptionBudgetList): OK

401: Unauthorized

create 创建一个 PodDisruptionBudget

HTTP 请求

POST /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets

参数

  • namespace (路径参数): string,必需

    namespace

  • dryRun (查询参数): string

    dryRun

  • pretty (查询参数): string

    pretty

响应

200 (PodDisruptionBudget): OK

201 (PodDisruptionBudget): Created

202 (PodDisruptionBudget): Accepted

401: Unauthorized

update 替换指定的 PodDisruptionBudget

HTTP 请求

PUT /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • namespace (路径参数): string,必需

    namespace

  • dryRun (查询参数): string

    dryRun

响应

200 (PodDisruptionBudget): OK

201 (PodDisruptionBudget): Created

401: Unauthorized

update 替换指定 PodDisruptionBudget 的状态

HTTP 请求

PUT /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}/status

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • namespace (路径参数): string,必需

    namespace

响应

200 (PodDisruptionBudget): OK

201 (PodDisruptionBudget): Created

401: Unauthorized

patch 部分更新指定的 PodDisruptionBudget

HTTP 请求

PATCH /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称

  • namespace (路径参数): string,必需

    namespace

  • dryRun (查询参数): string

    dryRun

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (PodDisruptionBudget): OK

201 (PodDisruptionBudget): Created

401: Unauthorized

patch 部分更新指定 PodDisruptionBudget 的状态

HTTP 请求

PATCH /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}/status

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • namespace (路径参数): string,必需

    namespace

  • dryRun (查询参数): string

    dryRun

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (PodDisruptionBudget): OK

201 (PodDisruptionBudget): Created

401: Unauthorized

delete 删除 PodDisruptionBudget

HTTP 请求

DELETE /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets/{name}

参数

  • name (路径参数): string,必需

    PodDisruptionBudget 的名称。

  • dryRun (查询参数): string

    dryRun

  • pretty (查询参数): string

    pretty

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 PodDisruptionBudget 的集合

HTTP Request

DELETE /apis/policy/v1/namespaces/{namespace}/poddisruptionbudgets

参数

  • dryRun (查询参数): string

    dryRun

  • limit (查询参数): integer

    limit

  • pretty (查询参数): string

    pretty

响应

200 (Status): OK

401: Unauthorized

6 - PriorityLevelConfiguration v1

PriorityLevelConfiguration 表示一个优先级的配置。

apiVersion: flowcontrol.apiserver.k8s.io/v1

import "k8s.io/api/flowcontrol/v1"

PriorityLevelConfiguration

PriorityLevelConfiguration 表示一个优先级的配置。


  • apiVersion: flowcontrol.apiserver.k8s.io/v1

  • kind: PriorityLevelConfiguration

PriorityLevelConfigurationSpec

PriorityLevelConfigurationSpec 指定一个优先级的配置。


  • exempt (ExemptPriorityLevelConfiguration)

    exempt 指定了对于豁免优先级的请求如何处理。 如果 type 取值为 "Limited",则此字段必须为空。 如果 type 取值为 "Exempt",则此字段可以非空。 如果为空且 type 取值为 "Exempt",则应用 ExemptPriorityLevelConfiguration 的默认值。

    ExemptPriorityLevelConfiguration 描述豁免请求处理的可配置方面。 在强制豁免配置对象中,与 spec 中的其余部分不同,此处字段的取值可以被授权用户修改。

    • exempt.lendablePercent (int32)

      lendablePercent 规定该级别的 NominalCL 可被其他优先级租借的百分比。 此字段的值必须在 0 到 100 之间,包括 0 和 100,默认为 0。 其他级别可以从该级别借用的席位数被称为此级别的 LendableConcurrencyLimit(LendableCL),定义如下。

      LendableCL(i) = round( NominalCL(i) * lendablePercent(i)/100.0 )

    • exempt.nominalConcurrencyShares (int32)

      nominalConcurrencyShares(NCS)也被用来计算该级别的 NominalConcurrencyLimit(NominalCL)。 字段值是为该优先级保留的执行席位的数量。这一设置不限制此优先级别的调度行为, 但会通过借用机制影响其他优先级。服务器的并发限制(ServerCL)会按照各个优先级的 NCS 值按比例分配:

      NominalCL(i) = ceil( ServerCL * NCS(i) / sum_ncs ) sum_ncs = sum[priority level k] NCS(k)

      较大的数字意味着更大的标称并发限制,且将影响其他优先级。此字段的默认值为零。

  • limited (LimitedPriorityLevelConfiguration)

    limited 指定如何为某个受限的优先级处理请求。 当且仅当 type"Limited" 时,此字段必须为非空。

    LimitedPriorityLevelConfiguration 指定如何处理需要被限制的请求。它解决两个问题:

    • 如何限制此优先级的请求?
    • 应如何处理超出此限制的请求?
    • limited.borrowingLimitPercent (int32)

      borrowingLimitPercent 配置如果存在,则可用来限制此优先级可以从其他优先级中租借多少资源。 该限制被称为该级别的 BorrowingConcurrencyLimit(BorrowingCL),它限制了该级别可以同时租借的资源总数。 该字段保存了该限制与该级别标称并发限制之比。当此字段非空时,必须为正整数,并按以下方式计算限制值:

      BorrowingCL(i) = round(NominalCL(i) * borrowingLimitPercent(i) / 100.0)

      该字段值可以大于100,表示该优先级可以大于自己标称并发限制(NominalCL)。当此字段为 nil 时,表示无限制。

    • limited.lendablePercent (int32)

      lendablePercent 规定了 NominalCL 可被其他优先级租借资源数百分比。 此字段的值必须在 0 到 100 之间,包括 0 和 100,默认为 0。 其他级别可以从该级别借用的资源数被称为此级别的 LendableConcurrencyLimit(LendableCL),定义如下。

      LendableCL(i) = round( NominalCL(i) * lendablePercent(i)/100.0 )

    • limited.limitResponse (LimitResponse)

      limitResponse 指示如何处理当前无法立即执行的请求。

      LimitResponse 定义如何处理当前无法立即执行的请求。

      • limited.limitResponse.type (string),必需

        type 是 “Queue” 或 “Reject”。此字段必须设置。 “Queue” 意味着在到达时无法被执行的请求可以被放到队列中,直到它们被执行或者队列长度超出限制为止。 “Reject” 意味着到达时无法执行的请求将被拒绝。

      • limited.limitResponse.queuing (QueuingConfiguration)

        queuing 包含排队所用的配置参数。只有 type"Queue" 时,此字段才可以为非空。

        QueuingConfiguration 保存排队所用的配置参数。

        • limited.limitResponse.queuing.handSize (int32)

          handSize 是一个小的正数,用于配置如何将请求随机分片到队列中。 当以该优先级将请求排队时,将对请求的流标识符(字符串对)进行哈希计算, 该哈希值用于打乱队列队列的列表,并处理此处指定的一批请求。 请求被放入这一批次中最短的队列中。 handSize 不得大于 queues,并且应该明显更小(以便几个大的流量不会使大多数队列饱和)。 有关设置此字段的更多详细指导,请参阅面向用户的文档。此字段的默认值为 8。

        • limited.limitResponse.queuing.queueLengthLimit (int32)

          queueLengthLimit 是任意时刻允许在此优先级的给定队列中等待的请求数上限; 额外的请求将被拒绝。 此值必须是正数。如果未指定,则默认为 50。

        • limited.limitResponse.queuing.queues (int32)

          queues 是这个优先级的队列数。此队列在每个 API 服务器上独立存在。此值必须是正数。 将其设置为 1 相当于禁止了混洗分片操作,进而使得对相关流模式的区分方法不再有意义。 此字段的默认值为 64。

    • limited.nominalConcurrencyShares (int32)

      nominalConcurrencyShares(NCS)用于计算该优先级的标称并发限制(NominalCL)。 NCS 表示可以在此优先级同时运行的席位数量上限,包括来自本优先级的请求, 以及从此优先级租借席位的其他级别的请求。 服务器的并发度限制(ServerCL)根据 NCS 值按比例分别给各 Limited 优先级:

      NominalCL(i) = ceil( ServerCL * NCS(i) / sum_ncs ) sum_ncs = sum[priority level k] NCS(k)

      较大的数字意味着更大的标称并发限制,但是这将牺牲其他优先级的资源。

  • type (string),必需

    type 指示此优先级是否遵从有关请求执行的限制。 取值为 "Exempt" 意味着此优先级的请求不遵从某个限制(且因此从不排队)且不会减损其他优先级可用的容量。 取值为 "Limited" 意味着 (a) 此优先级的请求遵从这些限制且 (b) 服务器某些受限的容量仅可用于此优先级。必需。

PriorityLevelConfigurationStatus

PriorityLevelConfigurationStatus 表示 “请求优先级” 的当前状况。


  • conditions ([]PriorityLevelConfigurationCondition)

    补丁策略:基于键 type 合并

    Map:合并期间保留根据键 type 保留其唯一值

    conditions 是 “请求优先级” 的当前状况。

    PriorityLevelConfigurationCondition 定义优先级的状况。

    • conditions.lastTransitionTime (Time)

      lastTransitionTime 是状况上次从一个状态转换为另一个状态的时间。

      Time 是对 time.Time 的封装。Time 支持对 YAML 和 JSON 进行正确封包。 为 time 包的许多函数方法提供了封装器。

    • conditions.message (string)

      message 是人类可读的消息,指示有关上次转换的详细信息。

    • conditions.reason (string)

      reason 是状况上次转换原因的、驼峰格式命名的、唯一的一个词。

    • conditions.status (string)

      status 表示状况的状态,取值为 True、False 或 Unknown 之一。必需。

    • conditions.type (string)

      type 表示状况的类型,必需。

PriorityLevelConfigurationList

PriorityLevelConfigurationList 是 PriorityLevelConfiguration 对象的列表。


  • apiVersion: flowcontrol.apiserver.k8s.io/v1

  • kind: PriorityLevelConfigurationList

操作


get 读取指定的 PriorityLevelConfiguration

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}

参数

  • name路径参数):string,必需

    PriorityLevelConfiguration 的名称。

  • pretty查询参数):string

    pretty

响应

200 (PriorityLevelConfiguration): OK

401: Unauthorized

get 读取指定的 PriorityLevelConfiguration 的状态

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}/status

参数

  • name路径参数):string,必需

    PriorityLevelConfiguration 的名称。

  • pretty查询参数):string

    pretty

响应

200 (PriorityLevelConfiguration): OK

401: Unauthorized

list 列出或监视 PriorityLevelConfiguration 类别的对象

HTTP 请求

GET /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations

参数

响应

200 (PriorityLevelConfigurationList): OK

401: Unauthorized

create 创建 PriorityLevelConfiguration

HTTP 请求

POST /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations

参数

响应

200 (PriorityLevelConfiguration): OK

201 (PriorityLevelConfiguration): Created

202 (PriorityLevelConfiguration): Accepted

401: Unauthorized

update 替换指定的 PriorityLevelConfiguration

HTTP 请求

PUT /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}

参数

响应

200 (PriorityLevelConfiguration): OK

201 (PriorityLevelConfiguration): Created

401: Unauthorized

update 替换指定的 PriorityLevelConfiguration 的状态

HTTP 请求

PUT /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}/status

参数

响应

200 (PriorityLevelConfiguration): OK

201 (PriorityLevelConfiguration): Created

401: Unauthorized

patch 部分更新指定的 PriorityLevelConfiguration

HTTP 请求

PATCH /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}

参数

  • name路径参数):string,必需

    PriorityLevelConfiguration 的名称。

  • body: Patch,必需

  • dryRun查询参数):string

    dryRun

  • fieldManager查询参数):string

    fieldManager

  • fieldValidation查询参数):string

    fieldValidation

  • force查询参数):boolean

    force

  • pretty查询参数):string

    pretty

响应

200 (PriorityLevelConfiguration): OK

201 (PriorityLevelConfiguration): Created

401: Unauthorized

patch 部分更新指定的 PriorityLevelConfiguration 的状态

HTTP 请求

PATCH /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}/status

参数

  • name路径参数):string,必需

    PriorityLevelConfiguration 的名称。

  • body: Patch,必需

  • dryRun查询参数):string

    dryRun

  • fieldManager查询参数):string

    fieldManager

  • fieldValidation查询参数):string

    fieldValidation

  • force查询参数):boolean

    force

  • pretty查询参数):string

    pretty

响应

200 (PriorityLevelConfiguration): OK

201 (PriorityLevelConfiguration): Created

401: Unauthorized

delete 删除 PriorityLevelConfiguration

HTTP 请求

DELETE /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations/{name}

参数

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 PriorityLevelConfiguration 的集合

HTTP 请求

DELETE /apis/flowcontrol.apiserver.k8s.io/v1/prioritylevelconfigurations

参数

响应

200 (Status): OK

401: Unauthorized

7 - ValidatingAdmissionPolicy

ValidatingAdmissionPolicy 描述了一种准入验证策略的定义,这种策略接受或拒绝一个对象而不对其进行修改。

apiVersion: admissionregistration.k8s.io/v1

import "k8s.io/api/admissionregistration/v1"

ValidatingAdmissionPolicy

ValidatingAdmissionPolicy 描述了一种准入验证策略的定义, 这种策略用于接受或拒绝一个对象,而不对其进行修改。


  • apiVersion: admissionregistration.k8s.io/v1

  • kind: ValidatingAdmissionPolicy

  • metadata (ObjectMeta)

    标准对象元数据;更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.

  • spec (ValidatingAdmissionPolicySpec)

    ValidatingAdmissionPolicy 的期望行为规范。

    ValidatingAdmissionPolicySpec 是 AdmissionPolicy 的期望行为规范。

    • spec.auditAnnotations ([]AuditAnnotation)

      原子性:合并期间将被替换

      auditAnnotations 包含用于为 API 请求的审计事件生成审计注解的 CEL 表达式。 validations 和 auditAnnotations 不能同时为空;至少需要 validations 或 auditAnnotations 中的一个。

      AuditAnnotation 描述了如何为 API 请求生成审计注解。

      • spec.auditAnnotations.key (string),必需

        key 指定了审计注解的键。ValidatingAdmissionPolicy 的审计注解键必须是唯一的。 键必须是一个合格的名字([A-Za-z0-9][-A-Za-z0-9_.]*),长度不超过 63 字节。

        键与 ValidatingAdmissionPolicy 的资源名称组合以构建审计注解键:"{ValidatingAdmissionPolicy 名称}/{key}"。

        如果一个准入 Webhook 使用与这个 ValidatingAdmissionPolicy 相同的资源名称和相同的审计注解键, 那么注解键将是相同的。在这种情况下,使用该键写入的第一个注解将包含在审计事件中, 并且所有后续使用相同键的注解将被丢弃。

        必需。

      • spec.auditAnnotations.valueExpression (string),必需

        valueExpression 表示由 CEL 求值以生成审计注解值的表达式。该表达式求值结果为字符串或 null 值。 如果表达式计算为字符串,则包含带有字符串值的审计注解。如果表达式计算为 null 或空字符串, 则审计注解将被省略。valueExpression 的长度不得超过 5kb。如果 valueExpression 的结果长度超过 10KB,它将被截断为 10KB。

        如果多个 ValidatingAdmissionPolicyBinding 资源匹配一个 API 请求, 则会为每个绑定计算 valueExpression。所有由 valueExpressions 产生的唯一值将以逗号分隔列表的形式连接在一起。

        必需。

    • spec.failurePolicy (string)

      failurePolicy 定义了如何处理准入策略的失败。失败可能由 CEL 表达式解析错误、类型检查错误、运行时错误以及无效或配置错误的策略定义或绑定引起。

      如果 spec.paramKind 引用了一个不存在的 Kind,则该策略无效。如果 spec.paramRef.name 引用了不存在的资源,则绑定无效。

      failurePolicy 不定义如何处理计算为 false 的验证。

      当 failurePolicy 设置为 Fail 时,ValidatingAdmissionPolicyBinding validationActions 定义如何处理失败。

      允许的值有 Ignore 或 Fail。默认为 Fail。

    • spec.matchConditions ([]MatchCondition)

      补丁策略:基于 name 键合并

      映射:在合并期间,基于 name 键的唯一值将被保留

      matchConditions 是请求能够被验证时必须满足的一系列条件。匹配条件过滤已经由 rules、 namespaceSelector 和 objectSelector 匹配的请求。空的 matchConditions 列表匹配所有请求。最多允许有 64 个匹配条件。

      如果提供了参数对象,可以通过 params 句柄以与验证表达式相同的方式访问它。

      精确的匹配逻辑(按顺序):

      1. 如果 matchConditions 中任意一个解析为 FALSE,则跳过该策略。
      2. 如果 matchConditions 中所有条件都解析为 TRUE,则执行该策略。
      3. 如果任何 matchCondition 解析出现错误(但没有解析为 FALSE):
        • 如果 failurePolicy=Fail,拒绝请求
        • 如果 failurePolicy=Ignore,则跳过该策略

      **MatchCondition 表示将请求发送到 Webhook 时必须满足的条件。**
      
      • spec.matchConditions.expression (string),必需

        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。

        必需。

      • spec.matchConditions.name (string),必需

        name 是此匹配条件的标识符,用于 matchConditions 的策略性合并以及为日志记录提供标识符。 一个好的名称应该能够描述相关的表达式。名称必须是由字母数字字符、-_. 组成的合格名称, 并且必须以字母数字字符开头和结尾(例如 'MyName' 或 'my.name' 或 '123-abc', 用于验证的正则表达式是 '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') 可以包含一个可选的 DNS 子域前缀和 '/' (例如 'example.com/MyName')。

        必需。

    • spec.matchConstraints (MatchResources)

      matchConstraints 指定此策略设计用来验证的资源。仅当 AdmissionPolicy 匹配所有约束时,才会关注请求。 然而,为了避免集群进入无法通过 API 恢复的不稳定状态,ValidatingAdmissionPolicy 不能匹配 ValidatingAdmissionPolicy 和 ValidatingAdmissionPolicyBinding。 必需。

      matchResources 决定了是否根据对象是否符合匹配标准来运行准入控制策略。 排除规则优先于包含规则(如果一个资源同时匹配两者,则它被排除)

      • spec.matchConstraints.excludeResourceRules ([]NamedRuleWithOperations)

        原子性:在合并期间将被替换

        excludeResourceRules 描述 ValidatingAdmissionPolicy 不应关心的操作及其资源/子资源。 排除规则优先于包含规则(如果一个资源同时匹配两者,则它被排除)

        namedRuleWithOperations 是操作和资源及其资源名称的元组。

        • spec.matchConstraints.excludeResourceRules.apiGroups ([]string)

          原子性:在合并期间将被替换

          apiGroups 是资源所属的 API 组。* 表示所有组。 如果存在 *,切片的长度必须为一。必需。

        • spec.matchConstraints.excludeResourceRules.apiVersions ([]string)

          原子性:在合并期间将被替换

          apiVersions 是资源所属的 API 版本。* 表示所有版本。 如果存在 *,切片的长度必须为一。必需。

        • spec.matchConstraints.excludeResourceRules.operations ([]string)

          原子性:在合并期间将被替换

          operations 是准入钩子关心的操作 - CREATE、UPDATE、DELETE、CONNECT 或者 * 表示所有这些操作以及将来可能添加的任何准入操作。 如果存在 *,切片的长度必须为一。必需。

        • spec.matchConstraints.excludeResourceRules.resourceNames ([]string)

          原子性:在合并期间将被替换

          resourceNames 是规则适用的名称白名单。空集表示允许所有。

        • spec.matchConstraints.excludeResourceRules.resources ([]string)

          原子性:在合并期间将被替换

          resources 是此规则适用的资源列表。

          例如:pods 表示 Pods。pods/log 表示 Pods 的日志子资源。 * 表示所有资源,但不包括子资源。pods/* 表示 Pods 的所有子资源。 */scale 表示所有扩缩子资源。*/* 表示所有资源及其子资源。

          如果通配符存在,验证规则将确保资源不会相互重叠。

          根据封装对象的不同,可能不允许有子资源。必需。

        • spec.matchConstraints.excludeResourceRules.scope (string)

          scope 指定此规则的作用范围。有效值为 ClusterNamespaced*Cluster 表示仅集群作用域的资源匹配此规则。Namespace API 对象是集群作用域的。 Namespaced 表示仅命名空间资源匹配此规则。* 表示没有作用范围限制。 子资源匹配其父资源的作用范围。默认是 *

      • spec.matchConstraints.matchPolicy (string)

        matchPolicy 定义了如何使用 "MatchResources" 列表来匹配传入的请求。允许的值为 "Exact" 或 "Equivalent"。

        • Exact:仅当请求完全匹配指定规则时才匹配请求。 例如,如果 deployments 可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改, 但 "rules" 仅包含 apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], 则对 apps/v1beta1 或 extensions/v1beta1 的请求不会发送到 ValidatingAdmissionPolicy。

        • Equivalent:如果请求修改了规则中列出的资源,即使通过另一个 API 组或版本, 也会匹配请求。例如,如果 deployments 可以通过 apps/v1apps/v1beta1extensions/v1beta1 修改, 并且 "rules" 仅包含 apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], 则对 apps/v1beta1extensions/v1beta1 的请求将被转换为 apps/v1 并发送到 ValidatingAdmissionPolicy。

        默认为 "Equivalent"

      • spec.matchConstraints.namespaceSelector (LabelSelector)

        namespaceSelector 决定了是否基于对象的命名空间是否匹配选择器来对该对象运行准入控制策略。 如果对象本身是一个命名空间,则匹配是针对 object.metadata.labels 执行的。 如果对象是另一个集群范围的资源,则永远不会跳过此策略。

        例如,要对任何命名空间未关联 "runlevel" 为 "0" 或 "1" 的对象运行 Webhook,你可以将选择算符设置如下:

        "namespaceSelector": { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }

        如果你只想对那些命名空间与 "environment" 为 "prod" 或 "staging" 相关联的对象运行策略,你可以将选择器设置如下:

        "namespaceSelector": { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }

        参阅标签选择算符示例 获取更多的示例。

        默认为空的 LabelSelector,匹配所有内容。

      • spec.matchConstraints.objectSelector (LabelSelector)

        objectSelector 决定了是否基于对象是否有匹配的标签来运行验证。 objectSelector 会针对将被发送到 CEL 验证的旧对象和新对象进行计算, 只要其中一个对象匹配选择算符,则视为匹配。Null 对象(在创建时为旧对象,或在删除时为新对象) 或不能有标签的对象(如 DeploymentRollback 或 PodProxyOptions 对象)不被认为匹配。 仅当 Webhook 是可选时使用对象选择器,因为终端用户可以通过设置标签跳过准入 Webhook。 默认为"空" LabelSelector,它匹配所有内容。

      • spec.matchConstraints.resourceRules ([]NamedRuleWithOperations)

        原子性:将在合并期间被替换

        resourceRules 描述了 ValidatingAdmissionPolicy 匹配的资源/子资源上的什么操作。 只要匹配任何规则,策略就会关心该操作。

        NamedRuleWithOperations 是操作和带有资源名称的资源的元组。

        • spec.matchConstraints.resourceRules.apiGroups ([]string)

          原子性:将在合并期间被替换

          apiGroups 是资源所属的 API 组。* 表示所有组。如果存在 *,则切片的长度必须为一。必需。

        • spec.matchConstraints.resourceRules.apiVersions ([]string)

          原子性:将在合并期间被替换

          apiVersions 是资源所属的 API 版本。* 表示所有版本。如果存在 *,则切片的长度必须为一。必需。

        • spec.matchConstraints.resourceRules.operations ([]string)

          原子性:在合并期间将被替换

          operations 是准入钩子关心的操作 - CREATE、UPDATE、DELETE、CONNECT 或者是代表所有这些操作以及任何未来可能添加的准入操作的通配符 *。 如果包含了 *,那么切片的长度必须为一。必需字段。

        • spec.matchConstraints.resourceRules.resourceNames ([]string)

          原子性:在合并期间将被替换

          resourceNames 是规则适用的名称白名单。一个空集合意味着允许所有。可选项。

        • spec.matchConstraints.resourceRules.resources ([]string)

          原子性:在合并期间将被替换

          resources 是此规则适用的资源列表。

          例如:pods 表示 pods。pods/log 表示 pods 的日志子资源。 * 表示所有资源,但不包括子资源。pods/* 表示 pods 的所有子资源。 */scale 表示所有资源的 scale 子资源。*/* 表示所有资源及其子资源。

          如果存在通配符,验证规则将确保资源之间不会相互重叠。

          根据封装对象的不同,可能不允许有子资源。必需字段。

        • spec.matchConstraints.resourceRules.scope (string)

          scope 指定此规则的作用范围。有效值为 "Cluster"、"Namespaced" 和 "*"。 "Cluster" 表示只有集群范围的资源匹配此规则。Namespace API 对象是集群范围的。 "Namespaced" 表示只有名字空间作用域的资源匹配此规则。"*" 表示没有作用范围限制。 子资源匹配其父资源的作用范围。默认值为 "*"。

    • spec.paramKind (ParamKind)

      paramKind 指定用于参数化此策略的资源类型。如果不存在,则此策略没有参数, 且不会向验证表达式提供 param CEL 变量。如果 paramKind 引用了一个不存在的类型, 则此策略定义配置错误,并应用 FailurePolicy。 如果指定了 paramKind 但在 ValidatingAdmissionPolicyBinding 中未设置 paramRef,则 params 变量将为 null。

      ParamKind 是组类型和版本的组合。

      • spec.paramKind.apiVersion (string)

        apiVersion 是资源所属的 API 组版本。格式为 "group/version"。必需字段。

      • spec.paramKind.kind (string)

        kind 是资源所属的 API 类型。必需字段。

    • spec.validations ([]Validation)

      原子性:将在合并期间被替换

      validations 包含用于应用验证的 CEL 表达式。validations 和 auditAnnotations 不能同时为空;至少需要一个 validations 或 auditAnnotations。

      Validation 指定用于应用验证的 CEL 表达式。

      • spec.validations.expression (string),必需

        expression 表示将由 CEL 计算的表达式。参考:https://github.com/google/cel-spec CEL 表达式可以访问 API 请求/响应的内容,这些内容被组织成 CEL 变量以及一些其他有用的变量:

        • 'object' - 来自传入请求的对象。对于 DELETE 请求,该值为 null。
        • 'oldObject' - 现有对象。对于 CREATE 请求,该值为 null。
        • 'request' - API 请求的属性(参考)。
        • 'params' - 由正在计算的策略绑定引用的参数资源。仅在策略具有 ParamKind 时填充。
        • 'namespaceObject' - 传入对象所属的命名空间对象。对于集群范围的资源,该值为 null。
        • 'variables' - 复合变量的映射,从其名称到其惰性求值的值。 例如,名为 'foo' 的变量可以作为 'variables.foo' 访问。
        • 'authorizer' - 一个 CEL 鉴权器。可用于对请求的主体(用户或服务帐户)执行授权检查。 请参阅 https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
        • 'authorizer.requestResource' - 由 'authorizer' 构建并使用请求资源配置的 CEL 资源检查。
          `apiVersion`、`kind`、`metadata.name` 和 `metadata.generateName` 总是可以从对象的根部访问。没有其他元数据属性是可访问的。
        

        只有形式为 [a-zA-Z_.-/][a-zA-Z0-9_.-/]* 的属性名称是可访问的。当在表达式中访问时,根据以下规则对可访问的属性名称进行转义:

        • __ 转义为 __underscores__
        • . 转义为 __dot__
        • - 转义为 __dash__
        • / 转义为 __slash__
        • 完全匹配 CEL 保留关键字的属性名称转义为 __{keyword}__。这些关键字包括: "true"、"false"、"null"、"in"、"as"、"break"、"const"、"continue"、"else"、"for"、"function"、"if"、 "import"、"let"、"loop"、"package"、"namespace"、"return"。 示例:
        • 访问名为 "namespace" 的属性的表达式:{"Expression": "object.namespace > 0"}
        • 访问名为 "x-prop" 的属性的表达式:{"Expression": "object.x__dash__prop > 0"}
        • 访问名为 "redact__d" 的属性的表达式:{"Expression": "object.redact__underscores__d > 0"}

        对于类型为 'set' 或 'map' 的列表,数组上的相等性忽略元素顺序,即 [1, 2] == [2, 1]。 带有 x-kubernetes-list-type 的数组上的连接使用列表类型的语义:

        • 'set':X + Y 执行一个联合操作,其中 X 中所有元素的数组位置被保留, 并且 Y 中不相交的元素被追加,保持它们的部分顺序。
        • 'map':X + Y 执行一个合并操作,其中 X 中所有键的数组位置被保留, 但值被 Y 中的值覆盖,当 XY 的键集相交时。Y 中具有不相交键的元素被追加, 保持它们的部分顺序。

        必需。

      • spec.validations.message (string)

        message 表示验证失败时显示的消息。如果 expression 包含换行符, 则消息是必需的。消息中不能包含换行符。如果未设置,消息为 "failed rule: {Rule}"。 例如 "must be a URL with the host matching spec.host"。 如果 expression 包含换行符,则 message 是必需的。消息中不能包含换行符。 如果未设置,消息为 "failed Expression: {Expression}"。

      • spec.validations.messageExpression (string)

        messageExpression 声明一个 CEL 表达式,当此规则失败时返回该表达式计算得到的验证失败消息。 由于 messageExpression 用作失败消息,它必须计算为字符串。如果验证同时包含 message 和 messageExpression,则验证失败时将使用 messageExpression。 如果 messageExpression 导致运行时错误,将记录运行时错误,并且如同未设置 messageExpression 字段一样生成验证失败消息。如果 messageExpression 计算为空字符串、仅包含空格的字符串或包含换行符的字符串,则同样会如同未设置 messageExpression 字段一样生成验证失败消息,并且将记录 messageExpression 产生了空字符串/仅包含空格的字符串/包含换行符的字符串的情况。 messageExpression 可访问与 expression 相同的所有变量,除了 'authorizer' 和 'authorizer.requestResource'。示例:"object.x 必须小于最大值 ("+string(params.max)+")"

      • spec.validations.reason (string)

        reason 表示机器可读的描述,说明为何此验证失败。如果这是列表中第一个失败的验证, 则这个 reason 以及相应的 HTTP 响应代码将用于对客户端的 HTTP 响应。 当前支持的原因有:"Unauthorized"、"Forbidden"、"Invalid"、"RequestEntityTooLarge"。 如果没有设置,在响应给客户端时将使用 StatusReasonInvalid。

    • spec.variables ([]Variable)

      补丁策略:基于 name 键合并

      映射:在合并期间,基于 name 键的唯一值将被保留

      变量包含可用于其他表达式组合的变量定义。每个变量都被定义为一个命名的 CEL 表达式。 这里定义的变量将在策略的其他表达式中的 variables 下可用,除了 matchConditions, 因为 matchConditions 会在策略其余部分之前进行计算。

      变量的表达式可以引用列表中先前定义的其他变量,但不能引用后续定义的变量。 因此,variables 必须按照首次出现的顺序排序并且不可存在循环的。

      Variable 是用于组合的变量定义。变量被定义为一个命名的表达式。

      • spec.variables.expression (string), 必需

        expression 是将被计算为变量值的表达式。CEL 表达式可以访问与 validation 中的 CEL 表达式相同的标识符。

      • spec.variables.name (string), 必需

        name 是变量的名称。名称必须是有效的 CEL 标识符,并且在所有变量中唯一。变量可以通过 variables 在其他表达式中访问。例如,如果名称是 "foo",变量将作为 variables.foo 可用。

  • status (ValidatingAdmissionPolicyStatus)

    ValidatingAdmissionPolicy 的状态,包括有助于确定策略是否按预期行为的警告。由系统填充。只读。

    ValidatingAdmissionPolicyStatus 表示一个准入验证策略的状态。

    • status.conditions ([]Condition)

      在合并期间,键类型上的唯一值将被保留

      这些条件表示策略当前状态的最新可用观察结果。

      Condition 包含此 API 资源当前状态某一方面的详细信息。

  • status.conditions.lastTransitionTime (Time),必填

    lastTransitionTime 是条件从一个状态转换到另一个状态的最后时间。这应该是底层条件改变的时间。 如果不知道该时间,使用 API 字段更改的时间是可以接受的。

    Time 是对 time.Time 的封装,支持正确地序列化为 YAML 和 JSON。time 包提供的许多工厂方法都有对应的封装。

    • status.conditions.message (string),必填

      message 是一个人类可读的消息,指示有关过渡的详细信息。这可以是一个空字符串。

    • status.conditions.reason (string),必填

      reason 包含一个编程标识符,指示条件上次转换的原因。特定条件类型的提供者可以为此字段定义预期值和含义, 以及这些值是否被视为保证的 API。值应当是 CamelCase 格式的字符串。此字段不能为空。

      • status.conditions.status (string),必需

        condition 的状态,可能是 True、False、Unknown 中的一个。

      • status.conditions.type (string),必需

        condition 的类型,采用 CamelCase 或 foo.example.com/CamelCase 格式。

      • status.conditions.observedGeneration (int64)

        observedGeneration 表示设置条件时依据的 .metadata.generation。例如,如果当前 .metadata.generation 是 12,而 .status.conditions[x].observedGeneration 是 9, 则说明该条件相对于实例的当前状态已过期。

    • status.observedGeneration (int64)

      控制器观察到的 generation。

    • status.typeChecking (TypeChecking)

      每个表达式的类型检查结果。此字段的存在表明类型检查已完成。

      TypeChecking 包含了对 ValidatingAdmissionPolicy 中表达式进行类型检查的结果

      • status.typeChecking.expressionWarnings ([]ExpressionWarning)

        原子性:将在合并期间被替换

        每个表达式的类型检查警告。

        ExpressionWarning 是针对特定表达式的警告信息。

        • status.typeChecking.expressionWarnings.fieldRef (string),必需

          引用表达式的字段路径。例如,对 validations 第一项的表达式的引用是 "spec.validations[0].expression"

        • status.typeChecking.expressionWarnings.warning (string),必需

          人类可读形式的类型检查信息内容。警告的每一行包含表达式所检查的类型,然后是编译器报告的类型检查错误。

ValidatingAdmissionPolicyList

ValidatingAdmissionPolicyList 是 ValidatingAdmissionPolicy 的列表。


  • items ([]ValidatingAdmissionPolicy),必需

    ValidatingAdmissionPolicy 的列表。

  • apiVersion (string)

    apiVersion 定义了对象表示的版本化模式。服务器应该将识别的模式转换为最新的内部值,并可能拒绝未识别的值。 更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

  • kind (string)

    kind 是一个字符串值,表示此对象代表的 REST 资源。服务器可能从客户端提交请求的端点推断出该值。 不能更新。采用驼峰命名法。更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

  • metadata (ListMeta)

    标准列表元数据。更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

ValidatingAdmissionPolicyBinding

ValidatingAdmissionPolicyBinding 将 ValidatingAdmissionPolicy 与参数化资源绑定。 ValidatingAdmissionPolicyBinding 和参数 CRD 共同定义了集群管理员如何为集群配置策略。

对于一个给定的准入请求,每个绑定将导致其策略被计算 N 次,其中 N 对于不使用参数的策略/绑定是 1, 否则 N 是由绑定选择的参数数量。

策略的 CEL 表达式必须具有低于最大 CEL 预算的计算 CEL 成本。每次策略计算都有独立的 CEL 成本预算。添加/移除策略、绑定或参数不会影响特定(策略,绑定,参数)组合是否在其自身的 CEL 预算内。


  • metadataObjectMeta

    标准对象元数据;更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata。

  • spec (ValidatingAdmissionPolicyBindingSpec)

    ValidatingAdmissionPolicyBinding 的期望行为规范。

    ValidatingAdmissionPolicyBindingSpec 是 ValidatingAdmissionPolicyBinding 的规范。

    • spec.matchResources (MatchResources)

    matchResources 声明了哪些资源匹配此绑定并会由此进行验证。注意,这与策略的 matchConstraints 相交, 因此只有被策略匹配的请求才能由此选择。如果此字段未设置,则由策略匹配的所有资源都将由此绑定验证。 当 resourceRules 未设置时,它不限制资源匹配。如果资源符合此对象的其他字段,它将被验证。 注意,这与 ValidatingAdmissionPolicy matchConstraints 不同,在那里 resourceRules 是必需的。

    MatchResources 根据对象是否满足匹配条件来决定是否对其运行准入控制策略。 排除规则优先于包含规则(如果一个资源同时匹配两者,则该资源被排除)

    • spec.matchResources.excludeResourceRules ([]NamedRuleWithOperations)

      原子性:将在合并期间被替换

      excludeResourceRules 描述了 ValidatingAdmissionPolicy 应忽略的操作和资源/子资源。 排除规则优先于包含规则(如果一个资源同时匹配两者,则该资源被排除)

      NamedRuleWithOperations 是操作和资源及资源名称的元组。

      • spec.matchResources.excludeResourceRules.apiGroups ([]string)

      原子性:将在合并期间被替换

      apiGroups 是资源所属的 API 组。`*` 表示所有组。
      如果存在 `*`,则切片的长度必须为一。必需。
      
      - **spec.matchResources.excludeResourceRules.apiVersions** ([]string)
      
      **原子性:将在合并期间被替换**
      
      apiVersions 是资源所属的 API 版本。`*` 表示所有版本。
      如果存在 `*`,则切片的长度必须为一。必需。
      
      • spec.matchResources.excludeResourceRules.operations ([]string)

        原子性:将在合并期间被替换

        operations 是 admission hook 关心的操作 - CREATE、UPDATE、DELETE、CONNECT 或者 * 表示所有这些操作以及将来可能添加的任何 admission 操作。 如果存在 *,则切片的长度必须为一。必需。

      • spec.matchResources.excludeResourceRules.resourceNames ([]string)

        原子性:将在合并期间被替换

        resourceNames 是规则适用的名字白名单。空集表示允许所有。

      • spec.matchResources.excludeResourceRules.resources ([]string)

        原子性:将在合并期间被替换

        resources 是此规则适用的资源列表。

        例如:pods 表示 pods。pods/log 表示 pods 的日志子资源。* 表示所有资源, 但不包括子资源。pods/* 表示 pods 的所有子资源。*/scale 表示所有 scale 子资源。 */* 表示所有资源及其子资源。

        如果存在通配符,验证规则将确保资源不会相互重叠。

        根据封装对象的不同,可能不允许有子资源。必需。

      • spec.matchResources.excludeResourceRules.scope (string)

        scope 指定此规则的范围。有效值为 "Cluster"、"Namespaced" 和 "*"。"Cluster" 表示只有集群范围的资源将匹配此规则。Namespace API 对象是集群范围的。"Namespaced" 表示只有命名空间范围的资源将匹配此规则。"*" 表示没有范围限制。子资源匹配其父资源的范围。默认是 "*"。

      • spec.matchResources.matchPolicy (string)

        matchPolicy 定义了如何使用 "MatchResources" 列表来匹配传入的请求。允许的值为 "Exact" 或 "Equivalent"。

        • Exact:仅当请求完全匹配指定规则时才匹配请求。例如,如果 deployments 可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改,但 "rules" 仅包含 apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], 则对 apps/v1beta1 或 extensions/v1beta1 的请求不会发送到 ValidatingAdmissionPolicy。

        • Equivalent:如果请求修改了规则中列出的资源,即使通过另一个 API 组或版本,也会匹配请求。 例如,如果 deployments 可以通过 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改, 并且 "rules" 仅包含 apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], 则对 apps/v1beta1 或 extensions/v1beta1 的请求将被转换为 apps/v1 并发送到 ValidatingAdmissionPolicy。

        默认为 "Equivalent"

      • spec.matchResources.namespaceSelector (LabelSelector)

        namespaceSelector 决定了是否基于对象的命名空间是否匹配选择器来对对象运行准入控制策略。 如果对象本身是一个命名空间,则匹配是在 object.metadata.labels 上执行的。 如果对象是另一个集群范围的资源,则永远不会跳过该策略。

        例如,要对任何命名空间未关联 "runlevel" 为 "0" 或 "1" 的对象运行 Webhook,你可以将选择器设置如下:

        "namespaceSelector": { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }

        如果你只想对那些命名空间与 "environment" 的 "prod" 或 "staging" 相关联的对象运行策略,你可以将选择器设置如下:

        "namespaceSelector": { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }

        参见标签选择器示例获取更多例子。

        默认为空的 LabelSelector,它匹配所有内容。

      • spec.matchResources.objectSelector (LabelSelector)

        objectSelector 决定是否基于对象是否有匹配的标签来运行验证。objectSelector 会针对将被发送到 CEL 验证的旧对象和新对象进行计算,只要其中一个对象匹配选择器,则认为匹配。 一个空对象(在创建时的旧对象,或在删除时的新对象)或不能有标签的对象(如 DeploymentRollback 或 PodProxyOptions 对象)不被认为是匹配的。 仅在 Webhook 是可选的情况下使用对象选择器,因为最终用户可以通过设置标签跳过准入 Webhook。默认为空的 LabelSelector ,它匹配所有内容。

      • spec.matchResources.resourceRules ([]NamedRuleWithOperations)

        原子性:将在合并期间被替换

        resourceRules 描述了 ValidatingAdmissionPolicy 匹配的资源/子资源上的什么操作。 如果操作匹配任意规则,策略就会关心该操作。

        NamedRuleWithOperations 是操作和带有资源名称的资源的元组。

        • spec.matchResources.resourceRules.apiGroups ([]string)

          原子性:将在合并期间被替换

          apiGroups 是资源所属的 API 组。* 表示所有组。如果存在 *,则切片的长度必须为一。必需。

        • spec.matchResources.resourceRules.apiVersions ([]string)

          原子性:将在合并期间被替换

          apiVersions 是资源所属的 API 版本。* 表示所有版本。如果存在 *,则切片的长度必须为一。必需。

        • spec.matchResources.resourceRules.operations ([]string)

          原子性:将在合并期间被替换

          operations 是准入钩子关心的操作 - CREATE、UPDATE、DELETE、CONNECT 或 * 表示所有这些操作和将来可能添加的任何其他准入操作。如果存在 *,则切片的长度必须为一。必需。

        • spec.matchResources.resourceRules.resourceNames ([]string)

          原子性:将在合并期间被替换

          resourceNames 是规则适用的名称可选白名单。一个空集意味着允许所有。

        • spec.matchResources.resourceRules.resources ([]string)

          原子性:将在合并期间被替换

          resources 是此规则适用的资源列表。

          例如:'pods' 表示 Pods。'pods/log' 表示 Pods 的日志子资源。* 表示所有资源, 但不包括子资源。pods/* 表示 Pods 的所有子资源。*/scale 表示所有扩缩子资源。 */* 表示所有资源及其子资源。

          如果通配符存在,验证规则将确保资源不会相互重叠。

          取决于外层对象是什么,可能不允许有子资源。必需。

        • spec.matchResources.resourceRules.scope (string)

          scope 指定此规则的范围。有效值为 "Cluster"、"Namespaced" 和 "*"。

          • "Cluster" 表示只有集群范围的资源会匹配此规则。Namespace API 对象是集群范围的。
          • "Namespaced" 表示只有命名空间范围的资源会匹配此规则。
          • "*" 表示没有范围限制。

          子资源匹配其父资源的范围。默认是 "*"。

    • spec.paramRef (ParamRef)

      paramRef 指定了用于配置准入控制策略的参数资源。它应该指向绑定的 ValidatingAdmissionPolicy 中 paramKind 所指定类型的资源。如果策略指定了 paramKind 而且由 paramRef 引用的资源不存在, 则认为此绑定配置错误,并应用 ValidatingAdmissionPolicy 的 FailurePolicy。 如果策略没有指定 paramKind,则此字段将被忽略,规则将在没有参数的情况下进行计算。

      ParamRef 描述了如何定位将作为策略绑定所应用规则表达式的输入参数。

      • spec.paramRef.name (string)

        name 是被引用资源的名称。

        nameselector 必须设置一个,但 nameselector 是互斥属性。 如果设置了其中一个,另一个必须未设置。

        通过设置 name 字段,留空 selector,并根据需要设置 namespace (如果 paramKind 是命名空间范围的),可以为所有准入请求配置单个参数。

      • spec.paramRef.namespace (string)

        namespace 是被引用资源的命名空间。允许将参数搜索限制到特定命名空间。适用于 nameselector 字段。

        通过在策略中指定命名空间范围的 paramKind 并留空此字段,可以使用每个命名空间的参数。

        • 如果 paramKind 是集群范围的,此字段必须未设置。设置此字段会导致配置错误。

        • 如果 paramKind 是命名空间范围的,在计算准入的对象时,如果此字段未设置,则会使用该对象的命名空间。 请注意,如果此字段为空,则绑定不能匹配任何集群范围的资源,否则将导致错误。

      • spec.paramRef.parameterNotFoundAction (string)

        parameterNotFoundAction 控制当资源存在,且名称或选择器有效但没有匹配的参数时绑定的行为。 如果值设置为 Allow,则未匹配到参数将被视为绑定的成功验证。如果设置为 Deny, 则未匹配到参数将会受到策略的 failurePolicy 的影响。

        允许的值为 AllowDeny

        必需

      • spec.paramRef.selector (LabelSelector)

        selector 可以用于根据 param 对象的标签匹配多个对象。提供 selector: {} 以匹配所有 ParamKind 的资源。

        如果找到多个 params,它们都将使用策略表达式进行计算,并将结果进行 AND 连接。

        必须设置 nameselector 中的一个,但 nameselector 是互斥属性。如果设置了其中一个,另一个必须未设置。

    • spec.policyName (string)

      policyName 引用一个 ValidatingAdmissionPolicy 的名称,ValidatingAdmissionPolicyBinding 将绑定到该名称。如果引用的资源不存在,此绑定将被视为无效并被忽略。必需。

    • spec.validationActions ([]string)

      集合:唯一值将在合并期间被保留

      validationActions 声明了如何执行引用的 ValidatingAdmissionPolicy 的验证。 如果验证结果为 false,则根据这些操作强制执行。

      仅当 FailurePolicy 设置为 Fail 时,根据这些操作强制执行由 ValidatingAdmissionPolicy 的 FailurePolicy 定义的失败,包括编译错误、运行时错误和策略的错误配置。否则,这些失败将被忽略。

      validationActions 被声明为一组操作值。顺序不重要。validationActions 不得包含相同操作的重复项。

      支持的操作值包括:

      "Deny" 指定验证失败将导致请求被拒绝。

      "Warn" 指定验证失败将以 HTTP 警告头的形式报告给请求客户端,警告代码为 299。警告可以随允许或拒绝的准入响应一起发送。

      "Audit" 指定验证失败将包含在请求的已发布审计事件中。审计事件将包含一个 validation.policy.admission.k8s.io/validation_failure 审计注解, 其值包含验证失败的详细信息,格式为对象列表的 JSON,每个对象具有以下字段:

      • message:验证失败消息字符串
      • policy:ValidatingAdmissionPolicy 的资源名称
      • binding:ValidatingAdmissionPolicyBinding 的资源名称
      • expressionIndex:在 ValidatingAdmissionPolicy 中失败验证的索引
      • validationActions:针对验证失败执行的强制操作

      示例审计注解: "validation.policy.admission.k8s.io/validation_failure": "[{\"message\": \"无效值\", {\"policy\": \"policy.example.com\", {\"binding\": \"policybinding.example.com\", {\"expressionIndex\": \"1\", {\"validationActions\": [\"Audit\"]}]"

      客户端应预期通过忽略任何未识别的值来处理额外的值。

      "Deny" 和 "Warn" 不能一起使用,因为这种组合会不必要地在 API 响应体和 HTTP 警告头中重复验证失败。

      必需。

操作


get 读取指定的 ValidatingAdmissionPolicy

HTTP 请求

GET /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}

参数

  • name路径参数): string, 必需

    ValidatingAdmissionPolicy 的名称

  • pretty查询参数): string

    pretty

响应

200 (ValidatingAdmissionPolicy): OK

401: Unauthorized

get 读取指定 ValidatingAdmissionPolicy 的状态

HTTP 请求

GET /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}/status

参数

  • name路径参数): string, 必需

    ValidatingAdmissionPolicy 的名称

  • pretty查询参数): string

    pretty

响应

200 (ValidatingAdmissionPolicy): OK

401: Unauthorized

list 列出或监视 ValidatingAdmissionPolicy 类型的对象

HTTP 请求

GET /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies

参数

响应

200 (ValidatingAdmissionPolicyList): OK

401: Unauthorized

create 创建 ValidatingAdmissionPolicy

HTTP 请求

POST /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies

参数

响应

200 (ValidatingAdmissionPolicy): OK

201 (ValidatingAdmissionPolicy): Created

202 (ValidatingAdmissionPolicy): Accepted

401: Unauthorized

update 替换指定的 ValidatingAdmissionPolicy

HTTP 请求

PUT /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}

参数

响应

200 (ValidatingAdmissionPolicy): OK

201 (ValidatingAdmissionPolicy): Created

401: Unauthorized

update 替换指定 ValidatingAdmissionPolicy 的状态

HTTP 请求

PUT /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}/status

参数

响应

200 (ValidatingAdmissionPolicy): OK

201 (ValidatingAdmissionPolicy): Created

401: Unauthorized

patch 部分更新指定的 ValidatingAdmissionPolicy

HTTP 请求

PATCH /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}

参数

  • name (路径参数): string,必需

    ValidatingAdmissionPolicy 的名称。

  • body: DeleteOptions

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

  • fieldValidation (查询参数): string

    fieldValidation

  • force (查询参数): boolean

    force

  • pretty (查询参数): string

    pretty

响应

200 (ValidatingAdmissionPolicy): OK

201 (ValidatingAdmissionPolicy): Created

401: Unauthorized

patch 部分更新指定 ValidatingAdmissionPolicy 的状态

HTTP 请求

PATCH /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}/status

参数

  • name (路径参数): string, 必需

    name of the ValidatingAdmissionPolicy

  • body: Patch, 必需

  • dryRun (查询参数): string

    dryRun

  • fieldManager (查询参数): string

    fieldManager

响应

200 (ValidatingAdmissionPolicy): OK

201 (ValidatingAdmissionPolicy): Created

401: Unauthorized

delete 删除 ValidatingAdmissionPolicy

HTTP 请求

DELETE /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies/{name}

参数

  • name (路径参数): string, 必需

    ValidatingAdmissionPolicy 的名称。

  • body: DeleteOptions

响应

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection 删除 ValidatingAdmissionPolicy 的集合

HTTP 请求

DELETE /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies

参数

响应

200 (Status): OK

401: Unauthorized

8 - ValidatingAdmissionPolicyBinding

ValidatingAdmissionPolicyBinding binds the ValidatingAdmissionPolicy with paramerized resources.

apiVersion: admissionregistration.k8s.io/v1

import "k8s.io/api/admissionregistration/v1"

ValidatingAdmissionPolicyBinding

ValidatingAdmissionPolicyBinding binds the ValidatingAdmissionPolicy with paramerized resources. ValidatingAdmissionPolicyBinding and parameter CRDs together define how cluster administrators configure policies for clusters.

For a given admission request, each binding will cause its policy to be evaluated N times, where N is 1 for policies/bindings that don't use params, otherwise N is the number of parameters selected by the binding.

The CEL expressions of a policy must have a computed CEL cost below the maximum CEL budget. Each evaluation of the policy is given an independent CEL cost budget. Adding/removing policies, bindings, or params can not affect whether a given (policy, binding, param) combination is within its own CEL budget.


  • apiVersion: admissionregistration.k8s.io/v1

  • kind: ValidatingAdmissionPolicyBinding

  • metadata (ObjectMeta)

    Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.

  • spec (ValidatingAdmissionPolicyBindingSpec)

    Specification of the desired behavior of the ValidatingAdmissionPolicyBinding.

    ValidatingAdmissionPolicyBindingSpec is the specification of the ValidatingAdmissionPolicyBinding.

    • spec.matchResources (MatchResources)

      MatchResources declares what resources match this binding and will be validated by it. Note that this is intersected with the policy's matchConstraints, so only requests that are matched by the policy can be selected by this. If this is unset, all resources matched by the policy are validated by this binding When resourceRules is unset, it does not constrain resource matching. If a resource is matched by the other fields of this object, it will be validated. Note that this is differs from ValidatingAdmissionPolicy matchConstraints, where resourceRules are required.

      MatchResources decides whether to run the admission control policy on an object based on whether it meets the match criteria. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)

      • spec.matchResources.excludeResourceRules ([]NamedRuleWithOperations)

        Atomic: will be replaced during a merge

        ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)

        NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.

        • spec.matchResources.excludeResourceRules.apiGroups ([]string)

          Atomic: will be replaced during a merge

          APIGroups is the API groups the resources belong to. '' is all groups. If '' is present, the length of the slice must be one. Required.

        • spec.matchResources.excludeResourceRules.apiVersions ([]string)

          Atomic: will be replaced during a merge

          APIVersions is the API versions the resources belong to. '' is all versions. If '' is present, the length of the slice must be one. Required.

        • spec.matchResources.excludeResourceRules.operations ([]string)

          Atomic: will be replaced during a merge

          Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.

        • spec.matchResources.excludeResourceRules.resourceNames ([]string)

          Atomic: will be replaced during a merge

          ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.

        • spec.matchResources.excludeResourceRules.resources ([]string)

          Atomic: will be replaced during a merge

          Resources is a list of resources this rule applies to.

          For example: 'pods' means pods. 'pods/log' means the log subresource of pods. '' means all resources, but not subresources. 'pods/' means all subresources of pods. '/scale' means all scale subresources. '/*' means all resources and their subresources.

          If wildcard is present, the validation rule will ensure resources do not overlap with each other.

          Depending on the enclosing object, subresources might not be allowed. Required.

        • spec.matchResources.excludeResourceRules.scope (string)

          scope specifies the scope of this rule. Valid values are "Cluster", "Namespaced", and "" "Cluster" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. "Namespaced" means that only namespaced resources will match this rule. "" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is "*".

      • spec.matchResources.matchPolicy (string)

        matchPolicy defines how the "MatchResources" list is used to match incoming requests. Allowed values are "Exact" or "Equivalent".

        • Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the ValidatingAdmissionPolicy.

        • Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the ValidatingAdmissionPolicy.

        Defaults to "Equivalent"

      • spec.matchResources.namespaceSelector (LabelSelector)

        NamespaceSelector decides whether to run the admission control policy on an object based on whether the namespace for that object matches the selector. If the object itself is a namespace, the matching is performed on object.metadata.labels. If the object is another cluster scoped resource, it never skips the policy.

        For example, to run the webhook on any objects whose namespace is not associated with "runlevel" of "0" or "1"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }

        If instead you want to only run the policy on any objects whose namespace is associated with the "environment" of "prod" or "staging"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }

        See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more examples of label selectors.

        Default to the empty LabelSelector, which matches everything.

      • spec.matchResources.objectSelector (LabelSelector)

        ObjectSelector decides whether to run the validation based on if the object has matching labels. objectSelector is evaluated against both the oldObject and newObject that would be sent to the cel validation, and is considered to match if either object matches the selector. A null object (oldObject in the case of create, or newObject in the case of delete) or an object that cannot have labels (like a DeploymentRollback or a PodProxyOptions object) is not considered to match. Use the object selector only if the webhook is opt-in, because end users may skip the admission webhook by setting the labels. Default to the empty LabelSelector, which matches everything.

      • spec.matchResources.resourceRules ([]NamedRuleWithOperations)

        Atomic: will be replaced during a merge

        ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. The policy cares about an operation if it matches any Rule.

        NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.

        • spec.matchResources.resourceRules.apiGroups ([]string)

          Atomic: will be replaced during a merge

          APIGroups is the API groups the resources belong to. '' is all groups. If '' is present, the length of the slice must be one. Required.

        • spec.matchResources.resourceRules.apiVersions ([]string)

          Atomic: will be replaced during a merge

          APIVersions is the API versions the resources belong to. '' is all versions. If '' is present, the length of the slice must be one. Required.

        • spec.matchResources.resourceRules.operations ([]string)

          Atomic: will be replaced during a merge

          Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.

        • spec.matchResources.resourceRules.resourceNames ([]string)

          Atomic: will be replaced during a merge

          ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.

        • spec.matchResources.resourceRules.resources ([]string)

          Atomic: will be replaced during a merge

          Resources is a list of resources this rule applies to.

          For example: 'pods' means pods. 'pods/log' means the log subresource of pods. '' means all resources, but not subresources. 'pods/' means all subresources of pods. '/scale' means all scale subresources. '/*' means all resources and their subresources.

          If wildcard is present, the validation rule will ensure resources do not overlap with each other.

          Depending on the enclosing object, subresources might not be allowed. Required.

        • spec.matchResources.resourceRules.scope (string)

          scope specifies the scope of this rule. Valid values are "Cluster", "Namespaced", and "" "Cluster" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. "Namespaced" means that only namespaced resources will match this rule. "" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is "*".

    • spec.paramRef (ParamRef)

      paramRef specifies the parameter resource used to configure the admission control policy. It should point to a resource of the type specified in ParamKind of the bound ValidatingAdmissionPolicy. If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the ValidatingAdmissionPolicy applied. If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param.

      ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.

      • spec.paramRef.name (string)

        name is the name of the resource being referenced.

        One of name or selector must be set, but name and selector are mutually exclusive properties. If one is set, the other must be unset.

        A single parameter used for all admission requests can be configured by setting the name field, leaving selector blank, and setting namespace if paramKind is namespace-scoped.

      • spec.paramRef.namespace (string)

        namespace is the namespace of the referenced resource. Allows limiting the search for params to a specific namespace. Applies to both name and selector fields.

        A per-namespace parameter may be used by specifying a namespace-scoped paramKind in the policy and leaving this field empty.

        • If paramKind is cluster-scoped, this field MUST be unset. Setting this field results in a configuration error.

        • If paramKind is namespace-scoped, the namespace of the object being evaluated for admission will be used when this field is left unset. Take care that if this is left empty the binding must not match any cluster-scoped resources, which will result in an error.

      • spec.paramRef.parameterNotFoundAction (string)

        parameterNotFoundAction controls the behavior of the binding when the resource exists, and name or selector is valid, but there are no parameters matched by the binding. If the value is set to Allow, then no matched parameters will be treated as successful validation by the binding. If set to Deny, then no matched parameters will be subject to the failurePolicy of the policy.

        Allowed values are Allow or Deny

        Required

      • spec.paramRef.selector (LabelSelector)

        selector can be used to match multiple param objects based on their labels. Supply selector: {} to match all resources of the ParamKind.

        If multiple params are found, they are all evaluated with the policy expressions and the results are ANDed together.

        One of name or selector must be set, but name and selector are mutually exclusive properties. If one is set, the other must be unset.

    • spec.policyName (string)

      PolicyName references a ValidatingAdmissionPolicy name which the ValidatingAdmissionPolicyBinding binds to. If the referenced resource does not exist, this binding is considered invalid and will be ignored Required.

    • spec.validationActions ([]string)

      Set: unique values will be kept during a merge

      validationActions declares how Validations of the referenced ValidatingAdmissionPolicy are enforced. If a validation evaluates to false it is always enforced according to these actions.

      Failures defined by the ValidatingAdmissionPolicy's FailurePolicy are enforced according to these actions only if the FailurePolicy is set to Fail, otherwise the failures are ignored. This includes compilation errors, runtime errors and misconfigurations of the policy.

      validationActions is declared as a set of action values. Order does not matter. validationActions may not contain duplicates of the same action.

      The supported actions values are:

      "Deny" specifies that a validation failure results in a denied request.

      "Warn" specifies that a validation failure is reported to the request client in HTTP Warning headers, with a warning code of 299. Warnings can be sent both for allowed or denied admission responses.

      "Audit" specifies that a validation failure is included in the published audit event for the request. The audit event will contain a validation.policy.admission.k8s.io/validation_failure audit annotation with a value containing the details of the validation failures, formatted as a JSON list of objects, each with the following fields: - message: The validation failure message string - policy: The resource name of the ValidatingAdmissionPolicy - binding: The resource name of the ValidatingAdmissionPolicyBinding - expressionIndex: The index of the failed validations in the ValidatingAdmissionPolicy - validationActions: The enforcement actions enacted for the validation failure Example audit annotation: "validation.policy.admission.k8s.io/validation_failure": "[{"message": "Invalid value", {"policy": "policy.example.com", {"binding": "policybinding.example.com", {"expressionIndex": "1", {"validationActions": ["Audit"]}]"

      Clients should expect to handle additional values by ignoring any values not recognized.

      "Deny" and "Warn" may not be used together since this combination needlessly duplicates the validation failure both in the API response body and the HTTP warning headers.

      Required.

ValidatingAdmissionPolicy

ValidatingAdmissionPolicy describes the definition of an admission validation policy that accepts or rejects an object without changing it.


  • apiVersion (string)

    APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

  • kind (string)

    Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

  • metadata (ObjectMeta)

    Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.

  • spec (ValidatingAdmissionPolicySpec)

    Specification of the desired behavior of the ValidatingAdmissionPolicy.

    ValidatingAdmissionPolicySpec is the specification of the desired behavior of the AdmissionPolicy.

    • spec.auditAnnotations ([]AuditAnnotation)

      Atomic: will be replaced during a merge

      auditAnnotations contains CEL expressions which are used to produce audit annotations for the audit event of the API request. validations and auditAnnotations may not both be empty; a least one of validations or auditAnnotations is required.

      AuditAnnotation describes how to produce an audit annotation for an API request.

      • spec.auditAnnotations.key (string), required

        key specifies the audit annotation key. The audit annotation keys of a ValidatingAdmissionPolicy must be unique. The key must be a qualified name ([A-Za-z0-9][-A-Za-z0-9_.]*) no more than 63 bytes in length.

        The key is combined with the resource name of the ValidatingAdmissionPolicy to construct an audit annotation key: "{ValidatingAdmissionPolicy name}/{key}".

        If an admission webhook uses the same resource name as this ValidatingAdmissionPolicy and the same audit annotation key, the annotation key will be identical. In this case, the first annotation written with the key will be included in the audit event and all subsequent annotations with the same key will be discarded.

        Required.

      • spec.auditAnnotations.valueExpression (string), required

        valueExpression represents the expression which is evaluated by CEL to produce an audit annotation value. The expression must evaluate to either a string or null value. If the expression evaluates to a string, the audit annotation is included with the string value. If the expression evaluates to null or empty string the audit annotation will be omitted. The valueExpression may be no longer than 5kb in length. If the result of the valueExpression is more than 10kb in length, it will be truncated to 10kb.

        If multiple ValidatingAdmissionPolicyBinding resources match an API request, then the valueExpression will be evaluated for each binding. All unique values produced by the valueExpressions will be joined together in a comma-separated list.

        Required.

    • spec.failurePolicy (string)

      failurePolicy defines how to handle failures for the admission policy. Failures can occur from CEL expression parse errors, type check errors, runtime errors and invalid or mis-configured policy definitions or bindings.

      A policy is invalid if spec.paramKind refers to a non-existent Kind. A binding is invalid if spec.paramRef.name refers to a non-existent resource.

      failurePolicy does not define how validations that evaluate to false are handled.

      When failurePolicy is set to Fail, ValidatingAdmissionPolicyBinding validationActions define how failures are enforced.

      Allowed values are Ignore or Fail. Defaults to Fail.

    • spec.matchConditions ([]MatchCondition)

      Patch strategy: merge on key name

      Map: unique values on key name will be kept during a merge

      MatchConditions is a list of conditions that must be met for a request to be validated. Match conditions filter requests that have already been matched by the rules, namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. There are a maximum of 64 match conditions allowed.

      If a parameter object is provided, it can be accessed via the params handle in the same manner as validation expressions.

      The exact matching logic is (in order):

      1. If ANY matchCondition evaluates to FALSE, the policy is skipped.
      2. If ALL matchConditions evaluate to TRUE, the policy is evaluated.
      3. If any matchCondition evaluates to an error (but none are FALSE):
        • If failurePolicy=Fail, reject the request
        • If failurePolicy=Ignore, the policy is skipped

      MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook.

      • spec.matchConditions.expression (string), required

        Expression represents the expression which will be evaluated by CEL. Must evaluate to bool. CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:

        'object' - The object from the incoming request. The value is null for DELETE requests. 'oldObject' - The existing object. The value is null for CREATE requests. 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request. See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the request resource. Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/

        Required.

      • spec.matchConditions.name (string), required

        Name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes. A good name should be descriptive of the associated expression. Name must be a qualified name consisting of alphanumeric characters, '-', '' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9.]*)?[A-Za-z0-9]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')

        Required.

    • spec.matchConstraints (MatchResources)

      MatchConstraints specifies what resources this policy is designed to validate. The AdmissionPolicy cares about a request if it matches all Constraints. However, in order to prevent clusters from being put into an unstable state that cannot be recovered from via the API ValidatingAdmissionPolicy cannot match ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding. Required.

      MatchResources decides whether to run the admission control policy on an object based on whether it meets the match criteria. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)

      • spec.matchConstraints.excludeResourceRules ([]NamedRuleWithOperations)

        Atomic: will be replaced during a merge

        ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)

        NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.

        • spec.matchConstraints.excludeResourceRules.apiGroups ([]string)

          Atomic: will be replaced during a merge

          APIGroups is the API groups the resources belong to. '' is all groups. If '' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.excludeResourceRules.apiVersions ([]string)

          Atomic: will be replaced during a merge

          APIVersions is the API versions the resources belong to. '' is all versions. If '' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.excludeResourceRules.operations ([]string)

          Atomic: will be replaced during a merge

          Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.excludeResourceRules.resourceNames ([]string)

          Atomic: will be replaced during a merge

          ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.

        • spec.matchConstraints.excludeResourceRules.resources ([]string)

          Atomic: will be replaced during a merge

          Resources is a list of resources this rule applies to.

          For example: 'pods' means pods. 'pods/log' means the log subresource of pods. '' means all resources, but not subresources. 'pods/' means all subresources of pods. '/scale' means all scale subresources. '/*' means all resources and their subresources.

          If wildcard is present, the validation rule will ensure resources do not overlap with each other.

          Depending on the enclosing object, subresources might not be allowed. Required.

        • spec.matchConstraints.excludeResourceRules.scope (string)

          scope specifies the scope of this rule. Valid values are "Cluster", "Namespaced", and "" "Cluster" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. "Namespaced" means that only namespaced resources will match this rule. "" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is "*".

      • spec.matchConstraints.matchPolicy (string)

        matchPolicy defines how the "MatchResources" list is used to match incoming requests. Allowed values are "Exact" or "Equivalent".

        • Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the ValidatingAdmissionPolicy.

        • Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the ValidatingAdmissionPolicy.

        Defaults to "Equivalent"

      • spec.matchConstraints.namespaceSelector (LabelSelector)

        NamespaceSelector decides whether to run the admission control policy on an object based on whether the namespace for that object matches the selector. If the object itself is a namespace, the matching is performed on object.metadata.labels. If the object is another cluster scoped resource, it never skips the policy.

        For example, to run the webhook on any objects whose namespace is not associated with "runlevel" of "0" or "1"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }

        If instead you want to only run the policy on any objects whose namespace is associated with the "environment" of "prod" or "staging"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }

        See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more examples of label selectors.

        Default to the empty LabelSelector, which matches everything.

      • spec.matchConstraints.objectSelector (LabelSelector)

        ObjectSelector decides whether to run the validation based on if the object has matching labels. objectSelector is evaluated against both the oldObject and newObject that would be sent to the cel validation, and is considered to match if either object matches the selector. A null object (oldObject in the case of create, or newObject in the case of delete) or an object that cannot have labels (like a DeploymentRollback or a PodProxyOptions object) is not considered to match. Use the object selector only if the webhook is opt-in, because end users may skip the admission webhook by setting the labels. Default to the empty LabelSelector, which matches everything.

      • spec.matchConstraints.resourceRules ([]NamedRuleWithOperations)

        Atomic: will be replaced during a merge

        ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. The policy cares about an operation if it matches any Rule.

        NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.

        • spec.matchConstraints.resourceRules.apiGroups ([]string)

          Atomic: will be replaced during a merge

          APIGroups is the API groups the resources belong to. '' is all groups. If '' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.resourceRules.apiVersions ([]string)

          Atomic: will be replaced during a merge

          APIVersions is the API versions the resources belong to. '' is all versions. If '' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.resourceRules.operations ([]string)

          Atomic: will be replaced during a merge

          Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.

        • spec.matchConstraints.resourceRules.resourceNames ([]string)

          Atomic: will be replaced during a merge

          ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.

        • spec.matchConstraints.resourceRules.resources ([]string)

          Atomic: will be replaced during a merge

          Resources is a list of resources this rule applies to.

          For example: 'pods' means pods. 'pods/log' means the log subresource of pods. '' means all resources, but not subresources. 'pods/' means all subresources of pods. '/scale' means all scale subresources. '/*' means all resources and their subresources.

          If wildcard is present, the validation rule will ensure resources do not overlap with each other.

          Depending on the enclosing object, subresources might not be allowed. Required.

        • spec.matchConstraints.resourceRules.scope (string)

          scope specifies the scope of this rule. Valid values are "Cluster", "Namespaced", and "" "Cluster" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. "Namespaced" means that only namespaced resources will match this rule. "" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is "*".

    • spec.paramKind (ParamKind)

      ParamKind specifies the kind of resources used to parameterize this policy. If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions. If ParamKind refers to a non-existent kind, this policy definition is mis-configured and the FailurePolicy is applied. If paramKind is specified but paramRef is unset in ValidatingAdmissionPolicyBinding, the params variable will be null.

      ParamKind is a tuple of Group Kind and Version.

      • spec.paramKind.apiVersion (string)

        APIVersion is the API group version the resources belong to. In format of "group/version". Required.

      • spec.paramKind.kind (string)

        Kind is the API kind the resources belong to. Required.

    • spec.validations ([]Validation)

      Atomic: will be replaced during a merge

      Validations contain CEL expressions which is used to apply the validation. Validations and AuditAnnotations may not both be empty; a minimum of one Validations or AuditAnnotations is required.

      Validation specifies the CEL expression which is used to apply the validation.

      • spec.validations.expression (string), required

        Expression represents the expression which will be evaluated by CEL. ref: https://github.com/google/cel-spec CEL expressions have access to the contents of the API request/response, organized into CEL variables as well as some other useful variables:

        • 'object' - The object from the incoming request. The value is null for DELETE requests. - 'oldObject' - The existing object. The value is null for CREATE requests. - 'request' - Attributes of the API request(ref). - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind. - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources. - 'variables' - Map of composited variables, from its name to its lazily evaluated value. For example, a variable named 'foo' can be accessed as 'variables.foo'.
        • 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request. See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
        • 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the request resource.

        The apiVersion, kind, metadata.name and metadata.generateName are always accessible from the root of the object. No other metadata properties are accessible.

        Only property names of the form [a-zA-Z_.-/][a-zA-Z0-9_.-/]* are accessible. Accessible property names are escaped according to the following rules when accessed in the expression: - '' escapes to 'underscores' - '.' escapes to 'dot' - '-' escapes to 'dash' - '/' escapes to 'slash' - Property names that exactly match a CEL RESERVED keyword escape to '{keyword}__'. The keywords are: "true", "false", "null", "in", "as", "break", "const", "continue", "else", "for", "function", "if", "import", "let", "loop", "package", "namespace", "return". Examples:

        • Expression accessing a property named "namespace": {"Expression": "object.namespace > 0"}
        • Expression accessing a property named "x-prop": {"Expression": "object.x__dash__prop > 0"}
        • Expression accessing a property named "redact__d": {"Expression": "object.redact__underscores__d > 0"}

        Equality on arrays with list type of 'set' or 'map' ignores element order, i.e. [1, 2] == [2, 1]. Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type:

        • 'set': X + Y performs a union where the array positions of all elements in X are preserved and non-intersecting elements in Y are appended, retaining their partial order.
        • 'map': X + Y performs a merge where the array positions of all keys in X are preserved but the values are overwritten by values in Y when the key sets of X and Y intersect. Elements in Y with non-intersecting keys are appended, retaining their partial order. Required.
      • spec.validations.message (string)

        Message represents the message displayed when validation fails. The message is required if the Expression contains line breaks. The message must not contain line breaks. If unset, the message is "failed rule: {Rule}". e.g. "must be a URL with the host matching spec.host" If the Expression contains line breaks. Message is required. The message must not contain line breaks. If unset, the message is "failed Expression: {Expression}".

      • spec.validations.messageExpression (string)

        messageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails. Since messageExpression is used as a failure message, it must evaluate to a string. If both message and messageExpression are present on a validation, then messageExpression will be used if validation fails. If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged. messageExpression has access to all the same variables as the expression except for 'authorizer' and 'authorizer.requestResource'. Example: "object.x must be less than max ("+string(params.max)+")"

      • spec.validations.reason (string)

        Reason represents a machine-readable description of why this validation failed. If this is the first validation in the list to fail, this reason, as well as the corresponding HTTP response code, are used in the HTTP response to the client. The currently supported reasons are: "Unauthorized", "Forbidden", "Invalid", "RequestEntityTooLarge". If not set, StatusReasonInvalid is used in the response to the client.

    • spec.variables ([]Variable)

      Patch strategy: merge on key name

      Map: unique values on key name will be kept during a merge

      Variables contain definitions of variables that can be used in composition of other expressions. Each variable is defined as a named CEL expression. The variables defined here will be available under variables in other expressions of the policy except MatchConditions because MatchConditions are evaluated before the rest of the policy.

      The expression of a variable can refer to other variables defined earlier in the list but not those after. Thus, Variables must be sorted by the order of first appearance and acyclic.

      Variable is the definition of a variable that is used for composition. A variable is defined as a named expression.

      • spec.variables.expression (string), required

        Expression is the expression that will be evaluated as the value of the variable. The CEL expression has access to the same identifiers as the CEL expressions in Validation.

      • spec.variables.name (string), required

        Name is the name of the variable. The name must be a valid CEL identifier and unique among all variables. The variable can be accessed in other expressions through variables For example, if name is "foo", the variable will be available as variables.foo

  • status (ValidatingAdmissionPolicyStatus)

    The status of the ValidatingAdmissionPolicy, including warnings that are useful to determine if the policy behaves in the expected way. Populated by the system. Read-only.

    ValidatingAdmissionPolicyStatus represents the status of an admission validation policy.

    • status.conditions ([]Condition)

      Map: unique values on key type will be kept during a merge

      The conditions represent the latest available observations of a policy's current state.

      Condition contains details for one aspect of the current state of this API Resource.

      • status.conditions.lastTransitionTime (Time), required

        lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.

        Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.

      • status.conditions.message (string), required

        message is a human readable message indicating details about the transition. This may be an empty string.

      • status.conditions.reason (string), required

        reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.

      • status.conditions.status (string), required

        status of the condition, one of True, False, Unknown.

      • status.conditions.type (string), required

        type of condition in CamelCase or in foo.example.com/CamelCase.

      • status.conditions.observedGeneration (int64)

        observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.

    • status.observedGeneration (int64)

      The generation observed by the controller.

    • status.typeChecking (TypeChecking)

      The results of type checking for each expression. Presence of this field indicates the completion of the type checking.

      TypeChecking contains results of type checking the expressions in the ValidatingAdmissionPolicy

      • status.typeChecking.expressionWarnings ([]ExpressionWarning)

        Atomic: will be replaced during a merge

        The type checking warnings for each expression.

        ExpressionWarning is a warning information that targets a specific expression.

        • status.typeChecking.expressionWarnings.fieldRef (string), required

          The path to the field that refers the expression. For example, the reference to the expression of the first item of validations is "spec.validations[0].expression"

        • status.typeChecking.expressionWarnings.warning (string), required

          The content of type checking information in a human-readable form. Each line of the warning contains the type that the expression is checked against, followed by the type check error from the compiler.

ValidatingAdmissionPolicyBindingList

ValidatingAdmissionPolicyBindingList is a list of ValidatingAdmissionPolicyBinding.


Operations


get read the specified ValidatingAdmissionPolicyBinding

HTTP Request

GET /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings/{name}

Parameters

  • name (in path): string, required

    name of the ValidatingAdmissionPolicyBinding

  • pretty (in query): string

    pretty

Response

200 (ValidatingAdmissionPolicyBinding): OK

401: Unauthorized

list list or watch objects of kind ValidatingAdmissionPolicyBinding

HTTP Request

GET /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings

Parameters

Response

200 (ValidatingAdmissionPolicyBindingList): OK

401: Unauthorized

create create a ValidatingAdmissionPolicyBinding

HTTP Request

POST /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings

Parameters

Response

200 (ValidatingAdmissionPolicyBinding): OK

201 (ValidatingAdmissionPolicyBinding): Created

202 (ValidatingAdmissionPolicyBinding): Accepted

401: Unauthorized

update replace the specified ValidatingAdmissionPolicyBinding

HTTP Request

PUT /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings/{name}

Parameters

Response

200 (ValidatingAdmissionPolicyBinding): OK

201 (ValidatingAdmissionPolicyBinding): Created

401: Unauthorized

patch partially update the specified ValidatingAdmissionPolicyBinding

HTTP Request

PATCH /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings/{name}

Parameters

  • name (in path): string, required

    name of the ValidatingAdmissionPolicyBinding

  • body: Patch, required

  • dryRun (in query): string

    dryRun

  • fieldManager (in query): string

    fieldManager

  • fieldValidation (in query): string

    fieldValidation

  • force (in query): boolean

    force

  • pretty (in query): string

    pretty

Response

200 (ValidatingAdmissionPolicyBinding): OK

201 (ValidatingAdmissionPolicyBinding): Created

401: Unauthorized

delete delete a ValidatingAdmissionPolicyBinding

HTTP Request

DELETE /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings/{name}

Parameters

Response

200 (Status): OK

202 (Status): Accepted

401: Unauthorized

deletecollection delete collection of ValidatingAdmissionPolicyBinding

HTTP Request

DELETE /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicybindings

Parameters

Response

200 (Status): OK

401: Unauthorized