【问题标题】:websocket connection failed after establishing https in google ingress controller在谷歌入口控制器中建立 https 后 websocket 连接失败
【发布时间】:2018-11-03 12:57:38
【问题描述】:

我在 kubernetes 中部署了一个应用程序,该应用程序由 Google Ingress Controller(服务为 ELB)提供服务。该应用程序运行良好。但是在我应用 https 相关配置的那一刻,https 来了,但是 websocket 失败了。

下面是服务文件和配置图

对于http:

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
  annotations:
    # Enable PROXY protocol
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
    # Increase the ELB idle timeout to avoid issues with WebSockets or Server-Sent Events.
    service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: '3600'
spec:
  type: LoadBalancer
  selector:
    app: ingress-nginx
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https

---------------------------------------------------------------------------------------------------


kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
data:
  use-proxy-protocol: "true"

对于 https:

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-east-1:2xxxxxxxxxxxxxxxxxxx56:certificate/3fxxxxxxxxxxxxxxxxxxxxxxxxxx80" 
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "http"
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "https" 
    # Increase the ELB idle timeout to avoid issues with WebSockets or Server-Sent Events.
    service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: '3600'
spec:
  type: LoadBalancer
  selector:
    app: ingress-nginx
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: http

------------------------------------------------------------------------------------------

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
data:
  use-proxy-protocol: "false"

我是否缺少 configmap 中的任何注释或数据?请帮帮我

【问题讨论】:

    标签: nginx websocket kubernetes amazon-elb kubernetes-ingress


    【解决方案1】:

    我认为问题出在注释上:

    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "http"
    

    ELB 中的后端协议必须是 TCP 才能进行 websocket 连接。

    另外,我看到你正在使用 Nginx Ingress Controller,也许你想在配置中设置这些变量

    proxy-read-timeout: "3600"
    proxy-send-timeout: "3600"
    

    为了避免连接关闭。

    【讨论】:

    • 嗨!如果答案解决了问题,请标记为正确
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 2019-08-30
    • 1970-01-01
    • 2018-06-13
    • 2014-12-19
    • 2016-01-29
    相关资源
    最近更新 更多