Kubernetes中的插座IO保持断开连接

发布于 2025-02-13 23:30:14 字数 449 浏览 2 评论 0原文

我想在Kubernetes启动簇的插座IO应用程序。当我创建服务(无论是nodeport还是LoadBalancer)时,客户端应用程序会不断断开连接,并且再次重新连接以下日志:

undefined
oah4g28zZCw36g1MAAAm
undefined
undefined
oac4g28zZCw36g1MFAAAx
undefined

这迅速发生。

但是,当我直接连接到一个吊舱时,问题就会消失,连接变得稳定。

我如何通过以下命令来创建服务:

kubectl expose deployment xxx --type=LoadBalancer --port=80 --target-port=3000

我知道服务中缺少诸如keetalive或超时配置之类的东西,但是我该如何添加或更好地说出适当地配置套接字IO的服务?

I'd like to launch a clustered Socket IO application in Kubernetes. When I create a service (whether NodePort or LoadBalancer) the client application keeps getting disconnected and it reconnects again with the following logs:

undefined
oah4g28zZCw36g1MAAAm
undefined
undefined
oac4g28zZCw36g1MFAAAx
undefined

and this happens rapidly.

However, when I connect to a single Pod directly, the problem goes away and the connection becomes stable.

How I am creating the service is by the following command:

kubectl expose deployment xxx --type=LoadBalancer --port=80 --target-port=3000

I know that something such as a KeepAlive or Timeout configuration is missing in the service, but how can I add those or better said properly configure the service for Socket IO?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羅雙樹 2025-02-20 23:30:14

您可以使用sessionaffition:clientip,它将从K8S服务管理会话。

kind: Service
apiVersion: v1
metadata:
  name: example
spec:
  selector:
    app: example
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 1800

仅适用于参考: WS WebSocket服务器库在加载平衡器后面使用时是否需要粘性会话?

You can use the sessionAffinity: ClientIP, which will manage the session from K8s service.

kind: Service
apiVersion: v1
metadata:
  name: example
spec:
  selector:
    app: example
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 1800

just for ref : Does the ws websocket server library requires sticky session when it is used behind a load balancer?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文