<p>I am running 2 pod(replicas) of particular deployment on Kubernetes with nginx ingress. Service using web socket also.</p>

<p>Out of 2 pod I have deleted one pod so it starts creating again while 1 was in a ready state. In between this, I tried to open the URL and got an error 504 gateway timeout.</p>

<p>As per my understanding traffic has to divert to Ready state pod from Kubernetes service. Am I missing something please let me know?</p>

<p>Thanks in advance. </p>

<p>Here is my ingress if any mistake </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: core-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: core-prod
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    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
    nginx.org/websocket-services: core
spec:
  tls:
  - hosts:
    - app.wotnot.io
    secretName: core-prod
  rules:
  - host: example.io
    http:
      paths:
      - backend:
          serviceName: core
          servicePort: 80
</code></pre>

Harsh Manvar
<p>Services do not guarantee 100% uptime, especially if there are only 2 pods. Depending on the timing of your request, one of a number of possible outcomes is occurring.</p>

<ol>
<li><p>You try to open the URL before the pod is marked as notReady. What happens, in this case, is your service forwards the request to your pod which is about to terminate. Since the pod is about to terminate and the webserver is shutting down, the pod is no longer able to respond so nginx responds with 504. It is also possible that a session is already started with this pod and it is interrupted because of the <code>sigterm</code>. </p></li>
<li><p>You send a request once the second pod is in terminating state. Your primary pod is being overworked from handling 100% of the requests so a response does not come fast enough so nginx returns an error.</p></li>
</ol>

<p>In any scenario, your best option is to check the nginx ingress container logs to see why 504 is being returned so you can further debug this. </p>

<p>Note that, as mentioned just above, services do only include pods marked as Ready, however, this does not guarantee that 100% of requests will always be served correctly. Any time a pod is taken down for any reason, there is always a chance that a 5xx error is returned. Having a greater number of pods will reduce the odds of an error being returned but it will rarely completely eliminate the odds.</p>
