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

decK로 플러그인 관리

원문 보기 위키 갱신

decK로 플러그인 관리 (Managing plugins with decK)

플러그인 추가와 관리는 플랫폼 팀에서 자주 하는 작업인데, decK의 deck file add-plugins 명령을 쓰면 이를 프로그래밍 방식으로 처리할 수 있어요. 이미 같은 이름의 플러그인이 있을 때는 --overwrite 플래그나 overwrite: true 설정을 지정해야 기존 플러그인을 덮어쓸 수 있다는 점을 기억해 주세요. 명령은 기본적으로 수정된 파일을 표준 출력으로 내보내지만, -o 옵션을 사용하면 결과를 파일로 저장할 수도 있어요. 플러그인 설정에서 일부 값만 고치고 싶을 때는 deck file patch 명령을 함께 활용하면 좋아요

출처: 문서

본문

추가하려는 플러그인이 이미 존재하면, --overwrite 플래그를 제공하거나 플러그인 구성 파일에 overwrite: true를 지정하지 않는 한 add-plugin 명령어는 플러그인을 수정하지 않아요.

deck file add-plugins 명령어는 기본적으로 패치된 파일을 stdout으로 출력해요. -o ./config.yaml을 사용해 파일 경로를 지정하면 업데이트된 구성을 디스크의 파일에 쓸 수 있어요.

새 플러그인 추가하기

다음 예제는 deck file add-plugins -s ./kong.yaml plugin1.yaml로 실행할 수 있어요.

여러 플러그인 정의 파일을 명령어에 전달할 수도 있어요. 예를 들어 deck file add-plugins -s ./kong.yaml plugin1.yaml plugin1.yaml처럼요.

# plugin.yaml
add-plugins:
  - selectors:
      - $..services[*]
    overwrite: false
    plugins:
      - name: request-termination
        config:
          status_code: 403
          message: Scheduled maintenance in progress

특정 구성 값 업데이트하기

deck file add-plugins 명령어는 플러그인 구성 전체를 설정해요. 특정 값만 편집하려면 deck file patch 명령어를 사용할 수 있어요.

위의 request-termination 플러그인이 다른 메시지를 반환하도록 업데이트하려면:

patches:
  - selectors:
      - $.services[*].plugins[?(@.name=='request-termination')].config
    values:
      message: "Installing new bits and bytes"

자세한 내용은 deck file patch 문서를 참고하세요.

명령어 사용법

Usage:
  deck file add-plugins [flags] [...plugin-files]

Examples:
# adds a plugin to all services in a deck file, except if it is already present
cat kong.yml | deck file add-plugins --selector='services[*]' \
               --config='{"name":"my-plugin","config":{"my-property":"value"}}'

# same, but now overwriting plugins if they already exist and reading from files
cat kong.yml | deck file add-plugins --overwrite plugin1.json plugin2.yml

Flags:
      --config stringArray     JSON snippet containing the plugin configuration to add. Repeat to add
                               multiple plugins.
      --format string          Output format: json or yaml (default "yaml")
  -h, --help                   help for add-plugins
  -o, --output-file string     Output file to write to. Use - to write to stdout. (default "-")
      --overwrite              Specify this flag to overwrite plugins by the same name if they already
                               exist in an array. The default behavior is to skip existing plugins.
      --selector stringArray   JSON path expression to select plugin-owning objects to add plugins to.
                               Defaults to the top-level (selector '$'). Repeat for multiple selectors.
  -s, --state string           decK file to process. Use - to read from stdin. (default "-")

관련 리소스

더 알아보기 (Learn more)

  • 플러그인 설정에서 특정 값만 선택적으로 수정하는 방법을 알아봐요 — deck file patch
  • Kong에서 사용할 수 있는 다양한 플러그인을 한눈에 탐색해요 — Kong Plugin Hub
  • 플러그인 엔티티의 구성 요소와 속성을 자세히 살펴봐요 — Plugin entity