【问题标题】:GKE Ingress dropping websocket connections when using https使用 https 时 GKE Ingress 丢弃 websocket 连接
【发布时间】:2018-08-01 08:17:21
【问题描述】:

我有一个入口(默认的 GKE 入口),它在我的服务之前处理所有 SSL。我的服务之一是 WebSocket 服务(python 高速公路)。当我使用 LoadBalancer 公开服务而不传递入口时,使用 ws:// 一切工作正常。相反,当我使用 NodePort 公开它并通过入口时,即使没有客户端连接,我也经常看到连接正在下降。以下是高速公路日志:

WARNING:autobahn.asyncio.websocket.WebSocketServerProtocol:dropping connection to peer tcp:10.156.0.58:36868 with abort=False: None

当我使用带有 wss:// 的客户端连接时,连接成功,但 每隔几秒钟就会发生一次断开连接(无法获得一致的数字)。 虽然我不认为它是相关的,但我将 GCE 中相关后端服务的超时更改为 3600 秒,并尝试使用 clientIP 和 cookie 为其提供会话亲和性,但似乎没有一个可以阻止断开连接。 这是我的入口定义:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ .Values.ingressName }}-ingress
  annotations:
      kubernetes.io/ingress.global-static-ip-name: {{ .Values.staticIpName }}-static-ip
  labels:
    oriient-app: "rest-api"
    oriient-system: "IPS"
spec:
  tls:
  - secretName: sslcerts
  rules:
  - host: {{ .Values.restApiHost }}
    http:
      paths:
      - backend:
          serviceName: rest-api-internal-service
          servicePort: 80
  - host: {{ .Values.dashboardHost }}
    http:
      paths:
      - backend:
          serviceName: dashboard-internal-service
          servicePort: 80
  - host: {{ .Values.monitorHost }}
    http:
      paths:
      - backend:
          serviceName: monitor-internal-service
          servicePort: 80
  - host: {{ .Values.ipsHost }}
    http:
      paths:
      - backend:
          serviceName: server-internal-ws-service
          servicePort: 80

ws 服务是“server-internal-ws-service”。 有什么建议吗?

【问题讨论】:

    标签: websocket google-compute-engine kubernetes-ingress google-kubernetes-engine


    【解决方案1】:

    我没有解决这个问题,但我确实通过使用 LoadBalancer 服务公开我的 wss 并自己实现了 WebSocket 的安全层来绕过它。 我将证书(私钥和全链公钥 - pem 格式)保存为秘密并将其安装为卷,然后在 python 中使用 SSLContex 并将其传递给 asyncio 循环创建服务器。

    为了创建证书秘密,请创建一个 yaml:

    apiVersion: v1
    kind: Secret
    type: tls
    metadata:
      name: sslcerts
    data:
      # this is base64 of your pem fullchain and private key
      tls.crt: XXX 
      tls.key: YYY
    

    然后

    kubectl apply -f [path to the yaml above]
    

    在您的服务器部署中安装密钥:

        apiVersion: apps/v1beta2
        kind: Deployment
        metadata:
          labels:
            ...
          name: server
        spec:
          replicas: {{ .Values.replicas }}
          selector:
            matchLabels:
              ...
          template:
            metadata:
              labels:
                ...
            spec:
              volumes:
              - name: wss-ssl-certificate
                secret:
                  secretName: sslcerts
           containers:
            - image: ...
            imagePullPolicy: Always
            name: server
            volumeMounts:
              - name: wss-ssl-certificate
                mountPath: /etc/wss
    

    在python代码中:

     sslcontext = ssl.SSLContext()
     sslcontext.load_cert_chain(/etc/wss/tls.crt, /etc/wss/tls.key)
     wssIpsClientsFactory = WebSocketServerFactory()
     ...        
     loop = asyncio.get_event_loop()
     coro = loop.create_server(wssIpsClientsFactory, '0.0.0.0', 9000, ssl=sslcontext)
     server = loop.run_until_complete(coro)
    

    希望对某人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多