3.2. Istio API를 사용하여 게이트웨이를 통해 송신 트래픽 전달
Istio API를 사용하여 게이트웨이 삽입을 사용하여 설치된 게이트웨이를 통해 아웃바운드 HTTP 트래픽을 전달합니다.
사전 요구 사항
- 게이트웨이 삽입을 사용하여 게이트웨이를 설치했습니다.
프로세스
다음 명령을 실행하여
curl이라는 네임스페이스를 생성합니다.$ oc create namespace curl사용 중인 업데이트 전략에 따라 적절한 명령을 실행하여 네임스페이스에서 사이드카 삽입을 활성화합니다.
InPlace업데이트 전략을 사용하는 경우 다음 명령을 실행합니다.$ oc label namespace curl istio-injection=enabledRevisionBased업데이트 전략을 사용하는 경우 다음 명령을 실행합니다.다음 명령을 실행하여 버전 이름을 표시합니다.
$ oc get istiorevisions.sailoperator.io출력 예
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33s다음 명령을 실행하여 버전 이름으로 네임스페이스에 라벨을 지정하여 사이드카 삽입을 활성화합니다.
$ oc label namespace curl istio.io/rev=default
다음 명령을 실행하여
curl애플리케이션을 배포합니다.$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yamlcurl 포드 이름으로 초기화된
CURL_POD환경 변수를 내보냅니다.$ export CURL_POD=$(oc get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')메시의 트래픽을 외부 서비스로 보내는
http-se.yaml이라는 YAML 파일을 생성합니다. 다음 예제에서는 URL에 대한ServiceEntry를 정의합니다.설정 예
apiVersion: networking.istio.io/v1 kind: ServiceEntry metadata: name: egress-se namespace: curl spec: hosts: - docs.redhat.com ports: - number: 80 name: http-port protocol: HTTP location: MESH_EXTERNAL resolution: DNS다음 명령을 실행하여 YAML 파일을 적용합니다.
$ oc apply -f http-se.yamlServiceEntry구성이 올바르게 적용되었는지 확인합니다. 다음 명령을 실행하여 이전 단계에서 지정한 호스트에 HTTP 요청을 보냅니다.$ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com이 명령은 연결이 작동함을 나타내는
301(redirect) 또는200(성공)과 같은 HTTP 상태 코드를 반환해야 합니다.송신
게이트웨이를 생성하고 메시에서 외부 서비스에 지정된 호스트로 트래픽을 라우팅하는http-gtw.yaml이라는 YAML 파일을 생성합니다.설정 예
apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: egress-gw namespace: <gateway_namespace> # Namespace where the egress gateway is deployed spec: selector: istio: <gateway_name> # Selects the egress-gateway instance to handle this traffic servers: - port: number: 80 name: http protocol: HTTP hosts: - docs.redhat.com # External service host, not a full URL. --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: egress-dr namespace: <gateway_namespace> # Namespace where the egress gateway is deployed spec: host: <gateway_name>.<gateway_namespace>.svc.cluster.local subsets: - name: rh-docs다음 명령을 실행하여 YAML 파일을 적용합니다.
$ oc apply -f http-gtw.yaml송신 게이트웨이를 통해 외부 호스트로 애플리케이션 사이드카의 트래픽 흐름을 관리하기 위해
VirtualService를 설정하는http-vs.yaml이라는 YAML 파일을 생성합니다.설정 예
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: egress-vs namespace: curl # Namespace where the curl pod is running spec: hosts: - docs.redhat.com # External service host, not a full URL. gateways: - mesh - <gateway_namespace>/egress-gw # Egress gateway name defined in the file that you used in the previous step. http: - match: - gateways: - mesh port: 80 route: - destination: host: <gateway_name>.<gateway_namespace>.svc.cluster.local subset: rh-docs port: number: 80 weight: 100 - match: - gateways: - <gateway_namespace>/egress-gw # Egress gateway name defined in the file that you used in the previous step. port: 80 route: - destination: host: docs.redhat.com port: number: 80 weight: 100다음 명령을 실행하여 YAML 파일을 적용합니다.
$ oc apply -f http-vs.yamlHTTP 요청을 URL에 다시 보냅니다.
$ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com터미널에 다음 출력과 유사한 정보가 표시되어야 합니다.
출력 예
... HTTP/1.1 301 Moved Permanently ... location: <example_url> ... HTTP/2 200 Content-Type: text/html; charset=utf-8다음 명령을 실행하여 요청을 게이트웨이를 통해 라우팅되었는지 확인합니다.
$ oc logs deployment/<gateway_name> -n <gateway_namespace> | tail -1참고이 확인 단계가 작동하려면 액세스 로깅을 활성화해야 합니다.
spec.values.meshConfig.accessLogFile필드를 Istio 리소스의/dev/stdout으로 설정하여 표준 출력에 대한 액세스 로깅을 활성화할 수 있습니다.터미널에 다음 출력과 유사한 정보가 표시되어야 합니다.
출력 예
[2024-11-07T14:35:52.428Z] "GET / HTTP/2" 301 - via_upstream - "-" 0 0 24 24 "10.128.2.30" "curl/8.11.0" "79551af2-341b-456d-b414-9220b487a03b" "docs.redhat.com" "23.55.176.201:80" outbound|80||docs.redhat.com 10.128.2.29:49766 10.128.2.29:80 10.128.2.30:38296 -