ALB Ingress Controller v2.15.0 では、Webhook 検証サービスが導入されています。このサービスは、アドミッション Webhook を使用して、API レベルで設定を検証します。無効または非準拠の設定が適用される前にインターセプトし、明確なエラーメッセージを提供します。この機能により、気づかれない可能性のある形式エラーによるリコンシリエーションの失敗を防ぎます。このトピックでは、Webhook 検証サービスの仕組みを説明し、一般的なエラーメッセージの例を示します。
仕組み
-
動的アドミッションコントロール
Kubernetes v1.9 以降、動的アドミッションコントロールでアドミッション Webhook がサポートされるようになりました。コンポーネントを使用して、API サーバーに送信されるリクエストにアクセス制御を適用できます。リクエストが認証および承認された後、オブジェクトが永続化される前に、API サーバーはリクエストをインターセプトし、アドミッションコントロールのために Webhook サービスを呼び出します。
-
Webhook 検証の利点
-
早期インターセプト:Webhook は、API レベルで誤った設定や非準拠の設定をインターセプトします。これにより、不要なリソース作成の試行が減少し、クラスターの状態への潜在的な混乱を防ぎ、リソーススケジューリングやネットワーク設定などの後続のステップでのリソースの無駄を回避します。
-
疎結合なロジック:Webhook に検証ロジックを配置することで、コントローラーは中核となる責務であるリソースのデプロイと管理に集中できます。これは単一責任の原則に準拠し、システムをよりモジュール化し、保守しやすく、スケーラブルにします。
-
セキュリティの強化:YAML 検証ロジックを独立した Webhook サービスに配置することで、クラスターへのリソースリクエストの一元管理と制御が可能になります。これにより、悪意のある設定や誤った設定のリスクが軽減されます。
-
設定ミスの即時フィードバック:パラメーターが誤っている場合、Webhook サービスはリクエストをインターセプトし、明確なエラーメッセージを提供して、問題を迅速に特定して修正できるようにします。
-
-
主要な Webhook コンポーネント
-
ValidatingAdmissionWebhook: API サーバーが Ingress の作成または更新リクエストを受信したときに呼び出す webhook URL を定義し、どの操作とリソースが webhook 検証をトリガーするかを指定します。このコンポーネントは、ALB Ingress Controller とともにデプロイされます。
-
TLS 証明書: API サーバーと Webhook サービス間の通信を暗号化します。
-
Webhook サービス:受信した AdmissionReview リクエストを解析し、Ingress リソース定義を検証し、
AdmissionResponseを生成します。
-
Webhook インターセプトメッセージ
-
Webhook インターセプトメッセージの例
次の例は、誤って設定された Ingress YAML ファイルを示しています。
listen-portsアノテーションの形式が正しくないため、Webhook サービスはエラーを識別し、迅速に修正できるように特定のエラーメッセージを返します。-
リクエストは、"the current request failed admission control" というメッセージでアドミッションコントロールに失敗します。詳細なエラーメッセージは
"admission webhook "ingress.alb.validate.k8s.io" denied the request: webhook validate ingress test: failed to parse listen-ports configuration: '[{"HTTP": 80},{"HTTPS": 443}]': invalid character ']' after object key:value pair"で、エラーコードはAPISERVER.403です。 -
CLI エラーメッセージ:
[root@iZxxxZ test]# kubectl apply -f test-ingress.yaml Error from server (webhook validate ingress alb-ingress: failed to parse listen-ports configuration: `[{"HTTP": 80},{"HTTPS": 443}]`: invalid character ']' after object key:value pair): error when creating "test-ingress.yaml": admission webhook "ingress.alb.validate.k8s.io" denied the request: webhook validate ingress alb-ingress: failed to parse listen-ports configuration: `[{"HTTP": 80},{"HTTPS": 443}]`: invalid character ']' after object key:value pair
-
-
Webhook
"admission webhook "ingress.alb.validate.k8s.io""は、リスナーポート設定に配列要素の後に無効な文字"]"が含まれていたため、リクエストを拒否しました。
次の表は、AlbConfig および Ingress リソースの検証エラーメッセージのその他の例を示しています。
|
リソースタイプ |
エラータイプ |
エラーメッセージ |
|
AlbConfig |
AlbConfig のアンマーシャル失敗 |
webhook validate albconfig alb: Unmarshal error : %v Please check the format of albconfig yaml |
|
無効なリスナーポート |
webhook validate albconfig alb: listener port number must be between [1:65535], or you should set listen port explicitly in listener config. Error listen port : 0 |
|
|
無効なリスナープロトコル |
webhook validate albconfig alb: listener protocol is invalid : HTTPP, or you should set listen protocol explicitly in listener config. Please set protocol value HTTP or HTTPS or QUIC |
|
|
Logstore 形式の検証 |
webhook validate albconfig alb: logstore name should start with alb_ |
|
|
タグ形式の検証 |
webhook validate albconfig alb: empty tag key/value is invalid |
|
|
IP アドレスタイプの検証 |
the value Interne is invalid. Please set the value as one of: [Internet Intranet] |
|
|
IPv6 アドレスタイプの検証 |
the value Interne is invalid. Please set the value as one of: [Internet Intranet] |
|
|
IP アドレスモードの検証 |
the value Dynamicc is invalid. Please set the value as one of: [Dynamic Fixed] |
|
|
インスタンスタイプの検証 |
the value Standardd is invalid. Please set the value as one of: [Basic Standard StandardWithWaf] |
|
|
アクセスコントロール |
webhook validate albconfig alb: aclEntry and aclIds cannot use together in listener |
|
|
Ingress |
Backend-scheduler |
the value of alb.ingress.kubernetes.io/backend-scheduler annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [wrr wlc sch uch] |
|
Backend-protocol |
the value of alb.ingress.kubernetes.io/backend-protocol annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [HTTP HTTPS gRPC] |
|
|
Healthcheck-protocol |
the value of alb.ingress.kubernetes.io/healthcheck-protocol annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [HTTP HTTPS TCP gRPC] |
|
|
Healthcheck-method |
the value of alb.ingress.kubernetes.io/healthcheck-method annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [GET HEAD POST] |
|
|
Healthcheck-httpcode |
the value of alb.ingress.kubernetes.io/healthcheck-httpcode annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [http_2xx http_3xx http_4xx http_5xx] |
|
|
Healthcheck-httpversion |
the value of alb.ingress.kubernetes.io/healthcheck-httpversion annotation is invalid : test. the value wlcc is invalid. Please set the value as one of: [HTTP1.1 HTTP1.0] |
|
|
無効な listen-port 形式 |
webhook validate ingress ingress: check ingress listen port invalid |
|
|
パスに '^' を含めることはできません |
webhook validate ingress ingress: path is invalid because path contains ^ character |
|
|
カスタム転送アクションのアンマーシャル失敗 |
webhook validate ingress test: the value of actions annotation is invalid |