我正在尝试在 Kubernetes 集群中运行的服务器上建立一个简单的 Websocket 连接。
Websocket 连接能够在我的本地测试计算机上建立,但在使用 nginx-ingress 部署到 GKE 后,我无法将客户端连接到服务器。
入口 yaml 文件:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.org/websocket-services : "socket-cluster-ip-service"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/websocket-services : "socket-cluster-ip-service"
nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
spec:
rules:
- host: my-socket.com
http:
paths:
- path: /
backend:
serviceName: socket-cluster-ip-service
servicePort: 3000
- host: www.my-socket.com
http:
paths:
- path: /
backend:
serviceName: socket-cluster-ip-service
servicePort: 3000
Run Code Online (Sandbox Code Playgroud)
服务yaml文件:
apiVersion: v1
kind: Service
metadata:
name: socket-cluster-ip-service
spec:
type: ClusterIP
selector:
component: socket
ports:
- …Run Code Online (Sandbox Code Playgroud)