Consul clients do not automatically rejoin the cluster after server rolling restart if server IPs change (e.g. in Kubernetes).
Description of the Issue (and unexpected/desired result)
After i restart my 3 consul servers the clients do not rejoin and report the nodes as "left".
The client reports:
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.148:8301 left server 1.0.6 2 dc1 <all>
consul-1 10.131.0.94:8301 left server 1.0.6 2 dc1 <all>
consul-2 10.130.0.149:8301 left server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-bflzp 10.130.0.150:8301 alive client 1.0.6 2 dc1 <default>
The servers formed a cluster with new IPs:
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.151:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.95:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.152:8301 alive server 1.0.6 2 dc1 <all>
Reproduction steps
I'm deploying the consul servers using a StatefulSet in Openshift 3.7.
- Deploy the StatefulSet with 3 replicas
- Deploy the client
- After a while delete the statefulset and create it again
- Check the client
Current Behavior: The client does not reconnect although the command line options is using FQDN:
args:
- "consul"
- "agent"
- "-retry-join=consul-service.blah.svc.cluster.local"
- "-config-file=/consul/config/tls/clients-tls-config.json"
- "-config-dir=/consul/config/"
- "-data-dir=/consul/data"
- "-domain=cluster.local"
- "-datacenter=dc1"
- "-encrypt=$(GOSSIP_ENCRYPTION_KEY)"
Expected Behavior:
At some point (ideally ~ 1 minute max) the client will try to connect to servers again using the FQDN that will resolve to a new IP.
consul version for both Client and Server
Consul v1.0.6
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
consul info for both Client and Server
Client:
agent:
check_monitors = 0
check_ttls = 0
checks = 3
services = 3
build:
prerelease =
revision = 9a494b5f
version = 1.0.6
consul:
known_servers = 0
server = false
runtime:
arch = amd64
cpu_count = 12
goroutines = 38
max_procs = 12
os = linux
version = go1.9.3
serf_lan:
coordinate_resets = 0
encrypted = true
event_queue = 0
event_time = 2
failed = 0
health_score = 0
intent_queue = 0
left = 3
member_time = 8
members = 4
query_queue = 0
query_time = 1
Server:
agent:
check_monitors = 0
check_ttls = 0
checks = 0
services = 0
build:
prerelease =
revision = 9a494b5f
version = 1.0.6
consul:
bootstrap = false
known_datacenters = 1
leader = false
leader_addr = 10.131.0.95:8300
server = true
raft:
applied_index = 6893
commit_index = 6893
fsm_pending = 0
last_contact = 22.817499ms
last_log_index = 6893
last_log_term = 5
last_snapshot_index = 0
last_snapshot_term = 0
latest_configuration = [{Suffrage:Voter ID:b836681e-241e-5de1-de46-d5878b268d16 Address:10.131.0.95:8300} {Suffrage:Voter ID:4de0f8c0-03d7-f018-3bc6-e841934b24a5 Address:10.130.0.152:8300} {Suffrage:Voter ID:9b6291fc-76b2-a050-c9bf-c6c8faebd129 Address:10.130.0.151:8300}]
latest_configuration_index = 6876
num_peers = 2
protocol_version = 3
protocol_version_max = 3
protocol_version_min = 0
snapshot_version_max = 1
snapshot_version_min = 0
state = Follower
term = 5
runtime:
arch = amd64
cpu_count = 12
goroutines = 79
max_procs = 12
os = linux
version = go1.9.3
serf_lan:
coordinate_resets = 0
encrypted = true
event_queue = 0
event_time = 3
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 11
members = 3
query_queue = 0
query_time = 1
serf_wan:
coordinate_resets = 0
encrypted = true
event_queue = 0
event_time = 1
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 10
members = 3
query_queue = 0
query_time = 1
Operating system and Environment details
Openshift Origin 3.7, Consul server deployed as StatefulSet with 3 replicas
StatefulSet args:
args:
- "consul"
- "agent"
- "-advertise=$(POD_IP)"
- "-bind=0.0.0.0"
- "-bootstrap-expect=3"
- "-retry-join=consul-0.consul-service.blah.svc.cluster.local"
- "-retry-join=consul-1.consul-service.blah.svc.cluster.local"
- "-retry-join=consul-2.consul-service.blah.svc.cluster.local"
- "-client=0.0.0.0"
- "-raft-protocol=3"
- "-config-file=/consul/config/servers-tls-config.json"
- "-datacenter=dc1"
- "-data-dir=/consul/data"
- "-domain=cluster.local"
- "-encrypt=$(GOSSIP_ENCRYPTION_KEY)"
- "-server"
- "-ui"
- "-disable-host-node-id"
Do I understand correctly that you stopped all three servers and deleted all their data then started three new servers on different IPs?
If you restart your other (client) agents presumably they discover the new cluster and work fine right?
In what case other than dev/experimentation do you expect to delete all the server instances at once and create new ones without interruption for clients? I guess I must be misunderstanding what you are trying to achieve 😄. If it's just dev then it seems reasonable to need to restart agents if you completely rebuild the servers from scratch to me.
I stopped the 3 servers (deleted the StatefulSet) but the data is persistent (it's a StatefulSet so the volumes are not deleted - /consul/data/). After removing the StatefulSet i deploy it again - note that the FQDNs of the servers are always the same but the IPs change. The clients are connecting using the StatefulSet service name: consul-service.blah.svc.cluster.local so after the StatefulSet gets deployed again all the clients have to do is just resolve the service name again to get the new IPs - which is what they are not doing -> hence the issue.
And yes - restarting the clients makes them re-join again but i though this is a situation that will be handled more gracefully.
I just tested a more realistic scenario - updating the consul servers image (i used the same binaries, just different image tag) - i see the same behavior:
- The StatefulSet update means that the 3 PODs are stopped and started one by one and you have always one running
- The update was successful but the client did not re-evaluate the service name to get the new IPs.
A workaround for someone that hits the same issue is to use liveliness/readiness probes on the consul client:
livenessProbe:
exec:
command:
- consul
- catalog
- nodes
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 2
failureThreshold: 1
readinessProbe:
exec:
command:
- consul
- catalog
- nodes
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 2
I have seen people deploy consul in kubernetes ( i used https://github.com/kelseyhightower/consul-on-kubernetes as a starting point) but i guess the question is whether this is supported at all out of the box?
Interesting that you see the same on a rolling restart.
Since Consul 1.0 (raft protocol 3) we support servers coming back with state intact but different IPs (they get a UUID generated internally on first startup) which explains how your rolling restart is working for the servers.
I'm not sure offhand if the issue with agents not picking up the new server IPs through retry-join is specific to you or something that isn't supported yet in general but I agree it should be automatic given that servers can now recover with different IPs.
I'll slightly edit the issue title to reflect the conditions necessary for the issue.
The issue appears to be that we don't re-trigger retryJoin once the cluster is initially bootstrapped. The servers also don't actively broadcast the fact that their IP changed when they come back up so clients are left trying to connect to three IP addresses that don't work.
It might make sense to have agents who have seen all servers leave and have a retry-join config revert to attempting a join again. We'll consider that although it does change some of the assumptions about retry join and cluster bootstrap/lifecycle so it's possibly not trivial.
An alternative would be some server IP gossip mechanism so servers that come back in a rolling manner can propagate their new IP directly to the cluster before all original IPs are inaccessible.
It seems important to handle this use-case gracefully especially since we already handle the harder part which is the servers getting into quorum.
Thanks for updating the title. I guess i'll use the workaround until the issue is fixed.
Yeah your workaround seems reasonable and not too much of a liability for the time being. Obviously we want to find a proper solution longer term.
I've labelled this as a "bug" since the work in 1.0.0 to enable server IPs to change seems incomplete without it.
Hi @pgeorgiev333,
@preetapan pointed out to me that this should work already without changes to retry.
When the servers come back up with new IP, they should recover their serf state too and start gossiping to the existing clients too.
So at a minimum your consul members output on the new server should show the old clients and vice versa. Once they are gossiping, the clients should pick up that the servers IP's have changed that way without needing to re-bootstrap.
We'll try to reproduce your conditions but could you take a look in your new server logs after they come back - you should see something like:
[INFO] serf: Attempting re-join to previously known node: <client IP address>
Can you also confirm just for sanity's sake that the new servers can actually ping the old client's IP immediately - I assume they can as restarting client works, but want to rule out something like Calico being delayed in updating the IPsets that are allowed to talk after the new pods start. (any details on your network fabric might help rule that out too).
I repeated the "update" test but this time i removed the probes on the client. The result was very strange.
Initial state:
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.169:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.103:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.170:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-491293915-h45bw 10.130.0.171:8301 alive client 1.0.6 2 dc1 <default>
Apply the new yml with a new image tag (same consul version, just different tag):
=== consul-0 ===
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.173:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.104:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.172:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-491293915-h45bw 10.130.0.171:8301 alive client 1.0.6 2 dc1 <default>
==== consul-1 ===
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.173:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.104:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.172:8301 leaving server 1.0.6 2 dc1 <all>
edge-1-deployment-491293915-h45bw 10.130.0.171:8301 alive client 1.0.6 2 dc1 <default>
==== consul-2 ====
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.173:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.104:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.172:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-491293915-h45bw 10.130.0.171:8301 alive client 1.0.6 2 dc1 <default>
==== client ====
consul-0 10.130.0.173:8301 leaving server 1.0.6 2 dc1 <all>
consul-1 10.131.0.104:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.172:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-491293915-h45bw 10.130.0.171:8301 alive client 1.0.6 2 dc1 <default>
Some logs
==== client ===
2018/02/22 07:01:07 [INFO] agent: Joining LAN cluster...
--
| 2018/02/22 07:01:07 [WARN] manager: No servers available
| 2018/02/22 07:01:07 [INFO] agent: (LAN) joining: [consul-service.st-lec.svc.cluster.local]
| 2018/02/22 07:01:07 [ERR] agent: failed to sync remote state: No known Consul servers
| 2018/02/22 07:01:07 [INFO] serf: EventMemberJoin: consul-1 10.131.0.104
| 2018/02/22 07:01:07 [WARN] memberlist: Refuting a suspect message (from: edge-1-deployment-491293915-h45bw)
| 2018/02/22 07:01:07 [INFO] serf: EventMemberJoin: consul-2 10.130.0.172
| 2018/02/22 07:01:07 [INFO] consul: adding server consul-1 (Addr: tcp/10.131.0.104:8300) (DC: dc1)
| 2018/02/22 07:01:07 [INFO] consul: adding server consul-2 (Addr: tcp/10.130.0.172:8300) (DC: dc1)
| 2018/02/22 07:01:07 [INFO] serf: EventMemberJoin: consul-0 10.130.0.173
| 2018/02/22 07:01:07 [INFO] consul: adding server consul-0 (Addr: tcp/10.130.0.173:8300) (DC: dc1)
| 2018/02/22 07:01:07 [INFO] agent: (LAN) joined: 3 Err: <nil>
| 2018/02/22 07:01:07 [INFO] agent: Join LAN completed. Synced with 3 initial agents
| 2018/02/22 07:01:08 [INFO] consul: New leader elected: consul-0
....
2018/02/22 07:02:26 [INFO] consul: New leader elected: consul-1
==== consul-0 ===
2018/02/22 07:00:12 [ERR] memberlist: Conflicting address for consul-0.dc1. Mine: 10.130.0.173:8302 Theirs: 10.130.0.169:8302
....
2018/02/22 07:00:12 [ERR] serf: Node name conflicts with another node at 10.130.0.169:8302. Names must be unique! (Resolution enabled: false)
2018/02/22 07:00:12 [ERR] memberlist: Conflicting address for consul-1.dc1. Mine: 10.131.0.103:8302 Theirs: 10.131.0.104:8302
--
| 2018/02/22 07:00:12 [WARN] serf: Name conflict for 'consul-1.dc1' both 10.131.0.103:8302 and 10.131.0.104:8302 are claiming
| 2018/02/22 07:00:19 [ERR] agent: failed to sync remote state: No cluster leader
| 2018/02/22 07:00:21 [WARN] raft: Heartbeat timeout from "" reached, starting election
| 2018/02/22 07:00:21 [INFO] raft: Node at 10.130.0.173:8300 [Candidate] entering Candidate state in term 65
| 2018/02/22 07:00:21 [INFO] raft: Election won. Tally: 1
| 2018/02/22 07:00:21 [INFO] raft: Node at 10.130.0.173:8300 [Leader] entering Leader state
| 2018/02/22 07:00:21 [INFO] raft: Added peer 4de0f8c0-03d7-f018-3bc6-e841934b24a5, starting replication
| 2018/02/22 07:00:21 [INFO] consul: cluster leadership acquired
| 2018/02/22 07:00:21 [INFO] consul: New leader elected: consul-0
| 2018/02/22 07:00:21 [ERR] raft: peer {Nonvoter 4de0f8c0-03d7-f018-3bc6-e841934b24a5 10.130.0.172:8300} has newer term, stopping replication
| 2018/02/22 07:00:21 [INFO] raft: Node at 10.130.0.173:8300 [Follower] entering Follower state (Leader: "")
| 2018/02/22 07:00:21 [ERR] consul: failed to add raft peer: node is not the leader
| 2018/02/22 07:00:21 [ERR] consul: failed to reconcile member: {consul-1 10.131.0.104 8301 map[port:8300 segment: raft_vsn:3 expect:3 role:consul wan_join_port:8302 dc:dc1 id:b836681e-241e-5de1-de46-d5878b268d16 vsn_max:3 build:1.0.6:9a494b5f vsn:2 vsn_min:2 use_tls:1] alive 1 5 2 2 5 4}: node is not the leader
| 2018/02/22 07:00:21 [INFO] consul: member 'consul-0' joined, marking health alive
| 2018/02/22 07:00:21 [ERR] consul: failed to reconcile member: {consul-0 10.130.0.173 8301 map[use_tls:1 dc:dc1 port:8300 id:9b6291fc-76b2-a050-c9bf-c6c8faebd129 vsn:2 role:consul segment: vsn_max:3 raft_vsn:3 wan_join_port:8302 vsn_min:2 build:1.0.6:9a494b5f expect:3] alive 1 5 2 2 5 4}: node is not the leader
| 2018/02/22 07:00:21 [INFO] consul: cluster leadership lost
| 2018/02/22 07:00:22 [INFO] memberlist: Suspect consul-1.dc1 has failed, no acks received
| 2018/02/22 07:00:30 [WARN] raft: Heartbeat timeout from "" reached, starting election
| 2018/02/22 07:00:30 [INFO] raft: Node at 10.130.0.173:8300 [Candidate] entering Candidate state in term 66
| 2018/02/22 07:00:30 [INFO] raft: Election won. Tally: 1
| 2018/02/22 07:00:30 [INFO] raft: Node at 10.130.0.173:8300 [Leader] entering Leader state
| 2018/02/22 07:00:30 [INFO] raft: Added peer 4de0f8c0-03d7-f018-3bc6-e841934b24a5, starting replication
| 2018/02/22 07:00:30 [INFO] consul: cluster leadership acquired
| 2018/02/22 07:00:30 [INFO] consul: New leader elected: consul-0
| 2018/02/22 07:00:30 [ERR] raft: peer {Nonvoter 4de0f8c0-03d7-f018-3bc6-e841934b24a5 10.130.0.172:8300} has newer term, stopping replication
| 2018/02/22 07:00:30 [INFO] raft: Node at 10.130.0.173:8300 [Follower] entering Follower state (Leader: "")
| 2018/02/22 07:00:30 [ERR] consul: failed to wait for barrier: node is not the leader
| 2018/02/22 07:00:30 [INFO] consul: cluster leadership lost
| 2018/02/22 07:00:30 [ERR] agent: failed to sync remote state: No cluster leader
| 2018/02/22 07:00:32 [INFO] memberlist: Suspect consul-1.dc1 has failed, no acks received
etc.
Very strange. Maybe it was the same as before but last time i did this scenario i did not check the logs of all nodes...
I'll delete the volumes and start from scratch.
Initial state:
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.174:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.105:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.175:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
After applying the update to the StatefulSet each server is stopped and started (so consul-2 pod is first, the consul-1, then consul-0).
After state:
oc exec -it consul-0 consul members
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.178:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.106:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.177:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
oc exec -it consul-1 consul members
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.178:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.106:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.177:8301 leaving server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
oc exec -it consul-2 consul members
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.178:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.106:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.177:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
oc exec -it edge-1-deployment-1161814082-4gp8c -c consul-agent consul members
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.178:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.106:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.177:8301 alive server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
So to summarize:
- My initial test of deleting the StatefulSet and creating it again is not valid
- The proper way to test is using StatefulSet update procedure (apply a new YML with a new docker image tag) which leads to better results
- one of the servers does not have consistent state of the cluster:
oc exec -it consul-1 consul members
Node Address Status Type Build Protocol DC Segment
consul-0 10.130.0.178:8301 alive server 1.0.6 2 dc1 <all>
consul-1 10.131.0.106:8301 alive server 1.0.6 2 dc1 <all>
consul-2 10.130.0.177:8301 leaving server 1.0.6 2 dc1 <all>
edge-1-deployment-1161814082-4gp8c 10.130.0.176:8301 alive client 1.0.6 2 dc1 <default>
I checked all nodes and all think that the new leader is "leader_addr = 10.130.0.177:8300". What is strange is that consul-1 shows that the leader is leaving...
Here are the logs from consul-1 pod:
2018/02/22 08:59:15 [INFO] serf: EventMemberJoin: consul-0 10.130.0.174
2018/02/22 08:59:15 [WARN] memberlist: Refuting a suspect message (from: consul-1)
2018/02/22 08:59:15 [INFO] serf: EventMemberJoin: edge-1-deployment-1161814082-4gp8c 10.130.0.176
2018/02/22 08:59:15 [INFO] consul: Adding LAN server consul-0 (Addr: tcp/10.130.0.174:8300) (DC: dc1)
2018/02/22 08:59:15 [WARN] memberlist: Refuting a suspect message (from: consul-1.dc1)
2018/02/22 08:59:15 [INFO] serf: EventMemberJoin: consul-0.dc1 10.130.0.174
2018/02/22 08:59:15 [INFO] consul: Handled member-join event for server "consul-0.dc1" in area "wan"
2018/02/22 08:59:15 [INFO] serf: EventMemberJoin: consul-2 10.130.0.177
2018/02/22 08:59:15 [INFO] agent: (LAN) joined: 3 Err: <nil>
2018/02/22 08:59:15 [INFO] agent: Join LAN completed. Synced with 3 initial agents
2018/02/22 08:59:15 [INFO] consul: Adding LAN server consul-2 (Addr: tcp/10.130.0.177:8300) (DC: dc1)
2018/02/22 08:59:20 [WARN] raft: Heartbeat timeout from "" reached, starting election
2018/02/22 08:59:20 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 3
2018/02/22 08:59:22 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 08:59:29 [WARN] raft: Election timeout reached, restarting election
2018/02/22 08:59:29 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 4
2018/02/22 08:59:29 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: EOF
2018/02/22 08:59:32 [ERR] memberlist: Conflicting address for consul-0. Mine: 10.130.0.174:8301 Theirs: 10.130.0.178:8301
2018/02/22 08:59:32 [WARN] serf: Name conflict for 'consul-0' both 10.130.0.174:8301 and 10.130.0.178:8301 are claiming
2018/02/22 08:59:32 [INFO] serf: EventMemberJoin: consul-2.dc1 10.130.0.177
2018/02/22 08:59:32 [ERR] memberlist: Conflicting address for consul-0.dc1. Mine: 10.130.0.174:8302 Theirs: 10.130.0.178:8302
2018/02/22 08:59:32 [WARN] serf: Name conflict for 'consul-0.dc1' both 10.130.0.174:8302 and 10.130.0.178:8302 are claiming
2018/02/22 08:59:32 [ERR] memberlist: Conflicting address for consul-1.dc1. Mine: 10.131.0.106:8302 Theirs: 10.131.0.105:8302
2018/02/22 08:59:32 [ERR] serf: Node name conflicts with another node at 10.131.0.105:8302. Names must be unique! (Resolution enabled: false)
2018/02/22 08:59:32 [INFO] consul: Handled member-join event for server "consul-2.dc1" in area "wan"
2018/02/22 08:59:32 [ERR] memberlist: Conflicting address for consul-0. Mine: 10.130.0.174:8301 Theirs: 10.130.0.178:8301
2018/02/22 08:59:32 [WARN] serf: Name conflict for 'consul-0' both 10.130.0.174:8301 and 10.130.0.178:8301 are claiming
2018/02/22 08:59:33 [INFO] memberlist: Suspect consul-0 has failed, no acks received
2018/02/22 08:59:38 [ERR] agent: Coordinate update error: No cluster leader
2018/02/22 08:59:38 [WARN] raft: Election timeout reached, restarting election
2018/02/22 08:59:38 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 5
2018/02/22 08:59:40 [INFO] consul: New leader elected: consul-0
2018/02/22 08:59:45 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 08:59:46 [WARN] raft: Election timeout reached, restarting election
2018/02/22 08:59:46 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 6
2018/02/22 08:59:47 [INFO] memberlist: Suspect consul-0 has failed, no acks received
2018/02/22 08:59:47 [DEBUG] raft-net: 10.131.0.106:8300 accepted connection from: 10.130.0.178:38416
2018/02/22 08:59:47 [INFO] consul: New leader elected: consul-0
2018/02/22 08:59:48 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: i/o timeout
2018/02/22 08:59:54 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 08:59:55 [INFO] consul: New leader elected: consul-0
2018/02/22 08:59:55 [WARN] raft: Election timeout reached, restarting election
2018/02/22 08:59:55 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 7
2018/02/22 08:59:56 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: i/o timeout
2018/02/22 08:59:57 [INFO] memberlist: Marking consul-0 as failed, suspect timeout reached (0 peer confirmations)
2018/02/22 08:59:57 [INFO] serf: EventMemberFailed: consul-0 10.130.0.174
2018/02/22 08:59:57 [INFO] consul: Removing LAN server consul-0 (Addr: tcp/10.130.0.174:8300) (DC: dc1)
2018/02/22 08:59:58 [INFO] memberlist: Suspect consul-0 has failed, no acks received
2018/02/22 09:00:02 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 09:00:03 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:03 [INFO] memberlist: Suspect consul-0.dc1 has failed, no acks received
2018/02/22 09:00:03 [WARN] raft: Election timeout reached, restarting election
2018/02/22 09:00:03 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 8
2018/02/22 09:00:03 [WARN] Unable to get address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4, using fallback address 10.130.0.174:8300: Could not find address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4
2018/02/22 09:00:04 [DEBUG] raft-net: 10.131.0.106:8300 accepted connection from: 10.130.0.177:60506
2018/02/22 09:00:04 [WARN] raft: Rejecting vote request from 10.130.0.177:8300 since our last index is greater (535, 533)
2018/02/22 09:00:04 [INFO] raft: Node at 10.131.0.106:8300 [Follower] entering Follower state (Leader: "")
2018/02/22 09:00:05 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: i/o timeout
2018/02/22 09:00:06 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: getsockopt: no route to host
2018/02/22 09:00:08 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:10 [WARN] raft: Rejecting vote request from 10.130.0.177:8300 since our last index is greater (535, 533)
2018/02/22 09:00:10 [WARN] raft: Heartbeat timeout from "" reached, starting election
2018/02/22 09:00:10 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 12
2018/02/22 09:00:10 [WARN] Unable to get address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4, using fallback address 10.130.0.174:8300: Could not find address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4
2018/02/22 09:00:11 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 09:00:12 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: getsockopt: no route to host
2018/02/22 09:00:13 [INFO] memberlist: Suspect consul-0.dc1 has failed, no acks received
2018/02/22 09:00:13 [ERR] agent: Coordinate update error: No cluster leader
2018/02/22 09:00:16 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:18 [WARN] raft: Rejecting vote request from 10.130.0.177:8300 since our last index is greater (535, 533)
2018/02/22 09:00:20 [WARN] raft: Election timeout reached, restarting election
2018/02/22 09:00:20 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 13
2018/02/22 09:00:20 [WARN] Unable to get address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4, using fallback address 10.130.0.174:8300: Could not find address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4
2018/02/22 09:00:20 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 09:00:20 [INFO] memberlist: Suspect consul-0.dc1 has failed, no acks received
2018/02/22 09:00:23 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: getsockopt: no route to host
2018/02/22 09:00:25 [WARN] raft: Election timeout reached, restarting election
2018/02/22 09:00:25 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 14
2018/02/22 09:00:25 [WARN] Unable to get address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4, using fallback address 10.130.0.174:8300: Could not find address for server id 69e5310a-04e4-1f50-01e6-f69307389ba4
2018/02/22 09:00:25 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:26 [ERR] raft: Failed to make RequestVote RPC to {Voter 69e5310a-04e4-1f50-01e6-f69307389ba4 10.130.0.174:8300}: dial tcp <nil>->10.130.0.174:8300: getsockopt: no route to host
2018/02/22 09:00:29 [ERR] agent: failed to sync remote state: No cluster leader
2018/02/22 09:00:31 [INFO] memberlist: Suspect consul-0.dc1 has failed, no acks received
2018/02/22 09:00:31 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:32 [INFO] serf: EventMemberJoin: consul-0 10.130.0.178
2018/02/22 09:00:32 [INFO] consul: Adding LAN server consul-0 (Addr: tcp/10.130.0.178:8300) (DC: dc1)
2018/02/22 09:00:33 [WARN] raft: Election timeout reached, restarting election
2018/02/22 09:00:33 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 15
2018/02/22 09:00:33 [INFO] memberlist: Marking consul-0.dc1 as failed, suspect timeout reached (0 peer confirmations)
2018/02/22 09:00:33 [INFO] serf: EventMemberFailed: consul-0.dc1 10.130.0.174
2018/02/22 09:00:33 [INFO] consul: Handled member-failed event for server "consul-0.dc1" in area "wan"
2018/02/22 09:00:35 [WARN] raft: Rejecting vote request from 10.130.0.177:8300 since our last index is greater (535, 533)
2018/02/22 09:00:37 [WARN] raft: Failed to get previous log: 555 log not found (last: 535)
2018/02/22 09:00:37 [INFO] raft: Node at 10.131.0.106:8300 [Follower] entering Follower state (Leader: "10.130.0.178:8300")
2018/02/22 09:00:37 [INFO] consul: New leader elected: consul-0
2018/02/22 09:00:37 [INFO] agent: Synced node info
2018/02/22 09:00:38 [DEBUG] raft-net: 10.131.0.106:8300 accepted connection from: 10.130.0.178:38838
2018/02/22 09:01:45 [INFO] serf: attempting reconnect to consul-0.dc1 10.130.0.174:8302
2018/02/22 09:01:45 [WARN] raft: Rejecting vote request from 10.130.0.177:8300 since we have a leader: 10.130.0.178:8300
2018/02/22 09:01:47 [WARN] raft: Heartbeat timeout from "10.130.0.178:8300" reached, starting election
2018/02/22 09:01:47 [INFO] raft: Node at 10.131.0.106:8300 [Candidate] entering Candidate state in term 17
2018/02/22 09:01:52 [INFO] raft: Node at 10.131.0.106:8300 [Follower] entering Follower state (Leader: "")
2018/02/22 09:01:52 [INFO] consul: New leader elected: consul-2
2018/02/22 09:01:53 [DEBUG] raft-net: 10.131.0.106:8300 accepted connection from: 10.130.0.177:33104
2018/02/22 09:02:24 [INFO] serf: EventMemberJoin: consul-0.dc1 10.130.0.178
2018/02/22 09:02:24 [INFO] consul: Handled member-join event for server "consul-0.dc1" in area "wan"
I also noticed this:
consul-2:
2018/02/22 08:58:50 [ERR] raft-net: Failed to flush response: write tcp 10.130.0.175:8300->10.130.0.174:58450: write: broken pipe
Not sure if it is related to the "leaving" state.
I tried adding these to the server's configuration:
"skip_leave_on_interrupt": true,
"leave_on_terminate" : false,
and it seems to work. After applying the update it took around 2 minutes to elect a leader and all nodes show the same info (all others are alive).
This comment gave me the hint: https://github.com/hashicorp/consul/issues/2172#issuecomment-231177225
The example StatefulSet that i used had this in it's configuration:
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- consul leave
So when you scale down the node leaves ( i removed the hook in my last test). This may be ok for manual scalling up and down but the problem is that the update procedure uses the same process - i am not aware of any way to detect if the StatefulSet is being just scalled down or updated (with a new image).
In summary my test shows that when you deploy a stateful set you need to deploy a fixed number of replicas (3, 4, etc) and do not "consul leave" (instead use "skip_leave_on_interrupt": true and "leave_on_terminate" : false). This allows you to upgrade but scalling down is not a great idea as the node will stop but will not leave the cluster.
Any comments are appreciated.
Thanks
@pgeorgiev333 thanks for the details, that's really useful. It looks like this is not specifically a bug in gossip rediscovering the new leader then.
We'll work out what the correct settings are as no doubt others will want to run in K8s too.
From docs:
On agents in client-mode, this [
skip_leave_on_interrupt] defaults to false and for agents in server-mode, this defaults to true
On agents in client-mode, this [
leave_on_terminate] defaults to true and for agents in server-mode, this defaults to false.
In other words, the settings you added to Server config are already the defaults which makes total sense - the servers going down due to crash or reboot shouldn't "leave" and mess up quorum.
The example StatefulSet that i used had this in it's configuration:
Aha so it was the StatefulSet configuration that was forcing leave every time the pod stopped.
For servers, you are right that you only want to leave if the total number of servers is being reduced.
Honestly I can't really see a good reason in practice to want to have server clusters auto-scale though - adding more servers will likely make your throughput worse in many cases since the raft quorum grows. Even if it doesn't for you, adding more servers only helps scale reads where ?stale consistency mode is enabled since all consistent reads have to go through raft (and hence the single leader) anyway.
The size of a server cluster is something that needs careful consideration and tuning with your workload so I just don't think auto-scaling them is a good idea. We allow non-voting replicas as an Enterprise feature where the tradeoffs change a little but even then I would be very wary of changing the size of cluster without manual intervention.
I realise that even manually changing the replica number in a stateful set will cause the same issue, but I'd advise that this should be a rare and manual operation in which case you can call consul leave on the server nodes yourself prior to shutting them down (or force-leave after they are gone).
Does that help?
Absolutely. I hope this helps others too.
I'm closing the issue.
Thanks. Removing the consul leave seems to help improve the auto-rejoining of members to my cluster w/o manual intervention.