Kubernetes入口Websockets连接问题 [英] Kubernetes ingress websockets connection issue

查看:1447
本文介绍了Kubernetes入口Websockets连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有KOPS的AWS上部署了k8. 我已经创建了nginx入口 https://github.com/kubernetes/ingress-nginx nginx入口控制器图像:quay.io/kubernetes入口控制器/nginx入口控制器:0.18.0

Deployed k8s on AWS with KOPS. I have created nginx ingress https://github.com/kubernetes/ingress-nginx nginx-ingress-controller image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.18.0

一切正常,我可以使用由nginx服务创建的aws classic负载均衡器从外部访问应用程序.

Everything is up and running and I could able to access applications externally using aws classic load balancer which is created by nginx service.

最近,我们开始研究websocket.我在k8s中部署了服务,并尝试从外部进行访问.

Recently we started working on websockets. I deployed my services in k8s and trying to access externally.

我为我的应用程序创建了服务和入口.现在,Ingress指向的是loadbalancer(位于json文件下方).

I created service and ingress for my application. Ingress is now pointing to loadbalancer(below json file).

我在aws中创建了route53条目并尝试连接到该条目,但是当我尝试通过chrome浏览器从客户端应用程序进行连接时,却出现错误提示

I created route53 entry in aws and trying to connect to that but I am getting below error when I am trying to connect from my client application through chrome browser

与'wss://blockchain.aro/socket.io/?EIO = 3& transport = websocket'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:400

WebSocket connection to 'wss://blockchain.aro/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

我尝试创建应用程序负载平衡器,但无法连接到wss://<host>

I tried creating Application load balancer but I could not able to connect to wss://<host>

错误:

WebSocket连接到 'wss://blockchain.aro/socket.io/?EIO = 3& transport = websocket'失败: WebSocket握手期间出错:意外的响应代码:400

WebSocket connection to 'wss://blockchain.aro/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

const config: SocketIoConfig = { url: 'wss://blockchain.aro',
  options: { autoConnect: false, transports: ['websocket']} };


Ingress:

   "annotations": {
      "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Ingress\",\"metadata\":{\"annotations\":{},\"name\":\"blockchain\",\"namespace\":\"adapt\"},\"spec\":{\"rules\":[{\"host\":\"blockchain.aro\",\"http\":{\"paths\":[{\"backend\":{\"serviceName\":\"blockchain\",\"servicePort\":8097},\"path\":\"/\"},{\"backend\":{\"serviceName\":\"blockchain\",\"servicePort\":8097},\"path\":\"/socket.io\"},{\"backend\":{\"serviceName\":\"blockchain\",\"servicePort\":8097},\"path\":\"/ws/\"}]}}],\"tls\":[{\"hosts\":[\"blockchain.aro\"],\"secretName\":\"blockchain-tls-secret\"}]}}\n",
      "nginx.ingress.kubernetes.io/proxy-read-timeout": "3600",
      "nginx.ingress.kubernetes.io/proxy-send-timeout": "3600"
    }

包含在入口文件中的tlssecretnamerules.我尝试创建ApplicationLoadbalancer,但也无法与此连接.

included tls and secretname and rules in ingress file. I tried creating ApplicationLoadbalancer but I could not able to connect with that too.

推荐答案

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    certmanager.k8s.io/cluster-issuer: core-prod
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/websocket-services: core-service
    nginx.org/websocket-services: core-service
  name: core-ingress
spec:
  rules:
  - host: test.io
    http:
      paths:
      - backend:
          serviceName: core-service
          servicePort: 80
  tls:
  - hosts:
    - test.io
    secretName: core-prod

这篇关于Kubernetes入口Websockets连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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