k8s Gateway API

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

개요

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

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

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

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

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:

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

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:

GRPCRoute:

TLSRoute:

UDPRoute:

계층 구조:

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

주요 특징: