Nginx proxy_pass directive string interpolation

左心房为你撑大大i 提交于 2019-12-06 03:45:29

I've found the reason and a solution.

Nginx detects if a variable is being used in proxy_pass (I don't know how it does that). If there is no variable it resolved the hostname at startup and caches the IP address. If there is a variable it uses a resolver (DNS server) to lookup the IP at runtime.

So the solution is to specify the Kube DNS server like this:

resolver kube-dns.kube-system.svc.cluster.local valid=5s;
set $service "service-1";
proxy_pass "http://$service.default.svc.cluster.local";

Note that the full local DNS name of the service must be used which you can get by running nslookup service-1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!