【发布时间】:2016-09-28 03:54:04
【问题描述】:
我正在尝试创建一个 nginx 代理,将请求转发到 /<service> 到 http://<service>。我首先尝试了以下方法:
location ~ ^/(.+)$ {
set $backend "http://$1:80";
proxy_pass $backend;
}
但它无法说出类似(调用/myservice时):
[error] 7741#0: *1 no resolver defined to resolve http://myservice
由于myservice 无法从外部访问,我尝试将go-dnsmasq 作为sidecar 安装在同一个pod 中,并尝试将其用于DNS 解析(就像我在this 示例中看到的那样)并更改我的 nginx 配置如下所示:
location ~ ^/(.+)$ {
resolver 127.0.0.1:53;
set $backend "http://$1:80";
proxy_pass $backend;
}
但是现在 nginx 失败了:
[error] 9#9: *734 myservice could not be resolved (2: Server failure), client: 127.0.0.1, server: nginx-proxy, request: "GET /myservice HTTP/1.1", host: "localhost:8080"
127.0.0.1 - xxx [30/May/2016:10:34:23 +0000] "GET /myservice HTTP/1.1" 502 173 "-" "curl/7.38.0" "-"
我的 Kubernetes pod 如下所示:
spec:
containers:
- name: nginx
image: "nginx:1.10.0"
ports:
- containerPort: 8080
name: "external"
protocol: "TCP"
- name: dnsmasq
image: "janeczku/go-dnsmasq:release-1.0.5"
args:
- --listen
- "0.0.0.0:53"
在 dnsmasq 容器中运行 netstat -ntlp 给了我:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN -
tcp 0 0 :::53 :::* LISTEN 1/go-dnsmasq
并在 nginx 容器中运行nmap --min-parallelism 100 -sT -sU localhost:
Starting Nmap 6.47 ( http://nmap.org ) at 2016-05-30 10:33 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00055s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 1997 closed ports
PORT STATE SERVICE
53/tcp open domain
8080/tcp open http-proxy
53/udp open domain
看来 dnsmasq 和 nginx 确实启动并运行了?我可能做错了什么?
【问题讨论】:
标签: nginx dns kubernetes dnsmasq