0

I've installed the Bitnami\Redis helm chart on a cluster with the value of master.kind = DaemonSet. Now I have a redis pod for each node. like this

  • NODE A - REDIS-POD-A
  • NODE B - REDIS-POD-B
  • NODE C - REDIS-POD-C

The chart installed three services:

  • redis-internal-master (1 IP address)
  • redis-internal-replica (1 IP address)
  • redis-internal-headless (3 IP addresses - mapped for each pod)

I have an app - MYAPP - running in NODE C. How can I connect to the redis pod that's running on NODE C? I can use the master-service IP address but I don't know where that sends me really (does it send me to a different one each time? then data won't be consistent).

I can fetch the 3 IP addresses of the headless service using getent hosts redis-internal-headless.default.svc.cluster.local but then how the hell do I know which one is running on the same node as MYAPP?

My nodes change too, I have autoscaling, nodes can come and go. How do I make sure every app on NODE A always connects to REDIS-POD-A, every app on NODE B to always connect to REDIS-POD-B, etc.?

I thought this would be pretty trivial, but it turns out to be pretty complicated? I'm losing my hair trying to figure this out. Please help

yuvi
  • 101
  • 1

1 Answers1

0

I figured it out, and I'm surprised in all the places where this subject was discussed no one suggests this, as it's a pretty common and reasonable use case when running a DaemonSet, and this is the nicest and most elegant solution I've found - if you have a service with a Cluster IP you can set InternalTrafficPolicy: Local on it, which:

The kube-proxy filters the endpoints it routes to based on the spec.internalTrafficPolicy setting. When it's set to Local, only node local endpoints are considered. When it's Cluster (the default), or is not set, Kubernetes considers all endpoints.

source

In the case of the bitnami\redis chart, its easy to inject this directly through the values.yaml, which means accessing the service always connects a pod to the redis running on the same node (and it's easy to fetch the IP as the the address is propagated as an ENV directly to the pods).

yuvi
  • 101
  • 1