<p>I am trying to make socket connection from react application to nodejs server hosted on GKE. I am getting connection error &quot;Connection closed before it was established&quot;.
HTTP connection working fine.
dev.host.com is used for frontend and dev.host.com/api is used for backend and included in ingress.yml file below. Can it might be the issue due to this setup or I missed any configuration. I haved configured 3 Replicas.</p>
<p><strong>GKE Configuration for frontend:</strong>
<em>frontend-deployment.yaml</em></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - image: image-frontend:latest
        name: vektor-fe
        imagePullPolicy: Always
        livenessProbe:
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: frontend-service
spec:
  selector:
    app: frontend
  ports:
  - port: 3000
    targetPort: 80
  type: ClusterIP

</code></pre>
<p><em>ingress.yml</em></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
spec:
  tls:
  - hosts:
    - dev.host.com
    secretName: my-ingress-tls      
  rules:
  - host: dev.host.com
    http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: frontend-service
            port:
              number: 3000
      - path: /api
        pathType: ImplementationSpecific
        backend:
          service:
            name: backend-service
            port:
              number: 4001

</code></pre>
<p><strong>Backend Configuration</strong>
<em>backend-deploy.yaml</em></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - image: my-app:latest
        name: vektor-be
        imagePullPolicy: Always
        ports:
        - containerPort: 4000
---
apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  ports:
  - port: 4001
    targetPort: 4000
  selector:
    app: app
  type: ClusterIP


</code></pre>
<p>Tried socket connection to dev.host.com at port 4001 but got error &quot;Connection closed before it was established&quot;. socket.io-client is used in react and socket.io is used in backend.</p>

Sudip Thapa
<p>try the ingress config like</p>
<pre><code>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: &quot;1800&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;1800&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/secure-backends: &quot;true&quot;
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/websocket-services: ws-service
    nginx.org/websocket-services: ws-service
  name: core-ingress
spec:
  rules:
  - host: test.io
    http:
      paths:
      - backend:
          serviceName: ws-service
          servicePort: 80
  tls:
  - hosts:
    - test.io
    secretName: core-secret
</code></pre>
