gRPC-Gateway로 Protobuf 정의 사용하기
gRPC-Gateway로 Protobuf 정의 사용하기 (Use a Protobuf definition)
이 문서는 gRPC-Gateway 플러그인이 hello-gateway.proto 같은 Protobuf 정의를 호출하도록 설정하는 방법을 안내해요. decK, Admin API, Konnect API, Kubernetes Ingress Controller, Terraform 등 다양한 도구로 플러그인을 전역 또는 서비스 단위에 구성하는 예시를 하나씩 살펴봐요. 처음부터 끝까지 따라 하는 전체 가이드가 필요하면 gRPC-Gateway how-to 문서를 함께 참고하면 좋아요
출처: 문서
본문
Protobuf 정의 사용하기v2.1+
hello-gateway.proto라는 이름의 Protobuf 정의를 호출하도록 플러그인을 설정해요.
전체 how-to 가이드는 gRPC-Gateway 플러그인을 사용해 HTTP 요청을 gRPC 서비스로 프록시하기를 참고하세요.
사전 준비
- Protobuf 정의를 만들어 두었어요
플러그인 설정하기
전역(Global)
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: grpc-gateway
config:
proto: path/to/hello-gateway.proto
{: data-file="kong.yaml" data-tool="deck" }
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요.
지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
proto: path/to/hello-gateway.proto
plugin: grpc-gateway
" | kubectl apply -f -
Terraform
사전 준비: 개인 액세스 토큰 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway 플러그인을 만들려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_grpc_gateway" "my_grpc_gateway" {
enabled = true
config = {
proto = "path/to/hello-gateway.proto"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
서비스(Service)
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: grpc-gateway
service: serviceName|Id
config:
proto: path/to/hello-gateway.proto
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
serviceName|Id: 플러그인 설정이 대상으로 할 서비스의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
serviceName|Id: 플러그인 설정이 대상으로 할 서비스의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
serviceId: 플러그인 설정이 대상으로 할 서비스의id예요.
지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
proto: path/to/hello-gateway.proto
plugin: grpc-gateway
" | kubectl apply -f -
다음으로, service 리소스에 어노테이션을 붙여 KongPlugin 리소스를 적용해요:
kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
사전 준비: 개인 액세스 토큰 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway 플러그인을 만들려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_grpc_gateway" "my_grpc_gateway" {
enabled = true
config = {
proto = "path/to/hello-gateway.proto"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
라우트(Route)
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: grpc-gateway
route: routeName|Id
config:
proto: path/to/hello-gateway.proto
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
routeName|Id: 플러그인 설정이 대상으로 할 라우트의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
routeName|Id: 플러그인 설정이 대상으로 할 라우트의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
routeId: 플러그인 설정이 대상으로 할 라우트의id예요.
지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
proto: path/to/hello-gateway.proto
plugin: grpc-gateway
" | kubectl apply -f -
다음으로, httproute 또는 ingress 리소스에 어노테이션을 붙여 KongPlugin 리소스를 적용해요:
Gateway API
kubectl annotate -n kong httproute konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress konghq.com/plugins=
Terraform
사전 준비: 개인 액세스 토큰 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway 플러그인을 만들려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_grpc_gateway" "my_grpc_gateway" {
enabled = true
config = {
proto = "path/to/hello-gateway.proto"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
컨슈머(Consumer)
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: grpc-gateway
consumer: consumerName|Id
config:
proto: path/to/hello-gateway.proto
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
consumerName|Id: 플러그인 설정이 대상으로 할 컨슈머의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/consumers/{consumerName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
consumerName|Id: 플러그인 설정이 대상으로 할 컨슈머의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/{consumerId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "grpc-gateway",
"config": {
"proto": "path/to/hello-gateway.proto"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
consumerId: 플러그인 설정이 대상으로 할 컨슈머의id예요.
지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
proto: path/to/hello-gateway.proto
plugin: grpc-gateway
" | kubectl apply -f -
다음으로, KongConsumer 리소스에 어노테이션을 붙여 KongPlugin 리소스를 적용해요:
kubectl annotate -n kong kongconsumer CONSUMER_NAME konghq.com/plugins=
Terraform
사전 준비: 개인 액세스 토큰 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway 플러그인을 만들려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_grpc_gateway" "my_grpc_gateway" {
enabled = true
config = {
proto = "path/to/hello-gateway.proto"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer = {
id = konnect_gateway_consumer.my_consumer.id
}
}
관련 리소스
더 알아보기 (Learn more)
- gRPC-Gateway 플러그인으로 HTTP 요청을 gRPC 서비스에 프록시하는 전체 how-to 가이드 — Use the gRPC-Gateway plugin to proxy HTTP requests to a gRPC service
- decK에서 플러그인 설정을 담는
kong.yaml선언형 구성 파일 시작하기 —kong.yaml - Konnect 제어 평면 구성 API의 리전별 URL과 개인 액세스 토큰 사용법 확인하기 — Konnect Control Planes Config API reference
- gRPC-Gateway와 함께 알아두면 좋은 gRPC-Web 플러그인 살펴보기 — gRPC-Web plugin