2.6. 앰비언트 모드에서 Kubernetes 게이트웨이 API를 사용하여 서비스 노출


Kubernetes Gateway API를 사용하여 게이트웨이 및 HTTPRoute 리소스를 생성하고 앰비언트 모드로 게이트웨이를 배포할 수 있습니다. 리소스는 메시의 서비스를 메시 외부의 트래픽에 노출하도록 게이트웨이를 구성합니다.

사전 요구 사항

  • cluster-admin 역할의 사용자로 OpenShift Container Platform 웹 콘솔에 로그인되어 있습니다.
  • Red Hat OpenShift Service Mesh Operator가 설치되어 있습니다.
  • Istio 리소스를 배포했습니다.
  • Kubernetes 네이티브 게이트웨이 API 리소스를 사용합니다.
  • Istio 앰비언트 모드를 사용하거나 앰비언트 모드로 마이그레이션할 계획입니다.
참고

앰비언트 모드(istio.io/dataplane-mode=앰비언트)를 사용하는 경우 Istio 게이트웨이 및 VirtualService 리소스가 앰비언트 모드와 완전히 호환되지 않으므로 수신 구성에 Kubernetes 게이트웨이 API를 사용하는 것이 좋습니다.

프로세스

  1. 다음 명령을 실행하여 httpbin 이라는 네임스페이스를 생성합니다.

    $ oc create namespace httpbin
    Copy to Clipboard Toggle word wrap
  2. 다음 명령을 실행하여 앰비언트 모드의 레이블을 적용합니다.

    $ oc label namespace httpbin istio.io/dataplane-mode=ambient
    Copy to Clipboard Toggle word wrap
  3. 다음 명령을 실행하여 httpbin 이라는 샘플 서비스를 배포합니다.

    $ oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
    Copy to Clipboard Toggle word wrap
  4. 다음 예와 유사하게 httpbin-waypoint.yaml 이라는 YAML 파일을 생성하여 waypoint 프록시를 배포합니다.

    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: httpbin-waypoint
      namespace: httpbin
      labels:
        istio.io/waypoint-for: service
    spec:
      gatewayClassName: istio-waypoint
      listeners:
      - name: mesh
        port: 15008
        protocol: HBONE
    Copy to Clipboard Toggle word wrap
  5. 다음 명령을 실행하여 YAML 파일을 적용합니다.

    $ oc apply -f httpbin-waypoint.yaml
    Copy to Clipboard Toggle word wrap
  6. 다음 명령을 실행하여 httpbin 서비스에서 ingress waypoint 라우팅을 활성화합니다.

    $ oc label service httpbin -n httpbin istio.io/ingress-use-waypoint=true
    Copy to Clipboard Toggle word wrap

    레이블은 httpbin 서비스에 도달하기 전에 Ingress 게이트웨이의 트래픽이 waypoint 프록시에 구성된 waypoint 프록시에 구성된 L7 정책이 수신 트래픽에 적용되는지 확인합니다.

  7. 다음 명령을 실행하여 네임스페이스 내부의 모든 서비스가 길 포인트를 통과하도록 네임스페이스에 waypoint 레이블을 적용합니다.

    $ oc label ns httpbin istio.io/use-waypoint=httpbin-waypoint
    Copy to Clipboard Toggle word wrap
  8. Kubernetes Gateway 리소스를 정의하는 httpbin-gw.yaml 이라는 YAML 파일을 생성합니다. 이 리소스는 호스트 httpbin.example.com 의 포트 80(HTTP)을 노출하도록 게이트웨이 프록시를 구성합니다.

    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: httpbin-gateway
      namespace: httpbin
    spec:
      gatewayClassName: istio
      listeners:
      - name: default
        hostname: "httpbin.example.com"
        port: 80
        protocol: HTTP
        allowedRoutes:
          namespaces:
            from: All
    Copy to Clipboard Toggle word wrap
    "httpbin.example.com"
    클라이언트가 연결된 포트에서 메시 서비스에 액세스하려고 할 때 사용하는 가상 호스트 이름을 지정합니다.
  9. 다음 명령을 실행하여 YAML 파일을 적용합니다.

    $ oc apply -f httpbin-gw.yaml
    Copy to Clipboard Toggle word wrap
  10. 다음 예와 유사하게 수신 게이트웨이에 대한 HTTPRoute 리소스를 정의하는 httpbin-ingress-hr.yaml 이라는 YAML 파일을 만듭니다.

    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-ingress
      namespace: httpbin
    spec:
      parentRefs:
      - name: httpbin-gateway
        namespace: httpbin
      hostnames:
      - "httpbin.example.com"
      rules:
      - backendRefs:
        - name: httpbin
          port: 8000
    Copy to Clipboard Toggle word wrap
    • spec.parentRefsHTTPROUTE 리소스를 이전 단계에서 생성한 Kubernetes 게이트웨이 리소스에 바인딩합니다.
    • spec.rules.backendRefshttpbin 서비스의 이름과 포트를 포함하는 backendRefs 를 정의하여 일치하는 트래픽을 httpbin 서비스로 라우팅합니다.

    HTTPRoute 리소스는 게이트웨이 프록시에서 httpbin 서비스로 트래픽을 라우팅하는 규칙을 지정합니다.

  11. 다음 명령을 실행하여 YAML 파일을 적용합니다.

    $ oc apply -f httpbin-ingress-hr.yaml
    Copy to Clipboard Toggle word wrap
  12. waypoint 프록시에 대해 HTTPRoute 리소스를 정의하는 httpbin-waypoint-hr.yaml 이라는 YAML 파일을 생성합니다.

    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-waypoint-route
      namespace: httpbin
    spec:
      parentRefs:
      - name: httpbin-waypoint
        namespace: httpbin
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /status
        - path:
            type: PathPrefix
            value: /headers
        backendRefs:
        - name: httpbin
          port: 8000
    Copy to Clipboard Toggle word wrap
    • spec.parentRefsHTTPROUTE 리소스를 waypoint Gateway 리소스에 바인딩합니다. waypoint가 적용할 L7 라우팅 규칙을 구성합니다.
    • spec.rules.backendRefshttpbin 서비스의 이름과 포트를 포함하는 backendRefs 를 정의하여 일치하는 트래픽을 httpbin 서비스로 라우팅합니다.
  13. 다음 명령을 실행하여 YAML 파일을 적용합니다.

    $ oc apply -f httpbin-waypoint-hr.yaml
    Copy to Clipboard Toggle word wrap
참고

이 예제 사용 사례에서 istio.io/ingress-use-waypoint=true 레이블 때문에 수신 게이트웨이의 트래픽이 waypoint 프록시를 통해 이동합니다. 그런 다음 HTTPRoute 리소스는 트래픽이 httpbin 서비스에 도달하기 전에 경로 기반 라우팅 정책을 적용합니다.

  1. 다음 명령을 실행하여 waypoint 프록시가 준비되었는지 확인합니다.

    $ oc wait --for=condition=programmed gtw httpbin-waypoint -n httpbin
    Copy to Clipboard Toggle word wrap

검증

  1. 다음 명령을 실행하여 curl 클라이언트의 네임스페이스를 생성합니다.

    $ oc create namespace curl
    Copy to Clipboard Toggle word wrap
  2. 다음 명령을 실행하여 curl 클라이언트를 배포합니다.

    $ oc apply -n curl
    Copy to Clipboard Toggle word wrap
  3. 다음 명령을 실행하여 앰비언트 모드의 레이블을 curl 네임스페이스에 적용합니다.

    $ oc label namespace curl istio.io/dataplane-mode=ambient
    Copy to Clipboard Toggle word wrap
  4. 다음 명령을 실행하여 CURL_POD 변수를 curl 포드의 이름으로 설정합니다.

    $ CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')
    Copy to Clipboard Toggle word wrap
  5. curl 클라이언트를 사용하여 수신 게이트웨이 서비스 리소스를 통해 httpbin 애플리케이션의 /headers 엔드포인트로 요청을 보냅니다. 요청의 Host 헤더를 httpbin.example.com 으로 설정하여 Kubernetes Gateway 및 HTTPROUTE 리소스가 지정하는 호스트와 일치시킵니다. 다음 명령을 실행하여 curl 요청을 보냅니다.

    $ oc exec $CURL_POD -n curl -- \
      curl -s -I \
        -H Host:httpbin.example.com \
        <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/headers
    Copy to Clipboard Toggle word wrap

    응답은 다음 예제와 유사하게 요청이 성공했음을 나타내는 200 OK HTTP 상태를 반환해야 합니다.

    HTTP/1.1 200 OK
    server: istio-envoy
    ...
    Copy to Clipboard Toggle word wrap
  6. 다음 명령을 실행하여 httpbin HTTPROUTE 에 정의된 해당 URI(Uniform Resource Identifier) 접두사 일치가 없는 엔드포인트에 curl 요청을 보냅니다.

    $ oc exec $CURL_POD -n curl -- \
      curl -s -I \
        -H Host:httpbin.example.com \
        <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/get
    Copy to Clipboard Toggle word wrap

    /get 끝점에 다음 예와 유사하게 httpbin HTTPROUTE 리소스에 일치하는 URI 접두사가 없기 때문에 응답에서 404 Not Found 상태를 예상대로 반환합니다.

    HTTP/1.1 404 Not Found
    server: istio-envoy
    ...
    Copy to Clipboard Toggle word wrap
  7. 서비스 유형을 LoadBalancer 로 설정하여 클러스터 외부의 트래픽에 게이트웨이 프록시를 노출합니다. 다음 명령을 실행합니다.

    $ oc patch service <gateway_name>-istio -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'
    Copy to Clipboard Toggle word wrap
    참고

    게이트웨이는 OpenShift 경로를 사용하여 클러스터 외부의 트래픽에도 노출될 수 있습니다. 자세한 내용은 "OpenShift 경로를 사용하여 클러스터 외부의 트래픽에 게이트웨이 추가"를 참조하십시오.

  8. 게이트웨이 서비스 리소스의 외부 호스트 이름 또는 IP 주소를 사용할 때 클러스터 외부에서 httpbin 서비스에 액세스할 수 있는지 확인합니다. 클러스터가 실행 중인 환경에 대해 INGRESS_HOST 변수를 적절하게 설정해야 합니다.

    1. 다음 명령을 실행하여 INGRESS_HOST 변수를 설정합니다.

      $ export INGRESS_HOST=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.addresses[0].value}')
      Copy to Clipboard Toggle word wrap
    2. 다음 명령을 실행하여 INGRESS_PORT 변수를 설정합니다.

      $ INGRESS_PORT=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')
      Copy to Clipboard Toggle word wrap
    3. 게이트웨이 호스트를 사용하여 다음 명령을 실행하여 curl 요청을 httpbin 서비스에 보냅니다.

      $ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/headers
      Copy to Clipboard Toggle word wrap
  9. 응답에 HTTP/1.1 200 OK 상태가 있는지 확인합니다. 이 상태는 요청이 성공했음을 나타냅니다.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat