当使用变量重写和代理到nginx容器proxy_pass配置中的内部Openshift服务时,由于需要解析器,NGINX无法解析服务的DNS。例如:
location /api/ {
set $pass_url http://service.namespace.svc:8080$request_uri;
proxy_pass $pass_url;
}
使用标准 Kubernetes 时,我可以使用kube-dns.kube-system.svc.cluster.local
作为解析器:
resolver kube-dns.kube-system.svc.cluster.local;
但是Openshift并没有提供这个。我尝试使用容器/etc/resolv.conf
中的 IP,这只是群集中运行 DNS 服务器的节点之一,但它仍然无法解析。
最奇怪的部分是从容器终端内部nslookup service.namespace.svc
使用名称服务器/etc/resolv.conf
并且工作正常。
是否有一个等效的 Openshift 中的 Kubernetes DNS 主机名,或者可能是另一种解决方案来解决这个问题?
在 OpenShift 4.7 中运行 ngnix 我能够通过添加来解决此问题
resolver 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
。
在Openshift集群中,每个主节点上都有SkyDNS服务。它通常侦听端口 8053。只需将它们用作nginx配置的解析器,您就会没事:
resolver your-openshift-master-node1-ip:8053 your-openshift-master-node2-ip:8053;
从 https://docs.openshift.com/container-platform/3.11/architecture/networking/networking.html#architecture-additional-concepts-openshift-dns 来看,看起来以下内容应该有效
<service>.<pod_namespace>.svc.cluster.local