Join us
You likely know that Services are how Kubernetes provides load balancing, exposing an application running on a set of Pods as a network service, and providing a single DNS name for that application.
If you have used a non-Kubernetes load balancer, you will also know that while active/active load balancing is probably the most common approach, active/passive load balancing is also a thing in that world. There can be a number of reasons one might want to do active/passive load balancing, for example licensing constraints, application requirements for consistent writes to local file systems, etc.
At first glance, however, it would appear that Kubernetes Services support only active/active approaches. There are ways to do active/passive load-balancing, however, if you are sufficiently motivated â but first you should consider some alternatives:
So, how can we do active/passive load-balancing? One of the easiest and most effective ways relies on 3 key facts:
What does the solution look like?
A word of caution â the example above is meant to be illustrative of the concept, not to be a production-ready implementation:
Hopefully, however, the provided code illustrates the general concept.
After deploying and waiting for just a moment or two, the helloworld-svc has one endpoint (which happens to correspond to Pod helloworld-statefulset-0):
After a while, the loadbalancer pod shows the following log:
and describing the helloworld-svc again shows the following:
As you can see, initially Pod helloworld-statefulset-0 was active. Its health check page at some point returned a 500 to signal that it was no longer healthy (in this example, that is done randomly, but presumably you would replace that health-check with a real implementation of something more applicable to your application). The script toggled the label value on the active pod to the role: passive, thereby removing it from the Service and the passive pod to the role: active, thereby adding it to the Service.
The full source code for the example is available over on GitHub.
Join other developers and claim your FAUN account now!
Architect, Sun Life Financial
@psdallyInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.