문제가 일어난 시점으로 돌아가 보겠습니다. swarm cluster 구성도는 아래와 같았습니다.
2 manager
3 worker
서막
docker 관련을 작업을 하다 잘 안되서 보니 swarm mode 가 걸려 있어서 이전에 공부할 때 swam mode 를 해 놓은 줄 알고 swarm leave 를 했습니다.
$ docker swarm leave
Error response from daemon: You are attempting to leave the swarm on a node that is participating as a manager. Removing this node leaves 1 managers out of 2. Without a Raft quorum your swarm will be inaccessible. The only way to restore a swarm that has lost consensus is to reinitialize it with ` — force-new-cluster`. Use ` — force` to suppress this message.
(어랏 잘 안 꺼지네….) 잘 안 꺼져져서 아무 생각 없이 force 옵션을 줬습니다.
$ docker swarm leave — force
Node left the swarm.
Quorum 깨짐
이 때까지만 해도 뭔 일인지 몰랐습니다. 그리고 혹시나 싶어 기존 service 들이 잘 동작하는지 살펴보려고 docker service ls 를 해봤습니다.
$ docker service ls
Error response from daemon: This node is not a swarm manager. Use “docker swarm init” or “docker swarm join” to connect this node to swarm and try again.
갑자기 간담이 서늘해지기 시작함
swarm mode에서 나왔으니 당연하거라 생각했지만, 다시 swarm manager로 join을 하면 잘 보이겠구나 하고 생각을 했습니다.
살리기 위한 시도
매우 순진했던 순간들….
매니저 토큰을 얻어오면 간단할 거라 생각하고 명령을 날렸습니다.
$ docker swarm join-token manager
Error response from daemon: rpc error: code = 2 desc = The swarm does not have a leader. It’s possible that too few managers are online. Make sure more than half of the managers are online.
당연한 결과입니다. manager 가 아니거든요. 그런데 leader 가 없다니 무슨 말인지 의심만 들었지 더 깊게 파고들지 않았습니다. manager 안되며 worker 는 될려나 하는 마음으로 명령을 날렸습니다.
$ docker swarm join-token worker
Error response from daemon: rpc error: code = 2 desc = The swarm does not have a leader. It’s possible that too few managers are online. Make sure more than half of the managers are online.
당연한 결과입니다. manager 가 아니거든요. 그래서 정말 순진하게 이전 토큰으로 그냥 붙여보기로 했습니다. 다행히 이전 토큰을 가지고 있었거든요.
docker swarm join — token {token} x.x.x.x
Error response from daemon: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = “transport: Error while dialing dial tcp x.x.x.x:2377: connect: connection refused”
인생 뭐 쉬운 거 없다는 생각이 들었습니다. 이제 즐거운 마음으로 삽을 들었습니다. 다시 한 번 순수하게 swarm mode 로 들어가면 자연스럽게 붙겠지? 하는 마음으로 명령을 날렸습니다.
$ docker swarm init
Swarm initialized: current node (kkkkkkkkkkk) is now a manager.To add a worker to this swarm, run the following command:docker swarm join — token {token} x.x.x.x:2377To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
한결 편안해진 마음으로
아…. 뭐 됐구나… 어쩌냐…. 다 갈아 엎어야 하나…. 오늘 퇴근 가능할까.. 등등 온갖 생각들이 머리에서 솟아났습니다. 일단 swarm worker 들이 잘 동작하는지 확인해봤습니다. 안되면 온갖 문의가 발생할거기 때문에 조심스럽게 테스트를 했는데 다행히 잘 됐습니다. (docker swarm 형님들 역시 잘 만들었네 =b)
이제 한결 편안해진 마음으로 인터넷 검색을 했습니다. swarm admin guide에 아래와 같은 문구를 보며 일단 안도에 한숨을 쉬었습니다.
Even if a swarm loses the quorum of managers, swarm tasks on existing worker nodes continue to run. However, swarm nodes cannot be added, updated, or removed, and new or existing tasks cannot be started, stopped, moved, or updated.
해결책 발견
docker swarm 형님들의 친절한 문서를 보면서 해결책을 찾았습니다. manager가 하나만 있는 줄 알았는데 서버를 뒤져보니 다행히 다른 살아 있는 manager가 있었습니다. 그럴 경우 아래와 같은 명령어로 쉽게 살릴 수 있다고 문서에 써 있었습니다.
$ docker swarm init --force-new-cluster --advertise-addr x.x.x.x:2377
바로 명령어 입력!!!
$ docker swarm join — token {token} x.x.x.x:2377
Error response from daemon: Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the “docker info” command to see the current swarm status of your node.
에러가 나서 식겁했지만 에러메세지를 찬찬히 읽어보니 백그라운드로 계속 시도한다고 해서 잠시 시 뒤에 다시 확인하였습니다.
$ docker info
…
Swarm: active
NodeID: xxxx
Is Manager: true
ClusterID: yyyy
Managers: 2
…
Manager Addresses:
x.x.x.x:2377
x.x.x.y:2377
…
manager가 2대 잘 들어가 있습니다. worker도 잘 들어가 있나 확인했습니다.
$ docker info
…
Swarm: active
NodeID: xyxyxyxyxyxyxy
Is Manager: false
Node Address: a.b.c.z
Manager Addresses:
x.x.x.x:2377
x.x.x.y:2377
…
저와 같은 실수를 하는 분 or manager 하나가 죽을 것을 대비하여 manager 1개를 더 추가해서 3 manager 체제를 갖추기로 하였습니다. (swarm 문서를 봐도 3, 5, … 이렇게 홀수를 맞추도록 가이드하고 있습니다.)
$ docker swarm join — token {token} x.x.x.x:2377
This node joined a swarm as a manager.
제대로 설정됐는지 확인합니다.
$ docker info
…
Swarm: active
NodeID: xxxxxxxxx
Is Manager: true
ClusterID: yyyyyyyyy
Managers: 3
…
Manager Addresses:
x.x.x.x:2377
x.x.x.y:2377
x.x.x.z:2377
…
마지막으로 worker에도 제대로 인식하고 있는지 확인합니다.
$ docker info
…
Swarm: active
NodeID: xyxyxyxyxyxyxy
Is Manager: false
Node Address: a.b.c.z
Manager Addresses:
x.x.x.x:2377
x.x.x.y:2377
x.x.x.z:2377
…
해결!!!!!
참고
https://docs.docker.com/engine/swarm/admin_guide/
https://docs.docker.com/engine/swarm/raft/