인증된 호출자를 기준으로 다른 업스트림에 요청 라우팅
인증된 호출자를 기준으로 다른 업스트림에 요청 라우팅 (Datakit)
이 문서는 OpenID Connect 플러그인이 검증한 토큰에서 추출한 자격증명을 기준으로 요청을 서로 다른 Upstream으로 보내는 Datakit 예제를 설명해요. GET_CREDENTIAL, PICK_UPSTREAM, SET_UPSTREAM 세 개 노드가 자격증명을 읽고, 매핑으로 업스트림을 골라, 요청별 백엔드를 동적으로 바꾸는 흐름을 소개해요. decK와 Admin API를 이용한 플러그인 설정 방법도 함께 안내해요
출처: 문서
본문
인증된 호출자를 기준으로 다른 업스트림으로 요청 라우팅 v3.14+
인증된 자격 증명을 이름이 지정된 Upstream 엔티티에 매핑하고 요청별로 백엔드를 재정의해요.
이 예제는 OpenID Connect 플러그인과 함께 작동해요. 이 플러그인은 베어러 토큰을 검증하고 토큰 클레임(예: client_id)을 가상 자격 증명으로 추출해요.
그런 다음 Datakit이 그 자격 증명을 읽고 그 값을 사용해 업스트림을 선택해요.
이 예제에는 다음 노드들이 포함되어 있어요:
GET_CREDENTIAL은 OpenID Connect 플러그인이 채워 넣은kong.client.credential객체를 읽어요.PICK_UPSTREAM은 jq 맵을 사용해 자격 증명의.id필드를 조회하고 일치하는 업스트림 이름을 반환해요. 알 수 없는 호출자는upstream-default로 넘어가요.SET_UPSTREAM은 결정된 업스트림 이름을kong.service.upstream에 기록해서 이 요청의 백엔드를 재정의해요.
전체 튜토리얼은 인증된 호출자를 기준으로 다른 업스트림으로 요청 라우팅을 참고하세요.
참고: OpenID Connect 플러그인은 Datakit보다 정적 우선순위가 높아서
access단계에서 항상 먼저 실행돼요. 별도의 플러그인 순서 설정은 필요하지 않아요.
사전 준비
-
credential_claim이 토큰 클레임(예:client_id)을 가리키고consumer_optional: true로 설정된 OpenID Connect 플러그인을 구성했어요. -
각 호출자를 위한 이름이 지정된 Upstream 엔티티와 폴백 업스트림을 만들었어요.
플러그인 설정하기
전역
decK
다음 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
config:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:
-
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:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
'caller-a': 'upstream-a',
'caller-b': 'upstream-b'
}[.id] // 'upstream-default'
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
plugin: datakit
" | 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 Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:
resource "konnect_gateway_plugin_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "GET_CREDENTIAL"
type = "property"
property = "kong.client.credential"
},
{
name = "PICK_UPSTREAM"
type = "jq"
input = "GET_CREDENTIAL"
jq = <<EOF
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
EOF
},
{
name = "SET_UPSTREAM"
type = "property"
property = "kong.service.upstream"
input = "PICK_UPSTREAM"
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
서비스
decK
다음 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
service: serviceName|Id
config:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:
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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:
-
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:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
'caller-a': 'upstream-a',
'caller-b': 'upstream-b'
}[.id] // 'upstream-default'
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
plugin: datakit
" | 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 Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:
resource "konnect_gateway_plugin_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "GET_CREDENTIAL"
type = "property"
property = "kong.client.credential"
},
{
name = "PICK_UPSTREAM"
type = "jq"
input = "GET_CREDENTIAL"
jq = <<EOF
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
EOF
},
{
name = "SET_UPSTREAM"
type = "property"
property = "kong.service.upstream"
input = "PICK_UPSTREAM"
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
라우트
decK
다음 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
route: routeName|Id
config:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
-
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:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
'caller-a': 'upstream-a',
'caller-b': 'upstream-b'
}[.id] // 'upstream-default'
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
plugin: datakit
" | 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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "GET_CREDENTIAL"
type = "property"
property = "kong.client.credential"
},
{
name = "PICK_UPSTREAM"
type = "jq"
input = "GET_CREDENTIAL"
jq = <<EOF
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
EOF
},
{
name = "SET_UPSTREAM"
type = "property"
property = "kong.service.upstream"
input = "PICK_UPSTREAM"
} ]
}
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: datakit
consumer: consumerName|Id
config:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
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": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
-
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:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
'caller-a': 'upstream-a',
'caller-b': 'upstream-b'
}[.id] // 'upstream-default'
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
plugin: datakit
" | 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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "GET_CREDENTIAL"
type = "property"
property = "kong.client.credential"
},
{
name = "PICK_UPSTREAM"
type = "jq"
input = "GET_CREDENTIAL"
jq = <<EOF
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
EOF
},
{
name = "SET_UPSTREAM"
type = "property"
property = "kong.service.upstream"
input = "PICK_UPSTREAM"
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer = {
id = konnect_gateway_consumer.my_consumer.id
}
}
Consumer Group
decK
이 섹션을 여러분의 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
consumer_group: consumerGroupName|Id
config:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
consumerGroupName|Id: 플러그인 구성이 대상으로 지정할 컨슈머 그룹의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/consumer_groups/{consumerGroupName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
consumerGroupName|Id: 플러그인 구성이 대상으로 지정할 컨슈머 그룹의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumer_groups/{consumerGroupId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "GET_CREDENTIAL",
"type": "property",
"property": "kong.client.credential"
},
{
"name": "PICK_UPSTREAM",
"type": "jq",
"input": "GET_CREDENTIAL",
"jq": "{\n \"caller-a\": \"upstream-a\",\n \"caller-b\": \"upstream-b\"\n}[.id] // \"upstream-default\"\n"
},
{
"name": "SET_UPSTREAM",
"type": "property",
"property": "kong.service.upstream",
"input": "PICK_UPSTREAM"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
-
region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
consumerGroupId: 플러그인 구성이 대상으로 삼을 컨슈머 그룹의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:
nodes:
- name: GET_CREDENTIAL
type: property
property: kong.client.credential
- name: PICK_UPSTREAM
type: jq
input: GET_CREDENTIAL
jq: |
{
'caller-a': 'upstream-a',
'caller-b': 'upstream-b'
}[.id] // 'upstream-default'
- name: SET_UPSTREAM
type: property
property: kong.service.upstream
input: PICK_UPSTREAM
plugin: datakit
" | kubectl apply -f -
다음으로, KongConsumerGroup 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용해요:
kubectl annotate -n kong kongconsumergroup CONSUMERGROUP_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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "GET_CREDENTIAL"
type = "property"
property = "kong.client.credential"
},
{
name = "PICK_UPSTREAM"
type = "jq"
input = "GET_CREDENTIAL"
jq = <<EOF
{
"caller-a": "upstream-a",
"caller-b": "upstream-b"
}[.id] // "upstream-default"
EOF
},
{
name = "SET_UPSTREAM"
type = "property"
property = "kong.service.upstream"
input = "PICK_UPSTREAM"
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer_group = {
id = konnect_gateway_consumer_group.my_consumer_group.id
}
}
관련 리소스
더 알아보기 (Learn more)
- 이 예제의 전체 튜토리얼을 단계별로 따라 할 수 있어요 — Route requests to different upstreams based on the authenticated caller
- Datakit의 기본 개념과 동작 방식을 먼저 훑어보고 싶을 때 참고해요 — Datakit overview
- Datakit을 처음 시작하는 분을 위한 입문 가이드예요 — Get started with Datakit
- 자격증명을 추출하는 OpenID Connect 플러그인의 설정 방법을 확인해요 — OpenID Connect plugin
- 라우팅 대상이 되는 Upstream 엔티티의 구성을 살펴봐요 — Upstream
- 설정이 의도대로 동작하는지 Datakit Debugger로 확인해요 — Using Debugger for Datakit