kong upstream支持ipv6

在开源网关kong下,若用户的upstream地址配置ipv6的域名,可能会出现httpDns(看各自使用的dns的场景而定)解析失败的情况。具体报错详情如下:


2020/08/18 16:30:01 [error] 289375#0: *9273676 [lua] balancer.lua:781: execute(): [dns] dns client error: 101 empty record received. Tried: (short)www.neu6.edu.cn:(na) - cache-miss
www.neu6.edu.cn:1 - cache-miss/scheduled/querying/dns client error: 101 empty record received
www.neu6.edu.cn:5 - cache-miss/scheduled/querying/dns client error: 101 empty record received
, client: xxx.38.xxx.ip, server: kong, request: "GET / HTTP/1.1", host: "xxxxxxxxxxxxxx"

2020/08/18 16:30:01 [warn] 289375#0: *9273676 [lua] handler.lua:136: header_filter(): requestId: btuq320og156hv9sva0ouss0j58nwq58 , message:UPSTREAM_ERROR=>upstream 500 error:-, client: xxx.38.xxx.ip, server: kong, request: "GET / HTTP/1.1", host: "xxxxxxxxxxxxxx"

2020/08/18 16:30:01 [info] 289375#0: *9273676 [lua] handler.lua:185: body_filter(): requestId: btuq320og156hv9sva0ouss0j58nwq58 , message:响应body: =>{"error":{"message":"name resolution failed [gw]","status":"UNAVAILABLE","code":503},"requestId":"btuq320og156hv9sva0ouss0j58nwq58"}

通过报错信息可以看到,是由于未查询到对应www.neu6.edu.cn的ip地址,因为该域名只有对应ipv6的vip,所以默认采取ipv4的类型去请求dns,自然查询不到。

通过调研发现,目前kong在请求dns时,会默认采用dns_order时配置的顺序,但默认官方给出的参数中只有这四项:LAST,SRV,A,CNAME。而ipv6对应的类型为AAAA。但当我讲AAAA添加到dns_order中时,会导致kong启动失败。这是因为kong在启动时会对参数的value值进行校验,经过修改校验规则完美解决该问题。具体路径为/usr/local/share/lua/5.1/kong/conf_loader.lua,具体代码如下:

  if conf.dns_order then
    local allowed = { LAST = true, A = true, CNAME = true, SRV = true , AAAA= true }
    for _, name in ipairs(conf.dns_order) do
      if not allowed[name:upper()] then
        errors[#errors+1] = "dns_order: invalid entry '" .. tostring(name) .. "'"
      end
    end
  end

你可能感兴趣的:(OpenResty,kong,ipv6,dns_order,upstream)