次のように呼び出しnginx
をプロキシする k8s クラスターに展開しています。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
機能しますが、ポッドの準備ができていない場合、nginx が次のエラーで失敗することがあります。
nginx: [emerg] host not found in upstream "backend-dev" in /etc/nginx/conf.d/default.conf:12
インターネットを数時間探索した後、ほぼ同じ問題の記事を見つけました。私はこれを試しました:
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でそれを修正する正しい方法は何ですか?