Reputation: 8411
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 "Primary".
How can it be achieved?
Upvotes: 0
Views: 824
Reputation: 252
You can modify your pod definition to contain a leader election sidecar container and achieve this with a readiness probe.
Only the leader in the group of pods will return a valid status for the readiness probe port. A kubernetes service
resource will only route requests to pods that are reporting ready.
When one pod terminates, another leader election will take place, the selected pod's readiness will activate, and the service
will begin routing traffic to the newly elected leader.
Example probe definition (container checking whether it is leader).
readinessProbe:
exec:
command:
- /bin/sh
- -c
- curl -v --silent http://localhost:4040/ 2>&1 | grep $HOSTNAME
Upvotes: 3