【发布时间】:2019-11-26 05:24:22
【问题描述】:
我在 k8s 集群中有一个 nginx 部署,它代理我的 api/ 调用,如下所示:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
proxy_pass http://backend-dev/api;
}
}
这在大多数情况下都有效,但是有时当api pod 没有准备好时,nginx 会失败并出现错误:
nginx: [emerg] host not found in upstream "backend-dev" in /etc/nginx/conf.d/default.conf:12
在浏览互联网几个小时后,我发现了article,这几乎是相同的问题。我试过这个:
location /api {
set $upstreamName backend-dev;
proxy_pass http://$upstreamName/api;
}
现在 nginx 返回 502。 还有这个:
location /api {
resolver 10.0.0.10 valid=10s;
set $upstreamName backend-dev;
proxy_pass http://$upstreamName/api;
}
Nginx 返回 503。
在 k8s 上修复它的正确方法是什么?
【问题讨论】:
标签: nginx kubernetes proxy nginx-reverse-proxy kubernetes-deployment