1

I have a K8s Service named orderProcessor with 5 pods. Based on the orderId HTTP Request header, I want to route the HTTP call to a specific pods.

For example:

requestId with orderId ABC should always go to Pod A and requestId with orderId PQR should always go to Pod B

If pod A is down and replaced with Pod C, then all request with orderId ABC should go to Pod C.

Basically, for the same header value, request should always end up in same pod.

Is this possible at service level? How to achieve this?

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48
  • Could you share your current configs? What have you tried already? We need more details regarding your use case in order to be able to help you out. – Wytrzymały Wiktor Jan 19 '21 at 15:37
  • It is not possible to do on service level. Kubernetes services works on Layer 4 and thus have no notion of "HTTP Headers". You may have more luck on the ingress controller which is Layer 7 and should have at least the technical capabilities to do what you ask. There are a number of Ingress Controller implementations that support sticky sessions based on cookies (like [nginx](https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/), but it is not exactly what you want based on your description – danielorn Jan 19 '21 at 17:16
  • Ingress controllers deliver traffic to Services not to Pods, so it couldn't help as well. I recon, the combination of a regular nginx pod configured as a reverse proxy and StatefulSet pods as a backend endpoints can do the trick. Every pod in StatefullSet has own permanent name and A record in Kubernetes DNS service, so you can refer to pod name in the nginx configuration. – VAS Feb 02 '21 at 11:36

1 Answers1

0

This is a community wiki answer. Feel free to expand it.

As already mentioned in the comments it is not possible to configure it at the Service level as it operates on Layer 4 which has no notion of "HTTP Headers".

The alternative would be to choose a fitting Ingress Controller for that task. For example you may choose from:

Bear in mind that different Controllers support different sets of annotations so if you mix them up than some of them will not be satisfied. You can find some of the key differences between the mentioned above here and here.

EDIT:

Including VASャ suggestion from the comments:

I recon, the combination of a regular nginx pod configured as a reverse proxy and StatefulSet pods as a backend endpoints can do the trick. Every pod in StatefullSet has own permanent name and A record in Kubernetes DNS service, so you can refer to pod name in the nginx configuration.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37