working on app engine but not with gke : Error during WebSocket handshake: Unexpected response code: 400

11/1/2019

main.58c4de976d0b122d6630.js:1 WebSocket connection to 'ws://35.226.60.64/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

In the client-side socket connection code, we have specified this:

this.socketObject = io.connect(this.backendUrl+'/live',{
            transports:['websocket']
        });

getting this error of websocket in gke The configuration files are as below

kind: Ingress
metadata:
  name: heartland-media
  annotations:
          kubernetes.io/ingress.class: nginx
          nginx.ingress.kubernetes.io/affinity: cookie
          nginx.ingress.kubernetes.io/affinity: balanced
          nginx.org/websocket-services: "heartland-media"
spec:
  rules:
  - http:
       paths:
       - path: /
         backend:
            serviceName: heartland-media
            servicePort: 80
kind: Deployment  #It will create pod with the following specifications
apiVersion: apps/v1
metadata:
  name: heartland-media
  namespace: default
  labels:
    run: heartland-media
spec:
  replicas: 2  #it will create an extra pod with same template
  selector:
    matchLabels:
      run: heartland-media 
  template:
    metadata:
      labels:
        run: heartland-media
    spec:
      containers:
        - name: heartland-media
          image: gcr.io/pe-training/heartland-final:v2
          livenessProbe:
              httpGet:
                 path: /
                 port: 80
              initialDelaySeconds: 15
              periodSeconds: 20
          ports:
                  - containerPort: 80
                    protocol: TCP



---

apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
  - default:
      memory: "1Gi"
    type: Container
apiVersion: v1
kind: Service
metadata:
  name: heartland-media
  labels:
    run: heartland-media 
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30877
    targetPort: 80
    protocol: TCP
    name: ports
  selector:
    run: heartland-media
  sessionAffinity: None
-- Ankita Shinde
google-kubernetes-engine
socket.io
websocket

0 Answers