kong的插件大多以lua脚本的形式提供,新增插件需要把脚本打到kong镜像中,一般分下面几步:
FROM kong:2.6
USER root
//1.安装kong-response-string-replace依赖的工具包
RUN apk update && apk add git zlib zlib-dev libc-dev gcc brotli brotli-libs brotli-dev
RUN cd kong-response-string-replace && luarocks install *.rockspec
//2.下载/拷贝插件源码到特定目录
RUN git config --global advice.detachedHead false
RUN git clone https://github.com.cnpmjs.org/dsteinkopf/kong-response-string-replace
//3.安装插件包,这里使用luarocks安装,也可手工拷贝到插件目录,但luarocks会处理依赖问题
RUN luarocks install luajit-brotli
//4.将kong-response-string-replace添加到kong的插件列表中
RUN sed -i '/"response-transformer"/a\ "kong-response-string-replace",'usr/local/share/lua/5.1/kong/constants.lua
验证插件是否安装成功:
curl -X GET http://10.108.209.14:8001/schemas/plugins/kong-response-string-replace
该IP为kong-kong-admin服务的ip,可获取插件的参数,如果获取到,即可说明插件已安装成功
获取已生效的插件:
curl -X GET http://10.108.209.14:8001/plugins | jq
新增插件:
curl -X POST http://10.108.209.14:8001/services/php/plugins --data "name=kong-response-string-replace" --data "config.body_replace_patterns=phpMyAdmin###xiaoyaoyao"