Nginx Ingress Controller中实现Pod重试机制
在K8S环境中实现,当请求后端服务如某个URL失败时,尝试下一个上游(upstream)服务器,类似于Nginx的ngx_stream_upstream_check_module模块功能(粗浅理解),Nginx 默认不会对 POST 等非幂等方法重试,除非显式的添加 non_idempotent 到 proxy-next-upstream。
完整示例:Ingress 配置:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/proxy-next-upstream: "error timeout http_500 http_502 http_503 http_504" #检测非200状态时跳到下一个节点·
nginx.ingress.kubernetes.io/proxy-next-upstream-timeout: "5"
nginx.ingress.kubernetes.io/proxy-next-upstream-tries: "3"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "5"
nginx.ingress.kubernetes.io/proxy-read-timeout: "60"
spec:
ingressClassName: nginx
rules:
- host: www.abc.com
http:
paths:
- path: /api/s1
pathType: Prefix
backend:
service:
name: abc-service
port:
number: 80
可以提升系统的容错能力,尤其是在后端 Pod 瞬时故障或重启时,可提高用户体验·
Tag标签:「Pod upstream」更新时间:「2025-08-27 08:58:27」阅读次数:「9」