<p>I followed <a href="https://blog.polyscribe.io/a-complete-guide-to-deploying-elixir-phoenix-applications-on-kubernetes-part-1-setting-up-d88b35b64dcd" rel="noreferrer">this</a> series of articles to create a deployment at Google Cloud. Everything is working as expected, except phoenix channels.</p>

<p>No errors on the backend side. On Javascript frontend I am getting first channel ERROR and then the socket CLOSES on frontend while using channels. And this keeps repeating endlessly in an interval of 10–20 secs.</p>

<pre><code>CHANNEL ERROR!
SOCKET CLOSE!
CHANNEL ERROR!
SOCKET CLOSE!
</code></pre>

<p>From this code:</p>

<pre><code>socket.connect()
socket.onError( e =&gt; console.log("SOCKET ERROR", e) )
socket.onClose( e =&gt; console.log("SOCKET CLOSE", e))
channel = socket.channel("note:" + noteId, {})
channel.onError( e =&gt; console.log("CHANNEL ERROR!", e) )
channel.onClose( e =&gt; console.log("CHANNEL CLOSED!", e) )
</code></pre>

<p>I need help to debug this and figure out where this problem is originating from. Please let me know if any piece of code is needed and I will update the question with that code. Its been a week now. :(</p>

<p>Thanks a lot!</p>

<p>(No problem when run locally)</p>

<p><strong>UPDATE:</strong> The only difference I am seeing is that on local server, phoenix.js is continuously sending heartbeat but this is not happening on server.</p>

<p><strong>UPDATE:</strong></p>

<pre><code>---- my-ingress.yaml ----
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    # ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.global-static-ip-name: my-ingress-ip
    kubernetes.io/tls-acme: "true"
spec:
  rules:
  - host: apiv2.example.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: my-service-nodeport
          servicePort: 80
      - path: /.well-known/acme-challenge
        backend:
          serviceName: kube-lego-gce
          servicePort: 8080
  tls:
  - secretName: my-secret-tls-7
    hosts:
    - apiv2.example.com
</code></pre>

<p>This is <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="noreferrer">ingress file</a> I am using and also using <a href="https://github.com/jetstack/kube-lego" rel="noreferrer">kube-lego</a> with it.</p>

<p><strong>UPDATE:</strong> I implemented this code (I checked frames in dev tools, they were being sent). But still... its giving SOCKER ERROR. May be issue is not with sending hearbeats.</p>

<pre><code>const HEARTBEAT_INTERVAL_MS = 5000
socket.onOpen(() =&gt; {
      clearInterval(this.heartbeatTimer);
      this.heartbeatTimer = setInterval(() =&gt; { 
        return socket.push({ 
          topic: "phoenix", 
          event: "heartbeat", 
          payload: {}, 
          ref: socket.makeRef(), 
        }); 
      }, 
        HEARTBEAT_INTERVAL_MS
      );
    })
</code></pre>

<p>You may need to increase the response timeout for your <a href="https://cloud.google.com/compute/docs/load-balancing/http/#timeouts_and_retries" rel="nofollow noreferrer">backend service</a> on GCP.</p>

<p>By default, the timeout was set at 30sec and was causing the same problem for me.</p>
