Docker로 커스텀 플러그인 배포하기
Docker로 커스텀 플러그인 배포하기 (Deploy a custom plugin with Docker)
이 문서는 직접 만든 커스텀 플러그인을 Docker 이미지로 패키징해서 Kong Gateway에 배포하는 방법을 안내해요 Dockerfile을 작성하고 이미지를 빌드한 다음, 퀵스타트 스크립트로 커스텀 이미지를 실행하는 과정을 차근차근 따라 해요 마지막에는 게이트웨이에서 서비스와 플러그인을 설정해 의도대로 동작하는지 직접 테스트까지 해봐요
출처: 문서
본문
TL;DR
커스텀 플러그인을 Kong Gateway에 어떻게 배포할 수 있나요? 플러그인용 Dockerfile을 만들고, 이미지를 빌드한 다음, 커스텀 이미지로 Kong Gateway를 실행해요.
사전 준비
시리즈 사전 준비
이 페이지는 커스텀 플러그인 개발 시작하기 시리즈의 일부예요.
이 페이지를 진행하기 전에 이전 페이지인 커스텀 플러그인에 메트릭 추가하기를 먼저 완료하세요.
Dockerfile 만들기
이 예제에서는 Dockerfile을 사용해 플러그인을 배포하지만, 다른 배포 옵션도 있어요.
-
프로젝트 루트에
Dockerfile이라는 이름의 파일을 만들어요:touch Dockerfile -
파일에 다음 내용을 추가해요:
FROM kong/kong-gateway:latest # Ensure any patching steps are executed as root user USER root # Add custom plugin to the image COPY ./kong/plugins/my-plugin /usr/local/share/lua/5.1/kong/plugins/my-plugin ENV KONG_PLUGINS=bundled,my-plugin # Ensure kong user is selected for image execution USER kong # Run kong ENTRYPOINT ["/entrypoint.sh"] EXPOSE 8000 8443 8001 8444 STOPSIGNAL SIGQUIT HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health CMD ["kong", "docker-start"]
Docker 이미지 빌드하기
다음 명령어로 Docker 이미지를 빌드해요:
docker build -t kong-gateway_my-plugin:latest-0.0.1 .
Docker 이미지를 빌드할 때는 이미지 태그에 Kong Gateway 버전과 플러그인 버전 정보가 포함되도록 태그를 지정하는 것을 추천해요.
커스텀 이미지 실행하기
이제 Kong Gateway 퀵스타트 스크립트를 사용해 커스텀 이미지를 실행하고 플러그인을 더 테스트할 수 있어요.
퀵스타트 스크립트는 Docker 저장소(-r), 이미지(-i), 태그(-t)를 재정의할 수 있는 플래그를 지원해요.
다음 명령어로 커스텀 이미지와 함께 퀵스타트를 실행해요:
curl -Ls https://get.konghq.com/quickstart | \
bash -s -- -r "" -i kong-gateway_my-plugin -t latest-0.0.1
배포된 커스텀 플러그인 테스트하기
Kong Gateway가 커스텀 이미지로 실행되고 나면, 플러그인을 수동으로 테스트하고 동작을 검증할 수 있어요.
-
테스트용 Gateway Service를 추가해요:
curl -X POST "http://localhost:8001/services" \ --no-progress-meter --fail-with-body \ --json '{ "name": "example_service", "url": "https://httpbin.konghq.com" }' -
이번에는 설정 값을 넣어서 플러그인을 활성화해요:
curl -X POST "http://localhost:8001/services/example_service/plugins" \ --no-progress-meter --fail-with-body \ --json '{ "name": "my-plugin", "config": { "response_header_name": "X-CustomHeaderName" } }' -
Route를 추가해요:
curl -X POST "http://localhost:8001/services/example_service/routes" \ --no-progress-meter --fail-with-body \ --json '{ "name": "example_route", "paths": [ "/mock" ] }' -
Route에 요청을 보내요:
curl -i "http://localhost:8000/mock/anything" \ --no-progress-meter --fail-with-body
다음과 같은 응답 헤더가 보여야 해요:
X-CustomHeaderName: http://httpbin.konghq.com/anything
{:.no-copy-code}
관련 리소스
더 알아보기 (Learn more)
- 이 페이지가 속한 커스텀 플러그인 개발 시리즈의 시작점을 확인할 수 있어요 — Get started with custom plugin development
- 바로 이전 단계에서 플러그인에 메트릭을 추가하는 방법을 배울 수 있어요 — Add metrics to a custom plugin
- Docker 외에 커스텀 플러그인을 배포할 수 있는 다른 옵션들을 소개해요 — deployment options
- 테스트 단계에서 Gateway Service를 생성할 때 사용하는 Admin API 레퍼런스예요 — Gateway Service
- 커스텀 플러그인 전반을 다루는 문서를 한눈에 볼 수 있어요 — Custom plugins