我有一个路由到 kubernetes 集群外部的自定义端点的入口。该服务仅在端口 8006 上侦听 HTTPS。
apiVersion: v1
kind: Service
metadata:
name: pve
spec:
ports:
- protocol: TCP
port: 8006
---
apiVersion: v1
kind: Endpoints
metadata:
name: pve
subsets:
- addresses:
- ip: 10.0.1.2
ports:
- port: 8006
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: pve
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/auth-tls-verify-client: "off"
nginx.ingress.kubernetes.io/whitelist-source-range: "10.0.0.0/16"
spec:
tls:
- hosts:
- pve.example.com
secretName: pve-tls
rules:
- host: pve.example.com
http:
paths:
- backend:
serviceName: pve
servicePort: 8006
path: /
nginx pod 中出现错误:
10.0.0.25 - - [28/Aug/2020:01:17:58 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0" "-"
2020/08/28 01:17:58 [错误] 2609#2609:*569 上游读取上游响应标头时过早关闭连接,客户端:10.0.0.25,服务器:pve.example.com,请求:“GET / HTTP/1.1”,上游:“http://10.0.1.2:8006/”,主机:“pve.example.com”
编辑
删除代理协议后,出现错误
10.0.10.1 - - [28/8月/2020:02:19:18 +0000] "GET / HTTP/1.1" 400 59 "-" "curl/7.58.0" "-"
2020/08/28 02:19:26 [错误] 2504#2504:*521 上游在读取上游响应标头时过早关闭连接,客户端:10.0.10.1,服务器:pve.example.com,请求:“GET / HTTP/1.1”,上游:“http://10.0.1.2:8006/”,主机:“pve.example.com”
10.0.10.1 - - [28/8月/2020:02:19:26 +0000] "GET / HTTP/1.1" 502 157 "-" "curl/7.58.0" "-"
如果相关的话,我的 nginx 配置是通过 helm char 部署的nginx-stable/nginx-ingress
## nginx configuration
## Ref: https://github.com/kubernetes/ingress/blob/master/controllers/nginx/configuration.md
##
controller:
config:
entries:
hsts-include-subdomains: "false"
ssl-ciphers: "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"
ssl-protocols: "TLSv1.1 TLSv1.2"
ingressClass: nginx
service:
externalTrafficPolicy: Local
annotations:
metallb.universe.tf/address-pool: default
defaultBackend:
enabled: true
tcp:
22: "gitlab/gitlab-gitlab-shell:22"
答案1
这个注释可能是导致问题的原因。
nginx.ingress.kubernetes.io/use-proxy-protocol: "true"
这文档状态:
启用或禁用 PROXY 协议以接收通过代理服务器和负载均衡器(例如 HAProxy 和 Amazon Elastic Load Balancer (ELB))传递的客户端连接(真实 IP 地址)信息。
如果您的 Ingress 前面没有使用 PROXY 协议传递连接的负载均衡器,那么这不是您想要的,并且这个注释不应该存在(或应该存在"false"
)。
答案2
这是社区 wiki 答案。请随意扩展它。
您看到的错误:upstream prematurely closed connection while reading response header from upstream
来自 Nginx,意味着连接已被您的“上游”关闭。
没有必要的详细信息,很难说出导致此问题的确切原因,但无论如何,您可以尝试根据以下方法增加超时值本文档, 具体来说:
proxy_read_timeout
proxy_connect_timeout
您还可以调整“上游”的代码/配置,无论您的用例是什么。