Application Gateway イングレス コントローラーの注釈

Kubernetes イングレス リソースには、任意のキー/値のペアを使用して注釈を付けることができます。 AGIC は、イングレス YAML を介して構成できない Application Gateway 機能をプログラムするために、注釈に依存します。 イングレス注釈は、イングレス リソースから派生したすべての HTTP 設定、バックエンド プール、およびリスナーに適用されます。

サポートされている注釈の一覧

イングレス リソースを AGIC によって監視するためには、kubernetes.io/ingress.class: azure/application-gateway を使用してリソースに注釈を付ける必要があります。 そうしないと、AGIC は問題のイングレス リソースに対して機能しません。

注釈キー 値の種類 Default Value 使用できる値
appgw.ingress.kubernetes.io/backend-path-prefix string nil
appgw.ingress.kubernetes.io/ssl-redirect bool false
appgw.ingress.kubernetes.io/connection-draining bool false
appgw.ingress.kubernetes.io/connection-draining-timeout int32 (秒) 30
appgw.ingress.kubernetes.io/cookie-based-affinity bool false
appgw.ingress.kubernetes.io/request-timeout int32 (秒) 30
appgw.ingress.kubernetes.io/use-private-ip bool false
appgw.ingress.kubernetes.io/backend-protocol string http http, https
appgw.ingress.kubernetes.io/rewrite-rule-set string nil

バックエンド パス プレフィックス

次の注釈を使用すると、イングレス リソースで指定されたバックエンド パスを、この注釈で指定されたプレフィックスで書き換えることができます。 これによりユーザーは、サービスのエンドポイントが、イングレス リソースでサービスを公開するために使用されるエンドポイント名と異なっている場合でも、そのサービスを公開できます。

使用方法

appgw.ingress.kubernetes.io/backend-path-prefix: <path prefix>

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-bkprefix
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-path-prefix: "/test/"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 80

前の例では、注釈 appgw.ingress.kubernetes.io/backend-path-prefix: "/test/" を使用して、go-server-ingress-bkprefix という名前のイングレス リソースを定義しました。 この注釈は、パス /hello から /test/ へのパス プレフィックス オーバーライドを含む HTTP 設定を作成するよう、アプリケーション ゲートウェイに指示します。

Note

上記の例では、1 つの規則のみを定義しています。 ただし、注釈はイングレス リソース全体に適用可能なため、ユーザーが複数の規則を定義した場合、指定されたパスのそれぞれに対してバックエンド パス プレフィックスが設定されます。 (同じサービスに対するものであっても) パス プレフィックスが異なっている別々の規則が必要な場合、ユーザーは別々のイングレス リソースを定義する必要があります。

TLS リダイレクト

対応する HTTPS に HTTP URL を自動的にリダイレクトするように Application Gateway を構成できます。 この注釈が存在し、TLS が正しく構成されている場合、Kubernetes イングレス コントローラーは、リダイレクト構成を持つルーティング規則を作成し、変更を Application Gateway に適用します。 作成されるリダイレクトは HTTP 301 Moved Permanently になります。

使用方法

appgw.ingress.kubernetes.io/ssl-redirect: "true"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-redirect
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
   - hosts:
     - www.contoso.com
     secretName: testsecret-tls
  rules:
  - host: www.contoso.com
    http:
      paths:
      - backend:
          service:
            name: websocket-repeater
            port:
              number: 80

接続のドレイン

connection-draining: この注釈により、接続のドレインを有効にするかどうかを指定できます。 connection-draining-timeout: この注釈により、タイムアウトを指定できます。この時間の経過後に Application Gateway は、ドレイン状態のバックエンド エンドポイントへの要求を終了します。

使用方法

appgw.ingress.kubernetes.io/connection-draining: "true"
appgw.ingress.kubernetes.io/connection-draining-timeout: "60"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-drain
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/connection-draining: "true"
    appgw.ingress.kubernetes.io/connection-draining-timeout: "60"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 80

次の注釈では、Cookie ベースのアフィニティを有効にするかどうかを指定できます。

使用方法

appgw.ingress.kubernetes.io/cookie-based-affinity: "true"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-affinity
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/cookie-based-affinity: "true"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 80

Request Timeout

次の注釈では、要求タイムアウトを秒単位で指定できます。この時間を過ぎても応答が受信されない場合、Application Gateway は要求を失敗と見なします。

使用方法

appgw.ingress.kubernetes.io/request-timeout: "20"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-timeout
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/request-timeout: "20"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 80

プライベート IP を使用

次の注釈では、このエンドポイントを Application Gateway のプライベート IP で公開するかどうかを指定できます。

Note

  • Application Gateway では、同じポート上の複数の IP (例: 80/443) はサポートされません。 HTTP で、appgw.ingress.kubernetes.io/use-private-ip: "false" という注釈を持つイングレスと、appgw.ingress.kubernetes.io/use-private-ip: "true" という注釈を持つ別のイングレスがある場合、AGIC は Application Gateway の更新に失敗します。
  • プライベート IP を持たない Application Gateway では、appgw.ingress.kubernetes.io/use-private-ip: "true" という注釈を持つイングレスは無視されます。 NoPrivateIP 警告が有効なイングレスの場合、これはコントローラーのログとイングレス イベントに反映されます。

使用方法

appgw.ingress.kubernetes.io/use-private-ip: "true"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-timeout
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/use-private-ip: "true"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 80

バックエンド プロトコル

次の注釈を使用すると、ポッドとの通信中に Application Gateway が使用するプロトコルを指定できます。 サポートされているプロトコルは、httphttps です。

Note

自己署名証明書は Application Gateway でサポートされていますが、現在は、よく知られた CA によって署名された証明書をポッドが使用している場合、AGIC は https のみをサポートします。

ポッドでは、HTTPS ではポート 80、HTTP ではポート 443 を使用しないようにしてください。

使用方法

appgw.ingress.kubernetes.io/backend-protocol: "https"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-timeout
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-protocol: "https"
spec:
  rules:
  - http:
      paths:
      - path: /hello/
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 443

書き換えルール セット

次の注釈を使用すると、既存の書き換えルール セットを対応する要求ルーティング規則に割り当てることができます。

使用方法

appgw.ingress.kubernetes.io/rewrite-rule-set: <rewrite rule set name>

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-server-ingress-bkprefix
  namespace: test-ag
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/rewrite-rule-set: add-custom-response-header
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Exact
        backend:
          service:
            name: go-server-service
            port:
              number: 8080