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

플러그인 구성 중복 제거

원문 보기 위키 갱신

플러그인 구성 중복 제거 (De-duplicate plugin configuration)

Kong Gateway에서 여러 컨슈머나 서비스에 같은 플러그인 구성을 붙이다 보면, 설정을 바꿀 때마다 모든 인스턴스에 동일한 내용을 반복해서 수정해야 하는 불편함이 생겨요. 이 문서에서는 decK의 플러그인 구성 중복 제거 기능을 활용해 플러그인 설정을 한 번만 정의하고 여러 엔티티에서 재사용하는 방법을 소개해요. 플러그인 구성을 다른 팀이 관리하고 API 소유자가 게이트웨이 구성을 다루는 상황에서의 활용법과, 재사용하는 구성에서 필요한 필드만 골라 재정의하는 방법도 함께 설명해요

출처: 문서

본문

Kong Gateway의 서로 다른 엔티티에 적용되지만 설정은 동일한 경우도 있어요. 이런 경우 플러그인 설정에서 무엇을 변경하더라도 플러그인의 각 인스턴스마다 그 변경을 반복해야 해요.

다른 사용 사례에서는 플러그인 설정을 다른 팀이 결정하고, 메인 Kong Gateway 설정은 API 오너가 직접 사용할 수도 있어요.

decK은 이 두 가지 사용 사례를 모두 지원해요.

중복 제거된 플러그인 설정 구성하기

예시 설정 파일을 살펴볼까요:

consumers:
  - username: foo
    tags:
      - silver-tier
    plugins:
      - name: rate-limiting
        config:
          day: null
          fault_tolerant: true
          hide_client_headers: false
          hour: null
          limit_by: consumer
          minute: 10
          month: null
          policy: redis
          redis_database: 0
          redis_host: redis.common.svc
          redis_password: null
          redis_port: 6379
          redis_timeout: 2000
          second: null
          year: null
        enabled: true
        run_on: first
        protocols:
          - http
          - https
  - username: bar
    tags:
      - silver-tier
    plugins:
      - name: rate-limiting
        config:
          day: null
          fault_tolerant: true
          hide_client_headers: false
          hour: null
          limit_by: consumer
          minute: 10
          month: null
          policy: redis
          redis_database: 0
          redis_host: redis.common.svc
          redis_password: null
          redis_port: 6379
          redis_timeout: 2000
          second: null
          year: null
        enabled: true
        run_on: first
        protocols:
          - http
          - https
  - username: baz
    tags:
      - gold-tier
    plugins:
      - name: rate-limiting
        config:
          day: null
          fault_tolerant: true
          hide_client_headers: false
          hour: null
          limit_by: consumer
          minute: 20
          month: null
          policy: redis
          redis_database: 0
          redis_host: redis.common.svc
          redis_password: null
          redis_port: 6379
          redis_timeout: 2000
          second: null
          year: null
        enabled: true
        run_on: first
        protocols:
          - http
          - https
  - username: fub
    tags:
      - gold-tier
    plugins:
      - name: rate-limiting
        config:
          day: null
          fault_tolerant: true
          hide_client_headers: false
          hour: null
          limit_by: consumer
          minute: 20
          month: null
          policy: redis
          redis_database: 0
          redis_host: redis.common.svc
          redis_password: null
          redis_port: 6379
          redis_timeout: 2000
          second: null
          year: null
        enabled: true
        run_on: first
        protocols:
          - http
          - https

여기에는 두 그룹의 Consumer가 있어요:

  • silver-tier Consumer는 분당 10개 요청으로 우리 API에 접근할 수 있어요
  • gold-tier Consumer는 분당 20개 요청으로 우리 API에 접근할 수 있어요

이제 rate limit을 늘리거나 Redis 서버의 호스트를 변경하려면 플러그인의 모든 인스턴스 설정을 하나하나 수정해야 해요.

이런 반복을 줄이려면 플러그인 설정을 중복 제거하고, 필요한 곳에서 이를 참조하면 돼요. 이 방식은 여러 파일에 걸쳐서도 동작해요.

위 파일은 이제 다음과 같이 바뀌어요:

_plugin_configs:
  silver-tier-limit:
    day: null
    fault_tolerant: true
    hide_client_headers: false
    hour: null
    limit_by: consumer
    minute: 14
    month: null
    policy: redis
    redis_database: 0
    redis_host: redis.common.svc
    redis_password: null
    redis_port: 6379
    redis_timeout: 2000
    second: null
    year: null
  gold-tier-limit:
    day: null
    fault_tolerant: true
    hide_client_headers: false
    hour: null
    limit_by: consumer
    minute: 20
    month: null
    policy: redis
    redis_database: 0
    redis_host: redis.common.svc
    redis_password: null
    redis_port: 6379
    redis_timeout: 2000
    second: null
    year: null
consumers:
  - username: foo
    tags:
      - silver-tier
    plugins:
      - name: rate-limiting
        _config: silver-tier-limit
        enabled: true
        protocols:
          - http
          - https
  - username: bar
    tags:
      - silver-tier
    plugins:
      - name: rate-limiting
        _config: silver-tier-limit
        enabled: true
        protocols:
          - http
          - https
  - username: baz
    tags:
      - gold-tier
    plugins:
      - name: rate-limiting
        _config: gold-tier-limit
        enabled: true
        protocols:
          - http
          - https
  - username: fub
    tags:
      - gold-tier
    plugins:
      - name: rate-limiting
        _config: gold-tier-limit
        enabled: true
        protocols:
          - http
          - https

이제 플러그인 설정을 한 곳에서 수정하면 여러 엔티티에 걸쳐 그 효과를 볼 수 있어요. 내부적으로 decK은 변경 사항을 가져와서 변경된 플러그인 설정을 참조하는 각 엔티티에 적용해요. 그리고 언제나 그렇듯이, Kong Gateway 클러스터에 적용하기 전에 deck gateway diff를 사용해 변경 사항을 확인하세요.

플러그인 설정에서 필드 재정의하기

_plugin_configs에 구성된 설정은 같은 태그를 가진 모든 플러그인에 적용돼요. 이 설정들이 기본 설정을 제공하지만, 해당 설정을 사용하는 엔티티에 맞게 필요한 특정 필드는 변경할 수 있어요.

엔티티에 설정된 특정 값은 _plugin_configs에 정의된 값보다 우선해요.

예를 들어, 앞선 예시의 Consumer fub는 여전히 gold-tier-limit에 속하지만 20 대신 50 분의 rate limit이 필요하다고 해볼게요. 이 값은 해당 특정 Consumer에 대해서만 변경할 수 있어요:

- username: fub
  tags:
    - gold-tier
  plugins:
    - name: rate-limiting
      _config: gold-tier-limit
      config:
        minute: 50
      enabled: true
      protocols:
        - http
        - https

이제 두 gold tier Consumer인 baz와 fub를 비교해 볼게요.

먼저 baz를 확인해 볼까요:

curl -i -X http://localhost:8001/consumers/baz/plugins

결과에서 minute 설정을 찾아보세요. 이 Consumer는 gold-tier-limit의 설정, 즉 minute: 20을 따라요.

이제 fub를 확인해 볼까요:

curl -i -X http://localhost:8001/consumers/fub/plugins

결과에서 minute 설정을 찾아보세요. 이 Consumer는 자체 rate limit인 minute: 50을 가지고 있어요.

관련 자료

더 알아보기 (Learn more)

  • 구성을 적용하기 전에 deck gateway diff 명령으로 변경 사항을 미리 비교하고 검증하는 방법이에요 — deck gateway diff
  • decK에서 사용할 수 있는 gateway 명령어 전체를 한눈에 살펴볼 수 있어요 — deck gateway commands