在具有Nginx入口的GKE上使用socket.io [英] Using socket.io on GKE with nginx ingress

查看:57
本文介绍了在具有Nginx入口的GKE上使用socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将socket.io集成到部署在Google Kubernetes Engine上的应用程序中.在本地开发,一切都很好.但是一旦部署,当我的套接字尝试连接时,我将不断收到可怕的400响应.我已经在SO和其他网站上搜索了几天,但没有找到能解决我问题的信息.

I'm trying to integrate socket.io into an application deployed on Google Kubernetes Engine. Developing locally, everything works great. But once deployed, I am continuously getting the dreaded 400 response when my sockets try to connect on. I've been searching on SO and other sites for a few days now and I haven't found anything that fixes my issue.

不幸的是,该体系结构是由不再在我们公司工作的开发人员建立的,而且我当然不是Kubernetes或GKE专家,所以我不确定我是否正确设置了一切.

Unfortunately this architecture was set up by a developer who is no longer at our company, and I'm certainly not a Kubernetes or GKE expert, so I'm definitely not sure I've got everything set up correctly.

这里是设置:

  • 我们有5个应用程序pod,可为分布在5个云节点(GCE vm实例)上的应用程序提供服务

  • we have 5 app pods that serve our application distributed across 5 cloud nodes (GCE vm instances)

我们正在使用nginx入口控制器( https://github.com/kubernetes/ingress-nginx )创建一个负载均衡器,以在我们的节点之间分配流量

we are using the nginx ingress controller (https://github.com/kubernetes/ingress-nginx) to create a load balancer to distribute traffic between our nodes

这是我到目前为止尝试过的:

Here's what I've tried so far:

  • 在入口处添加以下注释:

nginx.ingress.kubernetes.io/affinity: "cookie" nginx.ingress.kubernetes.io/session-cookie-hash: "sha1" nginx.ingress.kubernetes.io/session-cookie-name: "route"

nginx.ingress.kubernetes.io/affinity: "cookie" nginx.ingress.kubernetes.io/session-cookie-hash: "sha1" nginx.ingress.kubernetes.io/session-cookie-name: "route"

  • sessionAffinity: ClientIP添加到入口引用的后端服务
  • adding sessionAffinity: ClientIP to the backend service referenced by the ingress

这些措施似乎没有任何区别,我仍然收到400的回复.如果有人遇到过类似的情况或有任何建议可以向我指出正确的方向,我将非常感激!

These measures don't seem to have made any difference, I'm still getting a 400 response. If anyone has handled a similar situation or has any advice to point me in the right direction I'd be very, very appreciative!

推荐答案

我只是使用与我们使用socket.io相同的配置来设置ngin入口.

I just setup ngin ingress with same config where we are using socket.io.

这是我的入口配置

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: core-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.org/websocket-services : "app-test"
    nginx.ingress.kubernetes.io/rewrite-target: /
    certmanager.k8s.io/cluster-issuer: core-prod
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/websocket-services : "socket-service"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"

spec:
  tls:
  - hosts:
    - <domain>
    secretName: core-prod
  rules:
  - host: <domain>
    http:
      paths:
      - backend:
          serviceName: service-name
          servicePort: 80

我也遇到了同样的问题,因此添加了proxy-send-timeoutproxy-read-timeout.

i was also facing same issue so added proxy-send-timeout and proxy-read-timeout.

这篇关于在具有Nginx入口的GKE上使用socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆