解决 Kong 报错 DB-less memory cache full: shared dict exhausted 内存缓存耗尽修复
排查 Kong 在无数据库模式下随着路由与服务数量增加,启动报 failed to load declarative config: no memory in lua_shared_dict,分析 共享字典内存扩容。
问题现象
在大型微服务网格中加载包含数万条路由的 kong.yml 时,进程启动报错退出:
[emerg] 21401#0: [lua] dbless.lua:142: load(): no memory in lua_shared_dict: kong_core_db_cache
Error: failed to load declarative config into memory
触发根因
- 在 DB-less 模式下,Kong 将所有 Service、Route、Plugin、Consumer 完整元数据完全保存在 Nginx 的共享内存字典(
lua_shared_dict)中; - 默认分配的
mem_cache_size仅有 128MB; - 海量实体配置数据加上哈希索引体积超过了分配的物理共享内存上限。
解决步骤
在 kong.conf 中大幅调高共享内存缓存配额
编辑 /etc/kong/kong.conf:
mem_cache_size = 512m
对于极大规模集群(10 万+路由),可配置为 1024m。
确保宿主机/容器的物理内存配额充足支撑
在 Docker / Kubernetes 容器配额中分配至少 2GB 内存。
验证确认
重启 Kong 服务:
大型声明式配置在共享内存中秒级完成索引构建,全量路由平稳上线。


