我正在使用后端服务器和套接字服务器设置容器部署。当我尝试连接到我的Web服务器端点时,它很好,但是当连接到套接字服务器端点时,它返回了400
我跟踪了几个主题,例如: WebSocket handshake: Unexpected response code: 400 in kubernetes-ingress
但是添加注释WebSocket服务和代理超时不起作用。
当我向前转发部署平台时,它工作正常。因此问题必须出在Nginx入口控制器上。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
namespace: {{ include "namespace" . }}
labels:
helm.sh/chart: {{ include "chartname" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/stage: {{ .Values.stage }}
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
spec:
tls:
- secretName: tls-certificate
hosts:
{{ range .Values.hosts }}
- {{ . | quote }}
{{ end }}
rules:
- host: mydomain.tk
http:
paths:
- path: /
backend:
serviceName: web
servicePort: http
- path: /socket
backend:
serviceName: web
servicePort: socket
这是我的service.yml文件:
apiVersion: v1
kind: Service
metadata:
name: web
namespace: {{ include "namespace" . }}
labels:
helm.sh/chart: {{ include "chartname" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/stage: {{ .Values.stage }}
spec:
type: NodePort
sessionAffinity: ClientIP
ports:
- port: {{ .Values.web.port }}
targetPort: http
protocol: TCP
name: http
- port: {{ .Values.web.socket }}
targetPort: socket
protocol: TCP
name: socket
selector:
name: web
无论我在做什么,它总是在/ socket端点上返回400。
我当前正在使用最新版本的Nginx Ingress和GKE版本1.11.7
入口的输出:
Name: ingress
Namespace: backend
Address:
Default backend: default-http-backend:80 (10.48.0.9:8080)
TLS:
tls-certificate terminates mydomain.tk
Rules:
Host Path Backends
---- ---- --------
mydomain.tk
/ web:http (10.48.0.28:8080)
/socket web:socket (10.48.0.28:9092)
Annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-read-timeout: 3600
nginx.ingress.kubernetes.io/proxy-send-timeout: 3600
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 13s nginx-ingress-controller Ingress backend/ingress
答案 0 :(得分:0)
我基本上通过在应用程序中添加跨源标头来解决了问题。
答案 1 :(得分:0)
在我的情况下,此问题是由客户端发送的标题行过长引起的。我已经通过设置/增加NGINX Ingress Controller ConfigMap的以下配置参数解决了该问题: