MutatingWebhookConfiguration
apiVersion: admissionregistration.k8s.io/v1
import "k8s.io/api/admissionregistration/v1"
MutatingWebhookConfiguration
MutatingWebhookConfiguration 描述了接受或拒絕並可能變更物件的准入 webhook 的組態。
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata (ObjectMeta)
標準物件元數據;更多資訊:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata。
webhooks ([]MutatingWebhook)
Patch 策略:在鍵
name
上合併Map:在合併期間,鍵名稱上的唯一值將被保留
Webhooks 是 webhook 列表,以及受影響的資源和操作。
MutatingWebhook 描述了一個准入 webhook 及其應用的資源和操作。
webhooks.admissionReviewVersions ([]string), required
Atomic:將在合併期間被替換
AdmissionReviewVersions 是 Webhook 期望的偏好
AdmissionReview
版本排序列表。API 伺服器將嘗試使用列表中它支援的第一個版本。如果此列表中指定的版本 API 伺服器都不支援,則此物件的驗證將失敗。如果持久化的 webhook 組態指定了允許的版本,但不包含 API 伺服器已知的任何版本,則對 webhook 的呼叫將失敗,並受制於失敗策略。webhooks.clientConfig (WebhookClientConfig), required
ClientConfig 定義了如何與 hook 通訊。必要
WebhookClientConfig 包含與 webhook 建立 TLS 連線的資訊
webhooks.clientConfig.caBundle ([]byte)
caBundle
是一個 PEM 編碼的 CA 捆綁包,將用於驗證 webhook 的伺服器憑證。如果未指定,則使用 apiserver 上的系統信任根。webhooks.clientConfig.service (ServiceReference)
service
是對此 webhook 服務的參考。必須指定service
或url
之一。如果 webhook 在叢集內執行,則應使用
service
。ServiceReference 保留對 Service.legacy.k8s.io 的參考
webhooks.clientConfig.service.name (string), required
name
是服務的名稱。必要webhooks.clientConfig.service.namespace (string), required
namespace
是服務的命名空間。必要webhooks.clientConfig.service.path (string)
path
是一個可選的 URL 路徑,將在對此服務的任何請求中傳送。webhooks.clientConfig.service.port (int32)
如果指定,則為託管 webhook 的服務上的連接埠。預設值為 443 以實現向後相容性。
port
應為有效的連接埠號碼 (1-65535,包含)。
webhooks.clientConfig.url (string)
url
給出了 webhook 的位置,以標準 URL 形式 (scheme://host:port/path
)。必須指定url
或service
之一。host
不應參考在叢集中運行的服務;請改用service
欄位。主機可能會透過某些 apiserver 中的外部 DNS 解析 (例如,kube-apiserver
無法解析叢集內 DNS,因為那會是分層違規)。host
也可能是 IP 位址。請注意,使用
localhost
或127.0.0.1
作為host
是有風險的,除非您非常小心地在所有運行可能需要呼叫此 webhook 的 apiserver 的主機上運行此 webhook。此類安裝可能不具可攜性,即不易在新叢集中啟動。scheme 必須為 "https";URL 必須以 "https://" 開頭。
path 是可選的,如果存在,則可以是 URL 中允許的任何字串。您可以使用路徑將任意字串傳遞給 webhook,例如叢集識別符。
不允許嘗試使用使用者或基本身份驗證,例如 "user:password@"。也不允許片段 ("#...") 和查詢參數 ("?...")。
webhooks.name (string), required
准入 webhook 的名稱。名稱應完全限定,例如 imagepolicy.kubernetes.io,其中 "imagepolicy" 是 webhook 的名稱,而 kubernetes.io 是組織的名稱。必要。
webhooks.sideEffects (string), required
SideEffects 說明此 webhook 是否具有副作用。可接受的值為:None、NoneOnDryRun (透過 v1beta1 建立的 webhook 也可能指定 Some 或 Unknown)。具有副作用的 Webhook 必須實作協調系統,因為請求可能會被准入鏈中未來的步驟拒絕,因此需要撤銷副作用。如果具有 dryRun 屬性的請求與 sideEffects == Unknown 或 Some 的 webhook 匹配,則會自動拒絕這些請求。
webhooks.failurePolicy (string)
FailurePolicy 定義了如何處理來自准入端點的無法辨識的錯誤 - 允許的值為 Ignore 或 Fail。預設值為 Fail。
webhooks.matchConditions ([]MatchCondition)
Patch 策略:在鍵
name
上合併Map:在合併期間,鍵名稱上的唯一值將被保留
MatchConditions 是必須滿足的條件列表,請求才能傳送到此 webhook。匹配條件會篩選已經被規則、namespaceSelector 和 objectSelector 匹配的請求。空的 matchConditions 列表會匹配所有請求。最多允許 64 個匹配條件。
確切的匹配邏輯是 (依序)
- 如果任何 matchCondition 評估為 FALSE,則跳過 webhook。
- 如果所有 matchCondition 都評估為 TRUE,則呼叫 webhook。
- 如果任何 matchCondition 評估為錯誤 (但沒有任何一個為 FALSE)
- 如果 failurePolicy=Fail,則拒絕請求
- 如果 failurePolicy=Ignore,則忽略錯誤並跳過 webhook
MatchCondition 代表必須滿足的條件,請求才能傳送到 webhook。
webhooks.matchConditions.expression (string), required
Expression 代表將由 CEL 評估的表達式。必須評估為 bool。CEL 表達式可以存取 AdmissionRequest 和 Authorizer 的內容,組織到 CEL 變數中
'object' - 來自傳入請求的物件。對於 DELETE 請求,此值為 null。 'oldObject' - 現有的物件。對於 CREATE 請求,此值為 null。 'request' - 准入請求的屬性 (/pkg/apis/admission/types.go#AdmissionRequest)。 'authorizer' - CEL 授權器。可用於對請求的主體(使用者或服務帳戶)執行授權檢查。請參閱 https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 'authorizer.requestResource' - 從 'authorizer' 建構並使用請求資源配置的 CEL ResourceCheck。關於 CEL 的文件:https://kubernetes.dev.org.tw/docs/reference/using-api/cel/
必要。
webhooks.matchConditions.name (字串), 必要
名稱是此匹配條件的識別符,用於策略性合併 MatchConditions,以及為日誌記錄目的提供識別符。一個好的名稱應能描述相關的表達式。名稱必須是符合資格的名稱,由字母數字字符、'-'、'_' 或 '.' 組成,且必須以字母數字字符開頭和結尾(例如 'MyName'、'my.name' 或 '123-abc',用於驗證的正規表示式為 '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]'),可選的 DNS 子網域前綴和 '/'(例如 'example.com/MyName')
必要。
webhooks.matchPolicy (字串)
matchPolicy 定義了「rules」列表如何用於匹配傳入的請求。允許的值為「Exact」或「Equivalent」。
Exact:僅當請求與指定的規則完全匹配時才匹配請求。例如,如果可以透過 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改 deployments,但「rules」僅包含
apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]
,則對 apps/v1beta1 或 extensions/v1beta1 的請求將不會發送到 webhook。Equivalent:即使透過另一個 API 群組或版本,如果請求修改了 rules 中列出的資源,則匹配請求。例如,如果可以透過 apps/v1、apps/v1beta1 和 extensions/v1beta1 修改 deployments,且「rules」僅包含
apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]
,則對 apps/v1beta1 或 extensions/v1beta1 的請求將被轉換為 apps/v1 並發送到 webhook。
預設為「Equivalent」
webhooks.namespaceSelector (LabelSelector)
NamespaceSelector 決定是否基於物件的命名空間是否與選擇器匹配,來對該物件執行 webhook。如果物件本身是一個命名空間,則匹配將在 object.metadata.labels 上執行。如果物件是另一個叢集範圍的資源,則永遠不會跳過 webhook。
例如,要在任何命名空間未與「runlevel」為「0」或「1」關聯的物件上執行 webhook;您將如下設定選擇器:「namespaceSelector」: { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }
相反地,如果您只想在任何命名空間與「environment」為「prod」或「staging」關聯的物件上執行 webhook;您將如下設定選擇器:「namespaceSelector」: { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }
有關標籤選擇器的更多範例,請參閱 https://kubernetes.dev.org.tw/docs/concepts/overview/working-with-objects/labels/。
預設為空的 LabelSelector,它匹配所有內容。
webhooks.objectSelector (LabelSelector)
ObjectSelector 決定是否基於物件是否具有匹配的標籤來執行 webhook。objectSelector 會針對將發送到 webhook 的 oldObject 和 newObject 進行評估,並且如果任一物件與選擇器匹配,則視為匹配。空物件(create 情況下的 oldObject,或 delete 情況下的 newObject)或無法擁有標籤的物件(例如 DeploymentRollback 或 PodProxyOptions 物件)不被視為匹配。僅當 webhook 是選擇加入時才使用物件選擇器,因為終端使用者可以透過設定標籤來跳過准入 webhook。預設為空的 LabelSelector,它匹配所有內容。
webhooks.reinvocationPolicy (字串)
reinvocationPolicy 指示此 webhook 是否應在單一准入評估中多次呼叫。允許的值為「Never」和「IfNeeded」。
Never:webhook 在單一准入評估中不會被呼叫超過一次。
IfNeeded:如果被准入的物件在初始 webhook 呼叫後被其他准入外掛程式修改,則 webhook 將在准入評估中至少被額外呼叫一次。指定此選項的 Webhook必須是冪等的,能夠處理它們先前准入的物件。注意:* 不保證額外調用的次數正好為一次。 * 如果額外調用導致對物件的進一步修改,則不保證再次調用 webhook。 * 使用此選項的 webhook 可能會重新排序,以最大限度地減少額外調用的次數。 * 若要在保證所有變更都完成後驗證物件,請改用驗證准入 webhook。
預設為「Never」。
webhooks.rules ([]RuleWithOperations)
Atomic:將在合併期間被替換
Rules 描述了 webhook 關心哪些資源/子資源上的哪些操作。如果操作與任何 Rule 匹配,則 webhook 關心該操作。但是,為了防止 ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks 將叢集置於無法恢復的狀態(除非完全停用外掛程式),ValidatingAdmissionWebhooks 和 MutatingAdmissionWebhooks 永遠不會在 ValidatingWebhookConfiguration 和 MutatingWebhookConfiguration 物件的准入請求上被呼叫。
RuleWithOperations 是 Operations 和 Resources 的元組。建議確保所有元組擴展都是有效的。
webhooks.rules.apiGroups ([]字串)
Atomic:將在合併期間被替換
APIGroups 是資源所屬的 API 群組。「*」是所有群組。如果存在「*」,則切片的長度必須為一。必要。
webhooks.rules.apiVersions ([]字串)
Atomic:將在合併期間被替換
APIVersions 是資源所屬的 API 版本。「*」是所有版本。如果存在「*」,則切片的長度必須為一。必要。
webhooks.rules.operations ([]字串)
Atomic:將在合併期間被替換
Operations 是准入 hook 關心的操作 - CREATE、UPDATE、DELETE、CONNECT 或 *,表示所有這些操作以及任何未來新增的准入操作。如果存在「*」,則切片的長度必須為一。必要。
webhooks.rules.resources ([]字串)
Atomic:將在合併期間被替換
Resources 是此規則適用之資源的列表。
例如:「pods」表示 pods。「pods/log」表示 pods 的 log 子資源。「*」表示所有資源,但不包括子資源。「pods/*」表示 pods 的所有子資源。「*/scale」表示所有 scale 子資源。「*/*」表示所有資源及其子資源。
如果存在萬用字元,則驗證規則將確保資源彼此不重疊。
根據封閉物件的不同,可能不允許子資源。必要。
webhooks.rules.scope (字串)
scope 指定此規則的範圍。有效值為「Cluster」、「Namespaced」和「*」。「Cluster」表示只有叢集範圍的資源才會與此規則匹配。命名空間 API 物件是叢集範圍的。「Namespaced」表示只有命名空間資源才會與此規則匹配。「*」表示沒有範圍限制。子資源與其父資源的範圍匹配。預設值為「*」。
webhooks.timeoutSeconds (int32)
TimeoutSeconds 指定此 webhook 的逾時時間。逾時時間過後,將忽略 webhook 呼叫,或 API 呼叫將根據失敗策略而失敗。逾時值必須介於 1 到 30 秒之間。預設為 10 秒。
MutatingWebhookConfigurationList
MutatingWebhookConfigurationList 是 MutatingWebhookConfiguration 的列表。
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfigurationList
metadata (ListMeta)
標準列表元數據。更多資訊:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
items ([]MutatingWebhookConfiguration), 必要
MutatingWebhookConfiguration 的列表。
Operations
get
讀取指定的 MutatingWebhookConfiguration
HTTP Request
GET /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
Parameters
name (in path): 字串, 必要
MutatingWebhookConfiguration 的名稱
pretty (in query): 字串
Response
200 (MutatingWebhookConfiguration): OK
401: Unauthorized
list
列出或監看 kind 為 MutatingWebhookConfiguration 的物件
HTTP Request
GET /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
Parameters
allowWatchBookmarks (in query): 布林值
continue (in query): 字串
fieldSelector (in query): 字串
labelSelector (in query): 字串
limit (in query): 整數
pretty (in query): 字串
resourceVersion (in query): 字串
resourceVersionMatch (in query): 字串
sendInitialEvents (in query): 布林值
timeoutSeconds (in query): 整數
watch (in query): 布林值
Response
200 (MutatingWebhookConfigurationList): OK
401: Unauthorized
create
建立一個 MutatingWebhookConfiguration
HTTP Request
POST /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
Parameters
body: MutatingWebhookConfiguration, 必要
dryRun (in query): 字串
fieldManager (in query): 字串
fieldValidation (in query): 字串
pretty (in query): 字串
Response
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
202 (MutatingWebhookConfiguration): Accepted
401: Unauthorized
update
取代指定的 MutatingWebhookConfiguration
HTTP Request
PUT /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
Parameters
name (in path): 字串, 必要
MutatingWebhookConfiguration 的名稱
body: MutatingWebhookConfiguration, 必要
dryRun (in query): 字串
fieldManager (in query): 字串
fieldValidation (in query): 字串
pretty (in query): 字串
Response
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: Unauthorized
patch
部分更新指定的 MutatingWebhookConfiguration
HTTP Request
PATCH /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
Parameters
name (in path): 字串, 必要
MutatingWebhookConfiguration 的名稱
body: Patch, 必要
dryRun (in query): 字串
fieldManager (in query): 字串
fieldValidation (in query): 字串
force (in query): 布林值
pretty (in query): 字串
Response
200 (MutatingWebhookConfiguration): OK
201 (MutatingWebhookConfiguration): Created
401: Unauthorized
delete
刪除 MutatingWebhookConfiguration
HTTP Request
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations/{name}
Parameters
name (in path): 字串, 必要
MutatingWebhookConfiguration 的名稱
body: DeleteOptions
dryRun (in query): 字串
gracePeriodSeconds (in query): 整數
pretty (in query): 字串
propagationPolicy (in query): 字串
Response
200 (Status): OK
202 (Status): Accepted
401: Unauthorized
deletecollection
刪除 MutatingWebhookConfiguration 的集合
HTTP Request
DELETE /apis/admissionregistration.k8s.io/v1/mutatingwebhookconfigurations
Parameters
body: DeleteOptions
continue (in query): 字串
dryRun (in query): 字串
fieldSelector (in query): 字串
gracePeriodSeconds (in query): 整數
labelSelector (in query): 字串
limit (in query): 整數
pretty (in query): 字串
propagationPolicy (in query): 字串
resourceVersion (in query): 字串
resourceVersionMatch (in query): 字串
sendInitialEvents (in query): 布林值
timeoutSeconds (in query): 整數
Response
200 (Status): OK
401: Unauthorized
此頁面為自動產生。
如果您計劃回報此頁面的問題,請在您的問題描述中提及此頁面是自動產生的。修正可能需要在 Kubernetes 專案中的其他地方進行。