Admission WebhookによるAPIサーバーの拡張
検証用および変更用のAdmission Webhookを使って、処理中のKubernetes APIリクエストをインターセプトし、検証または変更してクラスターのポリシーを適用します。
「Admission WebhookによるAPIサーバーの拡張」はCoddyKit上の無料Docker & Kubernetes for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDocker & Kubernetes for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What Is Admission Control
After authentication and authorization, requests pass through admission controllers that can validate or modify objects before they are persisted.
Two Kinds of Webhooks
Dynamic admission uses webhooks: mutating webhooks change objects, and validating webhooks accept or reject them.
Where They Sit in the Pipeline
The API server runs mutating webhooks first, then validating webhooks, so a mutation can add defaults before validation checks the final object.
A Use Case
Examples: inject a sidecar (mutating), enforce that every Pod sets resource limits (validating), or block images from untrusted registries.
The MutatingWebhookConfiguration
This resource registers your webhook endpoint with the API server.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: add-defaults
webhooks:
- name: defaults.example.com
clientConfig:
service:
name: webhook-svc
namespace: default
path: /mutate
caBundle: <base64-ca>
rules:
- operations: ["CREATE"]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]The AdmissionReview Payload
The API server sends an AdmissionReview JSON to your webhook and expects an AdmissionReview response with allowed true/false, and for mutation a JSONPatch.
Returning a JSON Patch
A mutating webhook returns a base64-encoded JSONPatch describing the changes to apply.
{"response":{"allowed":true,"patchType":"JSONPatch","patch":"<base64-patch>"}}failurePolicy Matters
failurePolicy: Fail blocks requests if the webhook is down, which is safe but can lock up the cluster; Ignore lets requests through, which is risky for security policies.
Scoping With Selectors
Use namespaceSelector and objectSelector to limit which requests hit your webhook, avoiding overhead and accidental scope creep.
Policy Engines as an Alternative
Instead of writing webhook servers, tools like OPA Gatekeeper and Kyverno provide declarative policies on top of the same admission mechanism.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-limits
spec:
validationFailureAction: Enforce
rules:
- name: check-limits
match:
any:
- resources:
kinds: [Pod]
validate:
message: "CPU and memory limits are required"
pattern:
spec:
containers:
- resources:
limits:
memory: "?*"TLS Is Required
Webhook endpoints must serve HTTPS with a certificate trusted via the caBundle, since the API server only calls webhooks over TLS.
Quick Check
Test what you have learned.
Recap
You learned how admission webhooks extend the API server: mutating webhooks change objects and validating webhooks enforce policy, the AdmissionReview flow, failurePolicy and selectors, TLS requirements, and policy engines like Kyverno and Gatekeeper.
AI チューターと学ぶ Docker & Kubernetes for Developers — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「Admission WebhookによるAPIサーバーの拡張」レッスンは無料ですか?
はい。「Admission WebhookによるAPIサーバーの拡張」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Docker & Kubernetes for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
「Admission WebhookによるAPIサーバーの拡張」で何を学びますか?
検証用および変更用のAdmission Webhookを使って、処理中のKubernetes APIリクエストをインターセプトし、検証または変更してクラスターのポリシーを適用します。 ブラウザで直接実行するハンズオンコードでDocker & Kubernetes for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Docker & Kubernetes for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDocker & Kubernetes for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Admission WebhookによるAPIサーバーの拡張」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDocker & Kubernetes for Developersレッスンでコードを書いて実行できますか?
はい。すべてのDocker & Kubernetes for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- カスタムリソース定義(CRD)
- KubernetesのOperatorパターン
- Kubernetesによるサーバーレス(Knative)
- Admission WebhookによるAPIサーバーの拡張