You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

K8s集群中多Kong实例资源存储异常及控制器事件忽略问题问询

问题分析与解决方案

核心根因

从你提供的日志能抓到关键线索:ignoring add event for ... based on annotation kubernetes.io/ingress.class with value——这里的value是空的!也就是说,生产环境的Kong控制器在处理这些KongConsumer、KongCredential和部分KongPlugin时,根本没读取到正确的kubernetes.io/ingress.class: "kong-production"注解,所以判定这些资源不属于它的管理范围,直接忽略了同步操作;而沙箱环境的控制器因为监听的是kong类,这些无正确注解的资源被沙箱控制器误识别并同步到了沙箱数据库里。

另外你提到生产实例的KongPlugins能正常存储到生产数据库,说明这部分插件的注解是正确配置的,其他资源的注解大概率是遗漏或者配置位置不对。


排查与解决步骤

1. 检查CRD资源的注解配置(最关键)

Kong Ingress Controller 识别资源归属的核心是资源自身的kubernetes.io/ingress.class注解,而不是只在关联的Ingress上配置。你需要给生产环境的KongConsumer、KongCredential和对应的KongPlugin资源本身添加注解:

  • 示例KongPlugin配置:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: swaggerapi-production-basic-auth
  annotations:
    # 必须加在Plugin资源本身上,不是Ingress!
    kubernetes.io/ingress.class: "kong-production"
plugin: basic-auth
# 其他配置...
  • 示例KongConsumer配置:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
  name: zcrm365dev-consumer
  annotations:
    kubernetes.io/ingress.class: "kong-production"
username: zcrm365dev
# 其他配置...
  • 用kubectl验证注解是否生效:
kubectl get kongplugin swaggerapi-production-basic-auth -o yaml | grep -A2 annotations
kubectl get kongconsumer zcrm365dev-consumer -o yaml | grep -A2 annotations
kubectl get kongcredential zcrm365dev-credential -o yaml | grep -A2 annotations

如果输出里没有kubernetes.io/ingress.class: "kong-production",就需要修正资源配置。

2. 确认生产控制器的启动参数

检查生产环境Kong Ingress Controller的Deployment配置,确保:

  • 启动参数--ingress-class=kong-production拼写完全正确(无大小写错误、空格)
  • --kong-url指向的是生产Kong实例的管理端口(比如http://kong-production:8001),避免控制器误连沙箱数据库
    示例启动参数片段:
containers:
- name: kong-ingress-controller-production
  command:
  - /kong-ingress-controller
  args:
  - --ingress-class=kong-production
  - --kong-url=http://kong-production:8001
  # 其他参数...

3. 验证控制器版本兼容性

部分旧版本的Kong Ingress Controller对KongConsumer、KongCredential的ingress class注解支持不完善,如果你使用的版本较旧,建议升级到稳定版本,确保控制器能正确识别这些资源上的归属注解。

4. 清理沙箱数据库中的错误资源

问题解决后,需要手动删除沙箱数据库里误同步的生产资源:

  • 先端口转发沙箱Kong的管理端口:kubectl port-forward pod/kong-ingress-controller-xxx 8001:8001
  • 通过API删除消费者:curl -X DELETE http://localhost:8001/consumers/ycrm365dev
  • 删除对应凭证:先查询凭证ID curl http://localhost:8001/consumers/ycrm365dev/basic-auth,再执行curl -X DELETE http://localhost:8001/consumers/ycrm365dev/basic-auth/<credential-id>
  • 删除误同步的插件:查询插件ID curl http://localhost:8001/plugins,找到生产环境的插件后执行curl -X DELETE http://localhost:8001/plugins/<plugin-id>

内容的提问来源于stack exchange,提问作者bgarcial

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:26:35