如何处理etcdserver:不健康的集群

Dol*_*hin 5 etcd kubernetes

当我使用以下命令在 etcd 集群的 master 中添加节点时:

curl http://127.0.0.1:2379/v3beta/members \
-XPOST -H "Content-Type: application/json" \
-d '{"peerURLs": ["http://172.19.104.230:2380"]}'
Run Code Online (Sandbox Code Playgroud)

表明{"error":"etcdserver: unhealthy cluster","code":14}

我检查集群状态:

[root@iZuf63refzweg1d9dh94t8Z ~]# etcdctl member list
55a782166ce91d01, started, infra3, https://172.19.150.82:2380, https://172.19.150.82:2379
696a771758a889c4, started, infra1, https://172.19.104.231:2380, https://172.19.104.231:2379
Run Code Online (Sandbox Code Playgroud)

没事。我应该怎么做才能让它发挥作用?

Yas*_*sen 5

根据etcd源代码,如果方法失败,则返回 ErrUnhealthy错误代码。longestConnected

\n\n
// longestConnected chooses the member with longest active-since-time.\n// It returns false, if nothing is active.\nfunc longestConnected(tp rafthttp.Transporter, membs []types.ID) (types.ID, bool) {\n    var longest types.ID\n    var oldest time.Time\n    for _, id := range membs {\n        tm := tp.ActiveSince(id)\n        if tm.IsZero() { // inactive\n            continue\n        }\n\n        if oldest.IsZero() { // first longest candidate\n            oldest = tm\n            longest = id\n        }\n\n        if tm.Before(oldest) {\n            oldest = tm\n            longest = id\n        }\n    }\n    if uint64(longest) == 0 {\n        return longest, false\n    }\n    return longest, true\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,ectd无法找到合适的成员进行连接。

\n\n

Cluster 的方法返回投票VotingMemberIDs成员列表:

\n\n
transferee, ok := longestConnected(s.r.transport, s.cluster.VotingMemberIDs())\nif !ok {\n    return ErrUnhealthy\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n
transferee, ok := longestConnected(s.r.transport, s.cluster.VotingMemberIDs())\nif !ok {\n    return ErrUnhealthy\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

正如我们从您的报告中看到的,您的集群中有成员。

\n\n
\n
// VotingMemberIDs returns the ID of voting members in cluster.\nfunc (c *RaftCluster) VotingMemberIDs() []types.ID {\n    c.Lock()\n    defer c.Unlock()\n    var ids []types.ID\n    for _, m := range c.members {\n        if !m.IsLearner {\n            ids = append(ids, m.ID)\n        }\n    }\n    sort.Sort(types.IDSlice(ids))\n    return ids\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

所以我们应该检查成员 - 他们是否投票成员,而不是learners,请参阅etcd 文档 | 学习者

\n\n

筏学习者

\n\n
$ etcdctl member list\n> 55a782166ce91d01, started, infra3, https://172.19.150.82:2380, https://172.19.150.82:2379\n> 696a771758a889c4, started, infra1, https://172.19.104.231:2380, https://172.19.104.231:2379\n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,尝试增加成员数量以提供法定人数 netcd 法定人数

\n\n

要强制创建成员,请尝试此操作 ETCD_FORCE_NEW_CLUSTER=\xe2\x80\x9ctrue"

\n\n

法定人数

\n\n

另请参阅这篇文章:了解集群和池仲裁

\n