3.3. Kubernetes 게이트웨이 API를 사용하여 게이트웨이를 통해 송신 트래픽 전달
Kubernetes Gateway API를 사용하여 송신 게이트웨이를 통해 아웃바운드 HTTP 트래픽을 전달합니다.
사전 요구 사항
- Istio 컨트롤 플레인을 설치했습니다.
-
Istio및IstioCNI리소스를 구성했습니다.
프로세스
선택 사항: {k8} 게이트웨이 API CRD(사용자 정의 리소스 정의)를 활성화합니다.
참고Kubernetes 1.28 및 OpenShift Container Platform 4.18 또는 이전 버전의 Red Hat OpenShift Service Mesh에서 Kubernetes Gateway API CRD는 기본적으로 사용할 수 없으며 CRD를 활성화하기 전에 CRD를 활성화해야 합니다. OpenShift Container Platform 4.19 이상 버전에서는 기본적으로 CRD를 활성화합니다.
Kubernetes 게이트웨이 API CRD를 활성화하는
gateway-cr.yaml이라는 YAML 파일을 생성합니다.Kubernetes 게이트웨이 CR(사용자 정의 리소스) 파일의 예
apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: info-gateway spec: gatewayClassName: istio listeners: - name: http port: 80 protocol: HTTP allowedRoutes: namespaces: from: Same --- apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: info spec: parentRefs: - name: info-gateway rules: - matches: - path: type: Exact value: /productpage - path: type: PathPrefix value: /static - path: type: Exact value: /login - path: type: Exact value: /logout - path: type: PathPrefix value: /api/v1/products backendRefs: - name: productpage port: 9080다음 명령을 실행하여 YAML 파일을 적용합니다.
$ oc apply -f gateway-cr.yaml
다음 명령을 실행하여
egress-gateway라는 네임스페이스를 생성합니다.$ oc create namespace egress-gateway다음 명령을 실행하여
istio-injection레이블을 네임스페이스에 적용합니다.$ oc label namespace egress-gateway istio-injection=enabled송신 게이트웨이를 정의하는
egress-gateway-cr.yaml이라는 YAML 파일을 만듭니다.송신 게이트웨이 CR 파일의 예
# ServiceEntry to allow traffic to httpbin.org apiVersion: networking.istio.io/v1 kind: ServiceEntry metadata: name: httpbin-ext spec: hosts: - httpbin.org ports: - number: 80 name: http protocol: HTTP location: MESH_EXTERNAL resolution: DNS --- # Gateway API Gateway for egress apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: httpbin-egress-gateway annotations: networking.istio.io/service-type: ClusterIP spec: gatewayClassName: istio listeners: - name: http hostname: httpbin.org port: 80 protocol: HTTP allowedRoutes: namespaces: from: Same --- # HTTPRoute to direct traffic from sidecars to the egress gateway apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: direct-httpbin-to-egress-gateway spec: parentRefs: - kind: ServiceEntry group: networking.istio.io name: httpbin-ext rules: - backendRefs: - name: httpbin-egress-gateway-istio port: 80 --- # HTTPRoute to forward traffic from the egress gateway to httpbin.org apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: forward-httpbin-from-egress-gateway spec: parentRefs: - name: httpbin-egress-gateway hostnames: - httpbin.org rules: - backendRefs: - kind: Hostname group: networking.istio.io name: httpbin.org port: 80다음 명령을 실행하여 YAML 파일을 적용합니다.
$ oc apply -f egress-gateway-cr.yaml
검증
다음 명령을 실행하여 게이트웨이 구성의 상태를 확인합니다.
$ oc describe gateway -n egress-gateway원하는 출력은
Status열에표시된 대로 표시됩니다.다음 명령을 실행하여
egress-gateway네임스페이스에curl포드를 생성합니다.$ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- shcurl클라이언트를 사용하여 다음 명령을 입력하여 송신 게이트웨이를 통해httpbin.org에 액세스할 수 있는지 확인합니다.$ curl -v http://httpbin.org/get원하는 출력에는 구성된 게이트웨이를 통한 송신 트래픽 경로를 나타내는
httpbin.org의 응답이 표시됩니다.