이 문서는 게이트웨이 API에서 다음 리소스를 사용하는 예제 애플리케이션을 설정하는 데 도움이 됩니다. 다음 단계가 제공됩니다.
배경
컨테이너용 Application Gateway는 개선된 개인 정보 보호 및 보안을 위해 엔드투엔드 TLS를 지원합니다. 이 디자인에서는 클라이언트와 컨테이너용 Application Gateway 프런트 엔드 간의 트래픽이 암호화되고 컨테이너용 Application Gateway에서 백 엔드 대상으로 프록시된 트래픽이 암호화됩니다. 다음과 같은 예제 시나리오를 참조하세요.
필수 구성 요소
BYO 배포 전략을 따르는 경우 컨테이너용 Application Gateway 리소스 및 ALB 컨트롤러를 설정했는지 확인합니다.
ALB 관리된 배포 전략을 따르는 경우 ALB 컨트롤러를 프로비전하고 ApplicationLoadBalancer 사용자 지정 리소스를 통해 컨테이너용 Application Gateway 리소스를 프로비전했는지 확인합니다.
샘플 HTTPS 애플리케이션 배포 클러스터에 다음 deployment.yaml 파일을 적용하여 TLS/SSL 오프로드를 보여 주는 샘플 웹 애플리케이션을 만듭니다.
kubectl apply -f https://raw.githubusercontent.com/MicrosoftDocs/azure-docs/refs/heads/main/articles/application-gateway/for-containers/examples/https-scenario/end-to-end-tls/deployment.yaml이 명령은 클러스터에 다음을 만듭니다.
-
test-infra라는 네임스페이스 -
https-app네임스페이스에 있는test-infra(이)라는 하나의 서비스 -
https-app네임스페이스에 있는test-infra이라는 하나의 배포 -
https-app-cm네임스페이스에 있는test-infra이라는 하나의 configmap -
contoso.com네임스페이스에 있는test-infra이라는 하나의 비밀 -
contoso.xyz네임스페이스에 있는test-infra이라는 하나의 비밀
-
필수 게이트웨이 API 리소스 배포
게이트웨이 만들기
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: contoso.com EOF
참고
ALB 컨트롤러는 Azure Resource Manager에서 컨테이너용 Application Gateway 리소스를 만들 때 프런트 엔드 리소스 fe-<eight randomly generated characters>에 대해 다음 명명 규칙을 사용합니다.
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: https-app
port: 443
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
BackendTLSPolicy 만들기
kubectl apply -f - <<EOF
apiVersion: alb.networking.azure.io/v1
kind: BackendTLSPolicy
metadata:
name: https-app-tls-policy
namespace: test-infra
spec:
targetRef:
group: ""
kind: Service
name: https-app
namespace: test-infra
default:
sni: contoso.xyz
ports:
- port: 443
EOF
BackendTLSPolicy 개체가 만들어지면 개체의 상태를 확인하여 정책이 유효한지 확인합니다.
kubectl get backendtlspolicy -n test-infra https-app-tls-policy -o yaml
유효한 BackendTLSPolicy 개체 만들기의 출력 예제:
status:
conditions:
- lastTransitionTime: "2023-06-29T16:54:42Z"
message: Valid BackendTLSPolicy
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
애플리케이션에 대한 액세스 테스트
이제 프런트 엔드에 할당된 FQDN을 통해 샘플 애플리케이션에 일부 트래픽을 전송할 준비가 되었습니다. 다음 명령을 사용하여 FQDN을 가져옵니다.
fqdn=$(kubectl get gateway gateway-01 -n test-infra -o jsonpath='{.status.addresses[0].value}')
이 FQDN을 컬링하면 HTTPRoute에 구성된 대로 백 엔드에서 응답을 반환해야 합니다.
fqdnIp=$(dig +short $fqdn)
curl -k --resolve contoso.com:443:$fqdnIp https://contoso.com --insecure
다음 결과가 나타나야 합니다.
Hello world!
축하합니다. ALB 컨트롤러를 설치하고, 백 엔드 애플리케이션을 배포하고, 컨테이너용 Azure Application Gateway의 수신을 통해 애플리케이션으로 트래픽을 라우팅했습니다.