简体   繁体   English

为 Kubernetes 上的 Redis pod 动态获取正确的 IP

[英]Dynamically get the correct IP for a Redis pod on Kubernetes

Until now, our solution ran on three containers on the same IP.到目前为止,我们的解决方案在同一 IP 上的三个容器上运行。 One of the containers had Redis.其中一个容器有 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.当其他两个容器(通过 Redis 上的消息传递进行通信)需要到达 Redis 时,它们只需使用端口 6379。由于 Redis 具有相同的机器/IP,这很简单直接。

  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.现在需要在 Kuberenetes 上运行这三个 docker,每个 docker 容器现在都有自己唯一的 IP 地址。 How does one manage that correctly?如何正确地管理它?

  2. What if additional Redis containers are needed.如果需要额外的 Redis 容器怎么办。 How does each container knows which one to couple with?每个容器如何知道要与哪个容器耦合?

When switching to Kubernetes, you have to rely on the K8s architecture itself and think in a cloud-native manner.当切换到 Kubernetes 时,你必须依赖 K8s 架构本身,并以云原生的方式思考。 Consider that a pod is ephemeral: its IP will, potentially and eventually, change, anytime.考虑到一个 pod 是短暂的:它的 IP 可能并最终会随时发生变化。 You can not rely on a pod's IP.您不能依赖 pod 的 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.您可以做的是创建一个服务(clusterIP 非常适合此用例),它将作为 Redis pod 的每个副本的入口点。 The replicas should rely on the service, and K8s will take care of updating the list of: backing the service.副本应该依赖服务,K8s 将负责更新列表:支持服务。

You can find a great tutorial of doing this here .您可以在此处找到执行此操作的精彩教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM