본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

인증된 호출자를 기준으로 다른 업스트림에 요청 라우팅

원문 보기 위키 갱신

인증된 호출자를 기준으로 다른 업스트림에 요청 라우팅 (Datakit)

이 문서는 OpenID Connect 플러그인이 검증한 토큰에서 추출한 자격증명을 기준으로 요청을 서로 다른 Upstream으로 보내는 Datakit 예제를 설명해요. GET_CREDENTIAL, PICK_UPSTREAM, SET_UPSTREAM 세 개 노드가 자격증명을 읽고, 매핑으로 업스트림을 골라, 요청별 백엔드를 동적으로 바꾸는 흐름을 소개해요. decK와 Admin API를 이용한 플러그인 설정 방법도 함께 안내해요

출처: 문서

본문

인증된 호출자를 기준으로 다른 업스트림으로 요청 라우팅 v3.14+

인증된 자격 증명을 이름이 지정된 Upstream 엔티티에 매핑하고 요청별로 백엔드를 재정의해요. 이 예제는 OpenID Connect 플러그인과 함께 작동해요. 이 플러그인은 베어러 토큰을 검증하고 토큰 클레임(예: client_id)을 가상 자격 증명으로 추출해요. 그런 다음 Datakit이 그 자격 증명을 읽고 그 값을 사용해 업스트림을 선택해요.

이 예제에는 다음 노드들이 포함되어 있어요:

  1. GET_CREDENTIAL은 OpenID Connect 플러그인이 채워 넣은 kong.client.credential 객체를 읽어요.
  2. PICK_UPSTREAM은 jq 맵을 사용해 자격 증명의 .id 필드를 조회하고 일치하는 업스트림 이름을 반환해요. 알 수 없는 호출자는 upstream-default로 넘어가요.
  3. 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)