게이트웨이 API
게이트웨이 API (Gateway API)
Gateway API는 Kubernetes에서 네트워킹을 구성하는 리소스 집합으로, Ingress를 확장해 HTTP/HTTPS 외에 TCP, UDP, TLS 라우트와 Service 외 백엔드까지 지원해요. 이 문서에서는 Kong Ingress Controller 환경에서 Gateway 리소스를 관리하는 방법과 리스너 구성, 여러 Gateway를 다루는 방식을 설명해요. Kong은 Gateway의 Deployment나 Service 프로비저닝을 자동으로 처리하지 않기 때문에 리스너와 주소 설정에 맞춰 직접 구성해야 한다는 점이 핵심이에요. 관리되지 않는 Gateway 사용법과 FAQ까지 다루니 Gateway API를 처음 설정할 때 참고하기 좋아요
출처: 문서
본문
Gateway API는 Kubernetes에서 네트워킹을 구성하기 위한 리소스 모음이에요. Ingress를 확장해서 HTTP/HTTPS 외에 TCP, UDP, TLS 같은 추가 라우트 유형을 구성하고, Service 외의 백엔드도 지원하며, 라우트를 구현하는 프록시를 관리할 수 있게 해줘요.
Kong Ingress Controller가 시작되기 전에 클러스터에 Gateway API CRD가 설치되어 있어야만 Gateway API 리소스가 조정(reconcile)돼요. 설치 방법은 시작하기 페이지를 참고하세요.
Gateway 관리
Gateway 리소스는 Gateway API 라우팅 규칙을 처리하면서, 제공된 규칙에 따라 인바운드 트래픽을 Service로 보내는 애플리케이션 또는 클러스터 기능을 설명해요. Kong의 구현에서는 Gateway가 Ingress 컨트롤러가 관리하는 Kong Deployment에 해당해요.
일반적으로 Gateway API 구현체는 사용자를 대신해 Gateway와 연관된 리소스를 관리해요. Gateway 리소스를 만들면 Gateway의 리스너와 주소에 맞게 구성된 Deployment, Service 등이 자동으로 프로비저닝되거든요. 하지만 Kong의 구현은 Gateway 프로비저닝을 자동으로 관리하지 않아요.
Kong Deployment와 그 구성이 자동으로 관리되지 않기 때문에, 리스너와 주소 구성도 대신 지정되지 않아요. Gateway 구성에 맞게 Deployment와 Service를 직접 구성해야 해요.
예를 들어 다음과 같은 Gateway가 있다고 해볼게요:
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example
spec:
gatewayClassName: kong
listeners:
- name: proxy
port: 80
protocol: HTTP
- name: proxy-ssl
port: 443
protocol: HTTPS
hostname: kong.example.com
tls:
mode: Terminate
certificateRefs:
- kind: Secret
name: kong-example-com-cert
- name: proxy-tcp-9901
port: 9901
protocol: TCP
- name: proxy-udp-9902
port: 9902
protocol: UDP
- name: proxy-tls-9903
port: 9903
protocol: TLS
이 Gateway에는 요청된 모든 리스너 포트를 포함하는 프록시 Service가 필요해요:
apiVersion: v1
kind: Service
metadata:
name: proxy
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8000
- port: 443
protocol: TCP
targetPort: 8443
- port: 9901
protocol: TCP
targetPort: 9901
- port: 9902
protocol: UDP
targetPort: 9902
- port: 9903
protocol: TCP
targetPort: 9903
또한 컨테이너 환경에서 Kong Gateway의 proxy_listen과 stream_listen 구성 파라미터도 설정해야 해요:
KONG_PROXY_LISTEN="0.0.0.0:8000 reuseport backlog=16384, 0.0.0.0:8443 http2 ssl reuseport backlog=16384 http2"
KONG_STREAM_LISTEN="0.0.0.0:9901 reuseport backlog=16384, 0.0.0.0:9902 reuseport backlog=16384 udp", 0.0.0.0:9903 reuseport backlog=16384 ssl"
Service, proxy_listen, stream_listen 구성은 proxy 구성 블록을 사용해 Helm 차트를 통해 관리해요.
proxy:
http:
enabled: true
servicePort: 80
containerPort: 8000
tls:
enabled: true
servicePort: 443
containerPort: 8443
stream:
- containerPort: 9901
servicePort: 9901
protocol: TCP
- containerPort: 9902
servicePort: 9902
protocol: UDP
- containerPort: 9903
servicePort: 9903
protocol: TCP
parameters:
- "ssl"
Kong 쪽에 적절한 구성이 없는 포트가 있으면 Gateway 상태에 오류 조건이 표시돼요.
message: no Kong listen with the requested protocol is configured for the requested port
reason: PortUnavailable
리스너 호환성과 여러 Gateway 처리
각 Kong Ingress Controller에는 컨트롤러 이름을 지정할 수 있어요. --gateway-api-controller-name 필드(또는 CONTROLLER_GATEWAY_API_CONTROLLER_NAME 환경 변수)로 컨트롤러 이름을 지정하지 않으면 기본값인 konghq.com/kic-gateway-controller가 사용돼요.
controllerName 필드에서 이런 컨트롤러를 참조하는 모든 GatewayClass는 Kong Ingress Controller가 조정해요. 마찬가지로, 일치하는 controllerName을 지정하는 GatewayClass를 참조하는 모든 Gateway도 조정돼요.
Kong Gateway를 Gateway 리소스에 바인딩하기
Kong Ingress Controller가 Gateway 리소스를 조정하도록 구성하려면 다음을 해야 해요:
- GatewayClass 리소스에
konghq.com/gatewayclass-unmanaged=true어노테이션을 설정하세요. - 리스너 호환성 섹션에서 설명한 대로 GatewayClass에
spec.controllerName을 구성하세요. - Gateway 리소스의
spec.gatewayClassName값이GatewayClass의metadata.name값과 일치하는지 확인하세요.
연관된 주소 목록을 확인하면 Kong Ingress Controller가 Gateway를 업데이트했는지 알 수 있어요.
kubectl get gateway kong -o=jsonpath='{.status.addresses}' | jq
IP 주소가 표시되면 Gateway가 Kong에 의해 관리되고 있다는 뜻이에요:
[
{
"type": "IPAddress",
"value": "10.96.179.122"
},
{
"type": "IPAddress",
"value": "172.18.0.240"
}
]
관리되지 않는(Unmanaged) Gateway
Kong Operator 없이 Kong Ingress Controller를 사용하면, 같은 spec.controllerName을 가진 GatewayClass 리소스에 연관된 모든 Gateway 리소스가 하나의 구성으로 병합돼요. Kong Gateway 배포는 Kong Ingress Controller 외부에서 생성되기 때문에, Gateway 리스너에 맞춰 구성을 동적으로 제어할 수 없어요.
unmanaged 모드를 사용하면 모든 Gateway 인스턴스의 라우트가 하나로 병합되어, 단일 Kong Ingress Controller가 관리하는 모든 Kong Gateway 인스턴스로 전달돼요.
FAQ
-
오류:
One of publish services defined in Gateway's "konghq.com/publish-service" annotation didn't match controller manager's configuration이 오류를 해결하려면 Gateway의
konghq.com/publish-service어노테이션을--publish-service값으로 직접 변경하세요.unmanaged Gateway가 KIC에 의해 조정될 때는,
--publish-service(필요에 따라--publish-service-udp) CLI 플래그에 설정된 Service의 네임스페이스가 포함된 이름과 같은 값으로konghq.com/publish-service어노테이션이 붙어요. 이 어노테이션 값은 Gateway 컨트롤러가 리스너 상태를 판단하는 데 사용돼요.Gateway의
konghq.com/publish-service어노테이션이 한 번 지정되면 더 이상 Kong Ingress Controller가 자동으로 업데이트하지 않아요. 어노테이션이 지정된 후에--publish-service플래그가 변경되면, Gateway 컨트롤러가 Gateway 리스너의 상태를 판단할 수 없게 돼요. 이때는 CLI 플래그에 맞게 어노테이션을 업데이트하도록 직접 수정해야 해요.
관련 리소스
더 알아보기 (Learn more)
- Gateway API가 확장하는 기반이 되는 Kubernetes Ingress 개념을 먼저 확인해 보세요 — Ingress
- Gateway API CRD 설치를 포함한 Kong Ingress Controller 시작 방법을 안내해요 — getting started
- Gateway 리스너에 맞춰 설정해야 하는 Kong Gateway 프록시 리스닝 파라미터 설명이에요 —
proxy_listen - Kong 리소스 운영과 Gateway 프로비저닝 자동화에 활용할 수 있는 오퍼레이터예요 — Kong Operator