k8s Gateway API

Kubernetes Gateway API는 L4 및 L7 라우팅을 통해 인프라의 트래픽 관리를 혁신합니다.

k8s Gateway API
Photo by Sam Moghadam / Unsplash

개요

Gateway API는 Kubernetes의 L4 및 L7 라우팅에 초점을 맞춘 공식 Kubernetes 프로젝트입니다. 이 프로젝트는 Kubernetes Ingress, Load Balancing 및 Service Mesh API의 차세대를 나타냅니다. 처음부터 일반적이고 표현적이며 역할 지향적으로 설계되었습니다.

전체 모델과 관리해야할 리소스 역할은 다음과 같이 설정됩니다.

Notion Image

대부분의 구성은 라우팅 계층에 포함되어 프로토콜별 리소스( HTTPRoute , GRPCRoute 등)는 Ingress와 Mesh 모두에 대한 고급 라우팅 기능을 활성화합니다.

Gateway API 로고는 이 API의 이중 목적을 설명하는 데 도움이 되며, 북쪽-남쪽(Ingress = 외부 - 내부로 흐르는 트래픽) 및 동쪽-서쪽(Mesh = 클러스터 내부 서비스의 트래픽) 트래픽이 동일한 구성을 공유하도록 라우팅할 수 있습니다.


1. GatewayClass

  • 가장 상위 레벨의 리소스입니다
  • Gateway의 설정과 동작 방식을 정의하는 템플릿 역할을 합니다
  • 클러스터 전체에서 재사용 가능한 설정을 제공합니다
  • 특정 구현체(예: Istio, Contour)가 어떻게 Gateway를 처리할지 정의합니다
  • Kubernetes의 StorageClass와 유사한 개념입니다
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: example-gatewayclass
spec:
  controllerName: example.com/gateway-controller
  parametersRef:
    group: example.com
    kind: Config
    name: example-config
    namespace: default
  description: "Example GatewayClass for demonstration"

2. Gateway

  • GatewayClass의 구체적인 인스턴스입니다
  • 실제로 트래픽을 수신하는 인프라를 나타냅니다
  • 리스너(Listener)를 통해 특정 포트와 프로토콜을 정의합니다
  • TLS 설정, IP 주소 할당 등의 네트워크 설정을 포함합니다
  • 하나의 Gateway는 여러 Route 리소스에 의해 참조될 수 있습니다.

실제 로드밸런서의 역할을 정의합니다.

리스너(포트, 프로토콜) 등 게이트웨이 자체 설정을 작성합니다.

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: example-gateway
  namespace: default
spec:
  gatewayClassName: example-gatewayclass
  listeners:
    - name: http
      protocol: HTTP
      port: 80
      allowedRoutes:
        namespaces:
          from: All
    - name: https
      protocol: HTTPS
      port: 443
      tls:
        mode: Terminate
        certificateRefs:
        - name: example-cert
          kind: Secret
      allowedRoutes:
        namespaces:
          from: Sam

3. Route 리소스들 각각의 Route 타입은 특정 프로토콜에 특화되어 있습니다

HTTPRoute:

  • HTTP/HTTPS 트래픽을 처리합니다
  • URL 경로 기반 라우팅을 지원합니다
  • 헤더 기반 라우팅이 가능합니다
  • 요청/응답 수정이 가능합니다

라우팅 규칙을 정의합니다.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: example-httproute
  namespace: default
spec:
  parentRefs:
    - name: example-gateway
  hostnames:
    - "example.com"
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api
        - headers:
            - name: version
              value: "v2"
      backendRefs:
        - name: api-service
          port: 8080
          weight: 90
    - matches:
        - path:
            type: Exact
            value: /status
      backendRefs:
        - name: status-service
          port: 8081
          weight: 10
      filters:
        - type: RequestHeaderModifier
          requestHeaderModifier:
            add:
              - name: x-route-type
                value: status

리스너 규칙과 대상 그룹을 모두 포함하는 개념으로 경로 기반 호스트 기반 라우팅을 정의하며 트래픽을 전달할 백엔드도 구성합니다.

TCPRoute:

  • TCP 트래픽을 처리합니다
  • 포트 기반 라우팅을 지원합니다

GRPCRoute:

  • gRPC 트래픽에 특화되어 있습니다
  • 서비스/메소드 기반 라우팅이 가능합니다

TLSRoute:

  • TLS 트래픽을 처리합니다
  • SNI(Server Name Indication) 기반 라우팅을 지원합니다

UDPRoute:

  • UDP 트래픽을 처리합니다

계층 구조:

GatewayClass
    └── Gateway
        └── Routes (HTTP/TCP/gRPC/TLS/UDP)
            └── Rules
                └── Backends (Services)

주요 특징:

  • 모듈화된 설계: 각 리소스는 명확한 책임을 가집니다
  • 확장성: 새로운 Route 타입을 쉽게 추가할 수 있습니다
  • 재사용성: 동일한 Gateway를 여러 Route에서 공유할 수 있습니다
  • 유연성: 다양한 구현체(implementers)를 지원합니다