1

I have a service using Azure Kubernetes cluster and AKS load balancer. I want to forward some HTTP(client) requests to all instances. is there any way to configure this behavior using AKS or Kubernetes in general?

Say I have XYZ API running two replicas/instances.

  • XYZ-1 pod instance
  • XYZ-2 pod instance

I have some rest API requests to the app domain.com/testendpoint

Currently, using AKS load balancer it sends the requests in a round-robin fashion to XYZ-1 and XYZ-2. I am looking to see if it is possible to forward a request to both instances (XYZ-1 and XYZ-2) when the request endpoint is testendpoint and all other API requests use the same round-robin order.

The use case to refresh a service in-memory data via a rest call once a day or twice and the rest call will be triggered by another service when needed. so want to make sure all pod instances update/refresh in-memory data by an HTTP request.

vkt
  • 1,401
  • 2
  • 20
  • 46
  • What do you mean? Isn't this what a "load blancer" does? What do you mean with "to all instances" - that it should broadcast your request or use round robin to distribute load to the instances? "all instances" - you mean all replicas of an app, or to all different pods - for different apps - why would you like that? – Jonas Nov 30 '20 at 21:07
  • There are some requests that I want to forward to all pod instances. I updated my question now. – vkt Nov 30 '20 at 21:16
  • 1
    How do you plan do handle the responses? If the client receives both responses - its an error - must not happen. – Jonas Nov 30 '20 at 21:21
  • What's the purpose of the call? Should there be a return value? If it is to do some work on all instances try a messaging service like event grid and have all instances listen to an event. – Peter Bons Nov 30 '20 at 21:51
  • This is to refresh in-memory data via a call once a day or twice and the call will be triggered by another service when needed. so want to make sure all pod instances update/refresh in memory data by HTTP request. – vkt Nov 30 '20 at 21:52

1 Answers1

2

if it is possible to forward a request to both instances (XYZ-1 and XYZ-2) when the request endpoint is testendpoint

This is not a feature in the HTTP protocol, so you need a purpose built service to handle this.

The use case to refresh a service in-memory data via a rest call once a day or twice and the rest call will be triggered by another service when needed. so want to make sure all pod instances update/refresh in-memory data by an HTTP request.

I suggest that you create a new utility service, "update-service" - that you send the call once a day to. This service then makes a request to every instance of XYZ, like XYZ-1 and XYZ-2.

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Hi Jonas, thanks for the response. Is there any AKS (or K8S) API's available to achieve this to find all instances and send requests to those? – vkt Nov 30 '20 at 22:08
  • If `XYZ` is deployed as a StatefulSet (instead of Deployment), then this is easy, since your Pods will have the name as you wrote, `XYZ-0`, `XYZ-1` ...depending on how many replicas you have. For Deployment, it is easies to query Pods with the same labels as in your "selector", using a library, e.g. https://github.com/kubernetes/client-go or https://github.com/kubernetes-client/java – Jonas Nov 30 '20 at 22:12
  • Instead of using a Kubernetes client (and setting up the required permissions / service accounts) you might consider using an additional headless service that doesn’t have its own cluster ip and load balancing but instead returns all healthy pod ips when doing a dns lookup. See https://dev.to/kaoskater08/building-a-headless-service-in-kubernetes-3bk8 – Andreas Jägle Nov 30 '20 at 23:00