I have an azure load balancer service that sends requests to the active pod in a pair of pods:
pod0
is labeled active as part of the startup processpod1
is labeled not active, sopod0
is active andpod1
is backup.
When pod0
goes down the azure lb keeps sending requests to pod0
even though the 2 pods know that pod1
is now active.
I’m not sure how the azure lb is supposed to get updated to point to pod1
as now being the active pod, as both pods can see who is active and who is backup. Suggestions, ideas please?
K8s configuration changes not helping in this case such as changing app name and selectors to match
Azure load balancer map to active pod
The Azure Load Balancer requires knowledge of your pods’ status to efficiently direct traffic to the active ones. Consider these approaches to address this issue:
Health Probes: Employ health probes in your Azure Load Balancer to monitor the status of backend instances. Configure a probe on your pods to check a specific endpoint that reflects the pod’s operational status. Only if the pod is active should this endpoint show a healthy response (e.g., HTTP 200).
If pod0 fails, its health probe will fail, causing the load balancer to route traffic to pod1, assuming pod1’s probe is healthy.
Custom Solution with External Watcher: Create an external service or a watcher pod to monitor the status of pod0 and pod1. This watcher should be able to adjust the load balancer’s configuration or DNS settings in real-time, ensuring traffic is redirected to the operational pod.
- This goal can be accomplished through Azure API Management or by developing a custom API that dynamically adjusts DNS or routing configurations in response to pod states.
Azure Traffic Manager: Should the standard Load Balancer configurations prove inadequate; you might explore Azure Traffic Manager. It is capable of managing more intricate routing strategies and can be set up to manage failover more smoothly in accordance with your application’s logic.
Kubernetes Services: Double-check your Kubernetes service and deployment configurations to ensure they are set to handle failovers correctly. Typically, a Kubernetes service should automatically redirect traffic to healthy pods when configured with the right selectors and readiness/liveness probes.
simplified Kubernetes configuration
apiVersion: v1
kind: Service
metadata:
name: your-service
spec:
selector:
app: your-app
ports:
- protocol: TCP
port: 80
targetPort: 9376
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-deployment
spec:
replicas: 2
selector:
matchLabels:
app: your-app
template:
metadata:
labels:
app: your-app
spec:
containers:
- name: your-container
image: your-image
ports:
- containerPort: 9376
readinessProbe:
httpGet:
path: /health
port: 9376
initialDelaySeconds: 3
periodSeconds: 3
This example presupposes the existence of a /health
endpoint in your application that indicates the pod’s active status. Modify the settings to align with your application’s actual logic and endpoints.
Reference:
https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-custom-probe-overview#configure-probe
https://learn.microsoft.com/en-us/azure/traffic-manager/traffic-manager-routing-methods
https://learn.microsoft.com/en-us/azure/application-gateway/tutorial-url-route-cli
https://learn.microsoft.com/en-us/azure/application-gateway/overview