问题描述
使用变量重写&在Nginx容器的proxy_pass配置中代理内部Openshift服务时,由于必需的解析器,NGINX无法解析该服务的DNS.例如:
When using a variable to rewrite & proxy to an internal Openshift service within an nginx container's proxy_pass config, NGINX can't resolve the service's DNS due to a required resolver. For instance:
location /api/ {
set $pass_url http://service.namespace.svc:8080$request_uri;
proxy_pass $pass_url;
}
使用标准Kubernetes时,我可以使用 kube-dns.kube-system.svc.cluster.local
作为解析器:
When using standard Kubernetes, I can use kube-dns.kube-system.svc.cluster.local
as the resolver:
resolver kube-dns.kube-system.svc.cluster.local;
但是Openshift不提供此功能.我尝试使用容器的/etc/resolv.conf
中的IP,该IP只是群集中运行DNS服务器的节点之一,但仍然无法解析
But Openshift doesn't provide this. I've tried using the IP that is in the container's /etc/resolv.conf
, which is just one of the nodes in my cluster that is running the DNS server, but it still can't resolve.
最奇怪的部分是容器终端内部的 nslookup service.namespace.svc
使用/etc/resolv.conf
中的名称服务器,并且工作正常.
Weirdest part is nslookup service.namespace.svc
from inside the container terminal uses the nameserver in /etc/resolv.conf
and it works fine.
我可以使用Openshift中的Kubernetes DNS主机名等效项,还是解决此问题的另一种解决方案?
Is there an equivalent to the Kubernetes DNS hostname in Openshift I could use, or perhaps another solution to work around this?
推荐答案
在OpenShift 4.7中运行ngnix,我可以通过添加解决该问题
Running ngnix in OpenShift 4.7 I was able to work around this issue by adding
解析器dns-default.openshift-dns.svc.cluster.local
到 server
配置.显然,ngnix不会解析/etc/resolv.conf
,但是(以我为例), dns-default.openshift-dns.svc.cluster.local
也可以解析为 172.30.0.10
,在/etc/resolv.conf
中被定义为 nameserver
.
to the server
configuration. Apparently, ngnix is not parsing /etc/resolv.conf
, but (in my case), dns-default.openshift-dns.svc.cluster.local
also resolves to 172.30.0.10
, which was defined as a nameserver
in /etc/resolv.conf
.
这篇关于Openshift中的NGINX-NGINX无法解析内部主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!