[英]why cluster node's ip is not current pod's ip
I am login kubernetes's(v1.15.2) pod to check current redis cluster ip,but the problem is redis cluster(redis:5.0.1-alpine) ip is not current pod's ip:我正在登录 kubernetes 的(v1.15.2)pod 来检查当前的 redis 集群 ip,但问题是 redis cluster(redis:5.0.1-alpine) ip 不是当前 pod 的 ip:
~ ⌚ 23:45:03
$ kubectl exec -it redis-app-0 /bin/ash
/data # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:1E:E0:1E
inet addr:172.30.224.30 Bcast:172.30.231.255 Mask:255.255.248.0
UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1
RX packets:78447 errors:0 dropped:0 overruns:0 frame:0
TX packets:64255 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:74638073 (71.1 MiB) TX bytes:74257972 (70.8 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3922 errors:0 dropped:0 overruns:0 frame:0
TX packets:3922 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:297128 (290.1 KiB) TX bytes:297128 (290.1 KiB)
/data # /usr/local/bin/redis-cli -c
127.0.0.1:6379> cluster nodes
a1ecebe5c9dc2f9edbe3c239c402881da10da6de 172.30.224.22:6379@16379 myself,master - 0 1582644797000 0 connected
127.0.0.1:6379>
the pod's ip is:172.30.224.30,and redis ip is:172.30.224.22,what is the problem?is it possible to fix it? pod的ip是:172.30.224.30,redis的ip是:172.30.224.22,有什么问题吗?能解决吗?
How is this IP defined in your redis config ?这个 IP 在你的 redis 配置中是如何定义的? Redis must've taken it from somewhere.
Redis 一定是从某个地方拿走了它。 Keep in mind that
Pod
ip is subject to change when the Pod
is recreated so you have no guarantee that IP address defined in your Redis node statically will remain unchanged.请记住,重新创建
Pod
时, Pod
ip 可能会发生变化,因此您无法保证在Redis 节点中静态定义的 IP 地址将保持不变。 I would even say that you can be almost 100% sure that it will change.我什至可以说你几乎可以 100% 确定它会改变。
You can check IP address of a particular interface in a few ways.您可以通过多种方式检查特定接口的 IP 地址。 One of them is by running:
其中之一是运行:
hostname -I | awk '{print $1}'
You can try to add an init container to your Pod
running simple bash script which would check current host ip address eg using the above command and then would populate redis config accordingly.您可以尝试向运行简单 bash 脚本的
Pod
添加一个init 容器,该脚本将检查当前主机 ip 地址,例如使用上述命令,然后相应地填充 redis 配置。 But it seems to me an overkill and I'm almost sure it can be done more easily.但这对我来说似乎有点矫枉过正,我几乎可以肯定它可以更轻松地完成。 If your redis node by default binds to all IP addresses (
0.0.0.0
), cluster nodes
output should show you current ip address of your Pod
.如果您的redis 节点默认绑定到所有 IP 地址(
0.0.0.0
),则cluster nodes
输出应显示您Pod
当前 IP 地址。
Are you providing Redis configuration to your Pod via some ConfigMap
?您是否通过一些
ConfigMap
向您的 Pod 提供Redis配置?
Please share more details related to your Deployment
so you can get more accurate answer that resolves your particular issue.请分享与您的
Deployment
相关的更多详细信息,以便您获得更准确的答案来解决您的特定问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.