我如何 select 这个 Kubernetes 示例中的主 Redis pod?
How do I select the master Redis pod in this Kubernetes example?
这是我模仿的 example。
在自述文件的 "Delete our manual pod" 部分:
- The redis sentinels themselves, realize that the master has disappeared from the cluster, and begin the election procedure for selecting a new master. They perform this election and selection, and chose one of the existing redis server replicas to be the new master.
我如何select新主人?来自 redis-controller.yaml
的 redis
复制控制器控制的所有 3 个 Redis 服务器 pods 仍然具有相同的
labels:
name: redis
这是我目前在我的服务中使用的 select 他们。 3 pods 如何区分,以便从 Kubernetes 我知道哪个是主控?
How will the 3 pods be distinguishable so that from Kubernetes I know
which one is the master?
Kubernetes 不知道主节点。您可以通过连接到 Pod 并使用以下命令手动找到 Pod:
redis-cli info
您将获得有关服务器的大量信息,但我们需要角色:
redis-cli info | grep ^role
Output:
role: Master
请注意,对于无状态服务,Replication controllers
已替换为 Deployments
。对于有状态服务,请使用 Statefulsets
。
您的客户端 Redis 库实际上可以处理这个问题。例如 ioredis:
ioredis guarantees that the node you connected to is always a master even after a failover.
因此,您实际上连接到 redis-sentinel
而不是 redis-client
。
我们需要做同样的事情并尝试不同的事情,比如修改图表。最后,刚刚创建了一个简单的 python docker 来进行标记,并创建了将主 redis 公开为服务的图表。这会定期检查为 redis-ha 创建的 pods 并根据它们的角色(主/从)标记它们
它使用相同的哨兵命令来查找 master/slave。
这是我模仿的 example。
在自述文件的 "Delete our manual pod" 部分:
- The redis sentinels themselves, realize that the master has disappeared from the cluster, and begin the election procedure for selecting a new master. They perform this election and selection, and chose one of the existing redis server replicas to be the new master.
我如何select新主人?来自 redis-controller.yaml
的 redis
复制控制器控制的所有 3 个 Redis 服务器 pods 仍然具有相同的
labels:
name: redis
这是我目前在我的服务中使用的 select 他们。 3 pods 如何区分,以便从 Kubernetes 我知道哪个是主控?
How will the 3 pods be distinguishable so that from Kubernetes I know which one is the master?
Kubernetes 不知道主节点。您可以通过连接到 Pod 并使用以下命令手动找到 Pod:
redis-cli info
您将获得有关服务器的大量信息,但我们需要角色:
redis-cli info | grep ^role
Output:
role: Master
请注意,对于无状态服务,Replication controllers
已替换为 Deployments
。对于有状态服务,请使用 Statefulsets
。
您的客户端 Redis 库实际上可以处理这个问题。例如 ioredis:
ioredis guarantees that the node you connected to is always a master even after a failover.
因此,您实际上连接到 redis-sentinel
而不是 redis-client
。
我们需要做同样的事情并尝试不同的事情,比如修改图表。最后,刚刚创建了一个简单的 python docker 来进行标记,并创建了将主 redis 公开为服务的图表。这会定期检查为 redis-ha 创建的 pods 并根据它们的角色(主/从)标记它们
它使用相同的哨兵命令来查找 master/slave。