<p>I was testing my kubernetes services recently. And I found it's very unreliable. Here are the situation:<br>
1. The test service 'A' which receives HTTP requests at port 80 has five pods deployed on three nodes.<br>
2. An nginx ingress was set to route traffic outside onto the service 'A'.<br>
3. The ingress was set like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-A
  annotations:    
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "1s"
    nginx.ingress.kubernetes.io/proxy-next-upstream: "error timeout invalid_header http_502 http_503 http_504"
    nginx.ingress.kubernetes.io/proxy-next-upstream-tries: "2"
spec:
  rules:
  - host: &lt;test-url&gt;
    http:
      paths:
      - path: /
        backend:
          serviceName: A
          servicePort: 80
</code></pre>

<ol start="3">
<li>http_load was started on an client host and kept sending request to the ingress nginx at a speed of 1000 per-seconds. All the request were routed to the service 'A' in k8s and eveything goes well.</li>
</ol>

<p>When I restarted one of the nodes manually, things went wrong:<br>
<strong>In the next 3 minutes, about 20% requests were timeout, which is unacceptable in product environment.</strong>  </p>

<p>I don't know why k8s reacts so slow and is there a way to solve this problem?</p>

George Liang
<p>You can speed up that fail-over process by configuring <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/" rel="nofollow noreferrer">liveness and readiness probes</a> in the pods' spec:</p>
<blockquote>
<h3><a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes" rel="nofollow noreferrer">Container probes</a></h3>
<p>...</p>
<p><strong>livenessProbe</strong>: Indicates whether the Container is running. If the liveness probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a liveness probe, the default state is Success.</p>
<p><strong>readinessProbe</strong>: Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod’s IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure. If a Container does not provide a readiness probe, the default state is Success.</p>
</blockquote>
<p>Liveness probe example:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre>
