3.3. Kubernetes 게이트웨이 API를 사용하여 게이트웨이를 통해 송신 트래픽 전달


Kubernetes Gateway API를 사용하여 송신 게이트웨이를 통해 아웃바운드 HTTP 트래픽을 전달합니다.

사전 요구 사항

  • Istio 컨트롤 플레인을 설치했습니다.
  • IstioIstioCNI 리소스를 구성했습니다.

프로세스

  1. 선택 사항: {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를 활성화합니다.

    1. 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
      Copy to Clipboard Toggle word wrap

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

      $ oc apply -f gateway-cr.yaml
      Copy to Clipboard Toggle word wrap
  2. 다음 명령을 실행하여 egress-gateway 라는 네임스페이스를 생성합니다.

    $ oc create namespace egress-gateway
    Copy to Clipboard Toggle word wrap
  3. 다음 명령을 실행하여 istio-injection 레이블을 네임스페이스에 적용합니다.

    $ oc label namespace egress-gateway istio-injection=enabled
    Copy to Clipboard Toggle word wrap
  4. 송신 게이트웨이를 정의하는 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
    Copy to Clipboard Toggle word wrap

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

      $ oc apply -f egress-gateway-cr.yaml
      Copy to Clipboard Toggle word wrap

검증

  1. 다음 명령을 실행하여 게이트웨이 구성의 상태를 확인합니다.

    $ oc describe gateway -n egress-gateway
    Copy to Clipboard Toggle word wrap

    원하는 출력은 Status 열에 표시된 대로 표시됩니다.

  2. 다음 명령을 실행하여 egress-gateway 네임스페이스에 curl 포드를 생성합니다.

    $ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- sh
    Copy to Clipboard Toggle word wrap
  3. curl 클라이언트를 사용하여 다음 명령을 입력하여 송신 게이트웨이를 통해 httpbin.org 에 액세스할 수 있는지 확인합니다.

    $ curl -v http://httpbin.org/get
    Copy to Clipboard Toggle word wrap

    원하는 출력에는 구성된 게이트웨이를 통한 송신 트래픽 경로를 나타내는 httpbin.org 의 응답이 표시됩니다.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

Theme

© 2025 Red Hat