ETCD 集群出现 rpc 错误:code = DeadlineExceeded desc = 超出上下文截止时间

tin*_*mho 8 etcd kubernetes etcdctl

只是在这里寻找一些说明我有一个 2 节点 etcd 集群:

master01=http://10.1.1.21:2379,master02=http://10.1.1.22:2379
Run Code Online (Sandbox Code Playgroud)

一切运行良好。如果我登录 master01 并执行以下操作:

etcdctl --cluster=true endpoint health
Run Code Online (Sandbox Code Playgroud)

我得到了很好的回应:

http://10.1.1.21:2379 is healthy: successfully committed proposal: took = 25.628392ms
http://10.1.1.22:2379 is healthy: successfully committed proposal: took = 42.98645ms
Run Code Online (Sandbox Code Playgroud)

所有操作 get、put 都按预期运行。

ETCDCTL_API=3 etcdctl --endpoints=http://10.1.1.21:2379,http://10.1.1.22:2379 get date
Run Code Online (Sandbox Code Playgroud)

当我删除其中一个节点时,问题就开始了,因此,如果我杀死一个节点,我现在会收到错误而不是结果,例如:

ETCDCTL_API=3 etcdctl --endpoints=http://10.1.1.21:2379,http://10.1.1.22:2379 get date
{"level":"warn","ts":"2021-09-09T08:58:22.175Z","logger":"etcd-client","caller":"v3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc0000e0a80/#initially=[http://10.1.1.21:2379;http://10.1.1.22:2379]","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = context deadline exceeded"}
Error: context deadline exceeded
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我杀死了master01,我做错了什么吗?

Cha*_*kar 9

etcd 集群需要大多数节点(即法定人数)来就集群状态的更新达成一致。对于具有 n 个成员的集群,仲裁数为 (n/2)+1。对于任何奇数大小的集群,添加一个节点总是会增加仲裁所需的节点数量。虽然向奇数大小的集群添加节点看起来更好,因为机器更多,但容错能力更差,因为完全相同数量的节点可能会在不丢失仲裁的情况下发生故障,但可能发生故障的节点更多。如果集群处于无法容忍更多故障的状态,那么在删除节点之前添加节点是危险的,因为如果新节点无法向集群注册(例如,地址配置错误),仲裁将永久丢失。

\n

因此,在您的情况下,拥有两个 etcd 节点可提供与一个相同的冗余,因此始终建议拥有奇数个 etcd 节点。code = DeadlineExceeded desc = context deadline exceeded意味着客户端无法到达 etcd 服务器并且超时。因此,可能会出现这样的情况:您正在尝试连接到已关闭的 etcd 服务器,结果您会看到错误。请参阅以下文档以了解更多信息

\n

ETDC 故障容差表

\n

  • 这是一个很好的解决方案,我不确定为什么 stackoverflow 讨厌我的问题..(我们不允许问有关网络的问题?) (2认同)