<p>I want to create a Deployment with 3 Pods, but that only one of them receives traffic. If this Pod goes down, then the ClusterIP Service should route new requests to one of the remaining Pods (which act like a backup Pods for availability only) and it will act as the new &quot;Primary&quot;.</p>
<p>How can it be achieved?</p>

Raz Buchnik
<p>You can modify your pod definition to contain a <a href="https://github.com/kubernetes-retired/contrib/tree/master/election" rel="nofollow noreferrer">leader election sidecar container</a> and achieve this with a <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes" rel="nofollow noreferrer">readiness probe</a>.</p>
<p>Only the leader in the group of pods will return a valid status for the readiness probe port. A kubernetes <code>service</code> resource will only route requests to pods that are reporting ready.</p>
<p>When one pod terminates, another leader election will take place, the selected pod's readiness will activate, and the <code>service</code> will begin routing traffic to the newly elected leader.</p>
<p>Example probe definition (container checking whether it is leader).</p>
<pre><code>readinessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - curl -v --silent http://localhost:4040/ 2&gt;&amp;1 | grep $HOSTNAME
</code></pre>
