【发布时间】:2019-12-04 20:01:40
【问题描述】:
后端使用 Springboot 提供 WebSocket 连接,并将最大空闲时间设置为 3 分钟。该程序在本地运行良好。空闲 3 分钟后,连接将按计划断开。部署在Kubernetes中也可以通过节点端口服务正常访问。
但是当我将 sidecar 注入这个后端 pod 时,出现了问题。连接无法正常工作,经常中断,并且完全不规则。有时前端和后端正在发送消息时,突然中断。有时它会在大约 2 分钟空闲后中断。而且有时连接只能持续几十秒。
当连接中断时,后端会抛出java.io.EOFException,前端会收到on close事件。
只要在pod中注入sidecar就会出现这种现象(即使我使用节点端口服务访问pod)。另外,我做了一个测试,我使用 Nginx 将请求传输到 istio-ingressgateway 的 31380 端口,并配置网关 vs 和 dr 如下。但结果是一样的。
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: msapi
version: product
name: msapi
namespace: test
spec:
replicas: 1
selector:
matchLabels:
run: msapi
template:
metadata:
labels:
run: msapi
spec:
containers:
- env:
- name: JAVA_OPTS
valueFrom:
configMapKeyRef:
key: jvm.options
name: test-config
image: test/msapi:1.0.0
imagePullPolicy: Always
name: msapi
ports:
- containerPort: 9000
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: msapi
namespace: test
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9000
selector:
run: msapi
type: ClusterIP
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: ingress-test
namespace: test
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*.ingress.xxx.com'
port:
name: http
number: 80
protocol: HTTP
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: msapi
namespace: test
spec:
gateways:
- ingress-test
hosts:
- msapi.ingress.xxx.com
http:
- match:
- headers:
cookie:
regex: ^(.*?; ?)?(version=pre)(;.*)?$
route:
- destination:
host: msapi
subset: pre
- route:
- destination:
host: msapi
subset: product
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: msapi
namespace: test
spec:
host: msapi
subsets:
- labels:
version: product
name: product
- labels:
version: pre
name: pre
【问题讨论】:
-
你有哪些 K8s 和 istio 版本?你有哪些平台/基础设施?您可以安装istioctl 1.4.0 并尝试运行 istioctl x analyze -k 以查看它是否可以在 istio 网格中发现任何问题。您可以尝试使用 MTLS permisive mode 并进行检查,以便我们确定这不是政策问题。
-
k8s版本是1.13,istio版本是1.2.4。k8s是建立在私有云上的,是否需要将istio升级到1.4.0
-
不,istioctl 是命令行工具,它独立于 istio。上面提供了有关如何安装的链接,只有两行。如果发现了什么,请告诉我,您能否用 mtls 尝试其他建议,如果问题仍然存在,请告诉我?
-
github上的istio仓库误导了我很多。In this issue,istio的贡献者说websocketUpgrade前段时间被删除了,不再需要了。
-
你当然可以回答。谢谢你的帮助。
标签: kubernetes websocket istio