kong/plugin-example本镜像为 Kong Gateway Operator 提供插件分发的参考实现,旨在演示如何通过 Kubernetes 原生资源管理 Kong Gateway 插件的打包、分发与生命周期控制。镜像包含预配置的插件示例、元数据定义及与 Kong Gateway Operator 集成的必要配置,帮助用户快速理解 Operator 管理插件的工作流程。
plugin.yaml),定义插件名称、版本、依赖及配置schemaKongPlugin) 资源定义插件配置bash# 从 Docker Hub 拉取镜像 docker pull kong/kong-gateway-operator-plugin-example:latest # 或从私有仓库拉取(如配置) docker pull <私有仓库地址>/kong-plugin-example:v1.0.0
创建插件元数据文件 plugin-metadata.yaml,定义插件基本信息:
yamlapiVersion: gateway.konghq.com/v1alpha1 kind: KongPluginMetadata metadata: name: example-rate-limit namespace: kong spec: name: rate-limit-example # 插件名称(需与 Kong 插件目录名一致) version: 1.0.0 type: http # 插件类型(http/stream) configSchema: # 插件配置项schema type: object properties: limit: type: integer minimum: 1 period: type: string enum: [second, minute, hour]
通过 KongPlugin 资源定义插件配置及分发目标:
yamlapiVersion: gateway.konghq.com/v1alpha1 kind: KongPlugin metadata: name: demo-rate-limit namespace: kong spec: pluginRef: example-rate-limit # 关联上述元数据资源 config: # 插件运行时配置 limit: 100 period: minute targetRef: # 目标网关选择器 group: gateway.networking.k8s.io kind: Gateway name: kong-gateway namespace: kong
应用资源:
bashkubectl apply -f plugin-metadata.yaml kubectl apply -f kong-plugin.yaml
检查 Operator 状态:
bashkubectl get kongplugins.gateway.konghq.com demo-rate-limit -o yaml
预期输出中 status 字段显示 phase: Ready,表示插件已成功分发至目标网关。
plugin-demo.yaml)yamlapiVersion: gateway.konghq.com/v1alpha1 kind: KongPluginMetadata metadata: name: example-rate-limit namespace: kong spec: name: rate-limit-example version: 1.0.0 type: http configSchema: type: object properties: limit: {type: integer, minimum: 1} period: {type: string, enum: [second, minute, hour]} --- apiVersion: gateway.konghq.com/v1alpha1 kind: KongPlugin metadata: name: demo-rate-limit namespace: kong spec: pluginRef: example-rate-limit config: limit: 100 period: minute targetRef: group: gateway.networking.k8s.io kind: Gateway name: kong-gateway namespace: kong
部署命令:
bashkubectl apply -f plugin-demo.yaml
适用于本地测试 Kong Gateway 与插件集成(非 Operator 环境):
yamlversion: '3' services: kong: image: kong/kong-gateway:3.4 ports: - "8000:8000" # HTTP 代理端口 - "8443:8443" # HTTPS 代理端口 - "8001:8001" # Admin API 端口 environment: - KONG_DATABASE=off - KONG_DECLARATIVE_CONFIG=/etc/kong/kong.yaml - KONG_PLUGINS=bundled,rate-limit-example # 加载自定义插件 volumes: - ./kong.yaml:/etc/kong/kong.yaml - ./plugins/rate-limit-example:/usr/local/kong/plugins/rate-limit-example # 挂载插件目录 plugin-example: image: kong/kong-gateway-operator-plugin-example:latest volumes: - ./plugins:/output # 输出插件示例到本地目录
| 参数路径 | 类型 | 描述 | 示例值 |
|---|---|---|---|
spec.pluginRef | string | 关联的插件元数据资源名称 | example-rate-limit |
spec.config | object | 插件运行时配置(需符合元数据schema) | {limit: 100, period: "minute"} |
spec.targetRef.group | string | 目标网关所属API组 | gateway.networking.k8s.io |
spec.targetRef.kind | string | 目标网关资源类型 | Gateway |
spec.targetRef.name | string | 目标网关实例名称 | kong-gateway |
| 环境变量名 | 描述 | 默认值 |
|---|---|---|
PLUGIN_NAME | 插件名称(覆盖元数据定义) | rate-limit-example |
LOG_LEVEL | 日志级别(debug/info/warn/error) | info |
OPERATOR_SYNC_INTERVAL | 与 Operator 状态同步间隔(秒) | 30 |

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务