Dynamically get the correct IP for a Redis pod on Kubernetes

499 views Asked by At

Until now, our solution ran on three containers on the same IP. One of the containers had Redis. When the other two containers (communicating via message passing on Redis) needed to reach the Redis, they simply utilized port 6379. Since the Redis had the same machine/IP this was simple and straight forward.

  1. Now there is a need to run these three dockers on Kuberenetes and each docker container is now getting its own unique IP address. How does one manage that correctly?

  2. What if additional Redis containers are needed. How does each container knows which one to couple with?

1

There are 1 answers

0
Gregorio Palamà On

When switching to Kubernetes, you have to rely on the K8s architecture itself and think in a cloud-native manner. Consider that a pod is ephemeral: its IP will, potentially and eventually, change, anytime. You can not rely on a pod's IP.

What you can do is create a service (a clusterIP works great for this use case) that will serve as the entry point for every replicas of your Redis pod. The replicas should rely on the service, and K8s will take care of updating the list of : backing the service.

You can find a great tutorial of doing this here.