[zeromicro/go-zero]打包成docker的服务,启动时etcd写入问题

2024-01-12 560 views
8

问题:打包成docker的服务,启动时etcd写入问题 背景

1. etcd启动在宿主机的0.0.0.0:2379 2. docker启动的时候,连接报错 2.1 指定etcd的ip为docker0时, 报

{"level":"warn","ts":"2021-09-25T10:19:56.878Z","logger":"etcd-client","caller":"v3@v3.5.0/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc0005328c0/#initially=[172.17.0.1:2379]","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing dial tcp 172.17.0.1:2379: connect: no route to host\""}

2.2 指定etcd的ip为0.0.0.0,报

{"level":"warn","ts":"2021-09-25T10:21:30.406Z","logger":"etcd-client","caller":"v3@v3.5.0/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc000594540/#initially=[0.0.0.0:2379]","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing dial tcp 0.0.0.0:2379: connect: connection refused\""}

回答

0

报错挺明显的

  1. 你要配置到从启动的pod里可以telnet这个端口
  2. dial 0.0.0.0是肯定不对的
0

使用docker启动的服务,如果不加etcd注册的话,能正常启动,进入容器中,可以ping通 172.17.0.1 docker0 但是加上etcd,指定etcd的ip为 172.17.0.1时,就会报错了。

rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = "transport: Error while dialing dial tcp 172.17.0.1:2379: connect: no route to host

2

你在docker里装个telnet,先telnet通再看

3

好的。我先试下。

3

试了,能ping通,但telnet不通,我先找找原因。感谢。

0

感谢kevwan峰哥的指导,已经找到问题了。 iptables的顺序问题,2379端口的包被拦了,默认docker0的包到宿主机被拦截了。