Openshift 中的 NGINX - NGINX 无法解析内部主机名 [英] NGINX in Openshift - NGINX can't resolve internal hostnames

查看:26
本文介绍了Openshift 中的 NGINX - NGINX 无法解析内部主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用变量重写 &代理到 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.localas the resolver:

resolver kube-dns.kube-system.svc.cluster.local;

但 Openshift 不提供此功能.我已经尝试使用容器的 /etc/resolv.conf 中的 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 无法解析内部主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆