liquanzhou opened a new issue, #12691:
URL: https://github.com/apache/apisix/issues/12691

   ### Current Behavior
   
   官方文档有写
   
   <img width="645" height="411" alt="Image" 
src="https://github.com/user-attachments/assets/38d4aea1-5b10-44ae-b8e5-48938265a50c";
 />
   
   但实际执行kubernetes的dump列表404
   curl http://127.0.0.1:9090/v1/discovery/kubernetes/dump
   
   请求eureka的dump列表可以成功
   curl http://127.0.0.1:9090/v1/discovery/eureka/dump
   
   
   
   解决方法: 在 apisix/discovery/kubernetes/init.lua ,增加一个函数
   
   
[kubernetes.init.lua.txt](https://github.com/user-attachments/files/23053025/kubernetes.init.lua.txt)
   
   
   
   -- 新增:控制路由 /v1/discovery/kubernetes/dump
   function _M.dump_data()
       local discovery_conf = local_conf.discovery.kubernetes
   
       local function collect_dict(dict)
           local out = {}
           if not dict then
               return out
           end
           local keys = dict:get_keys(0)
           if not keys then
               return out
           end
           for _, k in ipairs(keys) do
               if not core.string.has_suffix(k, "#version") then
                   local v = dict:get_stale(k)
                   if v then
                       local decoded = core.json.decode(v)
                       out[k] = decoded or v
                   end
               end
           end
           return out
       end
   
       local res = { config = local_conf.discovery.kubernetes }
       if #discovery_conf == 0 then
           -- 单实例模式:共享字典名称为 kubernetes 或 kubernetes-stream
           local dict = get_endpoint_dict()
           res.endpoints = collect_dict(dict)
       else
           -- 多实例模式:按 id 维度汇总 kubernetes-<id>
           local endpoints = {}
           for _, conf in ipairs(discovery_conf) do
               local id = conf.id
               endpoints[id] = collect_dict(get_endpoint_dict(id))
           end
           res.endpoints = endpoints
       end
   
       return res
   end
   
   
   
   ### Expected Behavior
   
   _No response_
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   配置好k8s的服务发现
   执行dump接口,404
   curl http://127.0.0.1:9090/v1/discovery/kubernetes/dump
   
   ### Environment
   
   - APISIX version (run `apisix version`):3.9.1
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): 
openresty/1.25.3.1
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`): 3.9.1
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to