컨테이너용 Application Gateway를 사용한 SSL 오프로딩 - 게이트웨이 API

이 문서는 게이트웨이 API에서 다음 리소스를 사용하는 예제 애플리케이션을 설정하는 데 도움이 됩니다. 다음 단계가 제공됩니다.

  • 하나의 HTTPS 수신기를 사용하여 게이트웨이 리소스를 만듭니다.
  • 백 엔드 서비스를 참조하는 HTTPRoute를 만듭니다.

배경

백 엔드 성능 향상을 위해 컨테이너용 Application Gateway를 통해 SSL 오프로딩을 사용하도록 설정할 수 있습니다. 다음과 같은 예제 시나리오를 참조하세요.

Application Gateway for Containers를 사용한 SSL 오프로딩을 보여 주는 그림.

필수 조건

  1. BYO 배포 전략을 따르는 경우 컨테이너용 Application Gateway 리소스 및 ALB 컨트롤러를 설정했는지 확인합니다.

  2. ALB 관리된 배포 전략을 따르는 경우 ALB 컨트롤러를 프로비전하고 ApplicationLoadBalancer 사용자 지정 리소스를 통해 컨테이너용 Application Gateway 리소스를 프로비전했는지 확인합니다.

  3. 샘플 HTTPS 애플리케이션 배포 클러스터에 다음 deployment.yaml 파일을 적용하여 TLS/SSL 오프로드를 보여 주는 샘플 웹 애플리케이션을 만듭니다.

    kubectl apply -f https://trafficcontrollerdocs.blob.core.windows.net/examples/https-scenario/ssl-termination/deployment.yaml
    

    이 명령은 클러스터에 다음을 만듭니다.

    • test-infra라는 네임스페이스
    • test-infra 네임스페이스에 있는 echo(이)라는 하나의 서비스
    • test-infra 네임스페이스에 있는 echo(이)라는 하나의 배포
    • test-infra 네임스페이스에 있는 listener-tls-secret이라는 하나의 비밀

필수 게이트웨이 API 리소스 배포

  1. 게이트웨이 만들기

    kubectl apply -f - <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: gateway-01
      namespace: test-infra
      annotations:
        alb.networking.azure.io/alb-namespace: alb-test-infra
        alb.networking.azure.io/alb-name: alb-test
    spec:
      gatewayClassName: azure-alb-external
      listeners:
      - name: https-listener
        port: 443
        protocol: HTTPS
        allowedRoutes:
          namespaces:
            from: Same
        tls:
          mode: Terminate
          certificateRefs:
          - kind : Secret
            group: ""
            name: listener-tls-secret
    EOF
    

참고 항목

ALB 컨트롤러는 ARM에서 컨테이너용 Application Gateway 리소스를 만들 때 프런트 엔드 리소스에 fe-<임의로 생성된 문자 8개>와 같은 명명 규칙을 사용합니다.

Azure에서 만들어진 프런트 엔드의 이름을 변경하려면 자체 배포 전략 가져오기를 따르는 것이 좋습니다.

게이트웨이 리소스가 만들어지면 상태가 유효한지, 수신기가 프로그래밍되어 있는지, 주소가 게이트웨이에 할당되어 있는지 확인합니다.

kubectl get gateway gateway-01 -n test-infra -o yaml

게이트웨이가 성공적으로 만들어진 경우의 출력 예제입니다.

status:
  addresses:
  - type: Hostname
    value: xxxx.yyyy.alb.azure.com
  conditions:
  - lastTransitionTime: "2023-06-19T21:04:55Z"
    message: Valid Gateway
    observedGeneration: 1
    reason: Accepted
    status: "True"
    type: Accepted
  - lastTransitionTime: "2023-06-19T21:04:55Z"
    message: Application Gateway For Containers resource has been successfully updated.
    observedGeneration: 1
    reason: Programmed
    status: "True"
    type: Programmed
  listeners:
  - attachedRoutes: 0
    conditions:
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: ""
      observedGeneration: 1
      reason: ResolvedRefs
      status: "True"
      type: ResolvedRefs
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: Listener is accepted
      observedGeneration: 1
      reason: Accepted
      status: "True"
      type: Accepted
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: Application Gateway For Containers resource has been successfully updated.
      observedGeneration: 1
      reason: Programmed
      status: "True"
      type: Programmed
    name: https-listener
    supportedKinds:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute

게이트웨이가 만들어지면 HTTPRoute 리소스를 만듭니다.

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: https-route
  namespace: test-infra
spec:
  parentRefs:
  - name: gateway-01
  rules:
  - backendRefs:
    - name: echo
      port: 80
EOF

HTTPRoute 리소스가 만들어지면 경로가 수락됨 상태이고 컨테이너용 Application Gateway 리소스가 프로그래밍됨 상태인지 확인합니다.

kubectl get httproute https-route -n test-infra -o yaml

컨테이너용 Application Gateway 리소스가 성공적으로 업데이트되었는지 확인합니다.

status:
  parents:
  - conditions:
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: ""
      observedGeneration: 1
      reason: ResolvedRefs
      status: "True"
      type: ResolvedRefs
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: Route is Accepted
      observedGeneration: 1
      reason: Accepted
      status: "True"
      type: Accepted
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: Application Gateway For Containers resource has been successfully updated.
      observedGeneration: 1
      reason: Programmed
      status: "True"
      type: Programmed
    controllerName: alb.networking.azure.io/alb-controller
    parentRef:
      group: gateway.networking.k8s.io
      kind: Gateway
      name: gateway-01
      namespace: test-infra

애플리케이션에 대한 액세스 테스트

이제 프런트 엔드에 할당된 FQDN을 통해 샘플 애플리케이션에 일부 트래픽을 전송할 준비가 되었습니다. 다음 명령을 사용하여 FQDN을 가져옵니다.

fqdn=$(kubectl get gateway gateway-01 -n test-infra -o jsonpath='{.status.addresses[0].value}')

이 FQDN을 컬링하면 HTTPRoute에 구성된 대로 백 엔드에서 응답을 반환해야 합니다.

curl --insecure https://$fqdn/

축하합니다. ALB 컨트롤러를 설치하고, 백 엔드 애플리케이션을 배포하고, 컨테이너용 Azure Application Gateway의 수신을 통해 애플리케이션으로 트래픽을 라우팅했습니다.