問題背景
一個 python 服務介面由于需要處理大量資料,耗時比較長,每次請求都會報錯 nginx 504 gateway timeout,應用都是通過 k8s 容器部署的,請求從客戶端到達應用還需要經過一層代理分發層應用 web-proxy,
分析排查
簡單分析如下:??
- 應用介面是用的 gunicron 服務器,顯然地與 nginx 報錯資訊無關,所以問題不在這里
- 代理分發層應用 web-proxy 部署時需要用到 ingress,大膽懷疑報錯來自這里
可以通過查看 nginx-ingress-controller pod 日志,搜索報錯的 api url,來驗證猜想:

如果找不到 nginx-ingress-controller pod,可能是因為其在另外的 namesapce 下,可以使用命令 kubectl get pods --all-namespaces | grep ingress 查詢所有命名空間的 ingress pod,
解決方案
驗證猜想正確后,就需要動手修改 web-proxy 的ingress 配置了,根據 https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-timeouts 檔案,修改后的 Ingress 配置如下:
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web-proxy-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
# 按自己實際所需配置
nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
參考
- custom-timeouts

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/549883.html
標籤:其他
