도커 스웜swarm 은 도커에서 제공하는 오케스트레이션Orchestration 도구이다.

Note
Cluster
  • 서버의 부하를 줄이고 최대 가용성을 뽑아내기 위해 나온 기술

  • 여러 장비를 하나의 묶음으로 취급하는 걸 의미

Note
스웜 클러스터
  • 스웜 클러스터 자체를 스웜이라고도 한다.

  • 도커 스웜이란 도커에서 제공하는 클러스터.

  • 쿠버네티스는 클러스터를 관리하는 도구이다.

모니터링

portainer 설치하기
$ mkdir /home/apps/portainer_host_data
$ docker service create \
    --name portainer \
    --publish 9000:9000 \
    --replicas=1 \
    --constraint 'node.role == manager' \
    --mount type=bind,src=/home/apps/portainer_host_data,dst=/data \
    --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock
    portainer/portainer

클러스터 생성하기

$ docker swarm init --advertise-addr 10.106.148.138
Swarm initialized: current node (uav8ow31vi4xwzevfuea27fu7) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-0ak1au0d6flegmgdig5889l14se3rbv9ngij9ljxj6en38ngh4-0guamgmlx492ffp0g6k6b9lfi 10.106.148.138:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
  • 매니저 노드가 생성되었다.

위 명령어를 다른 노드에서 실행시켜 준다.

워커 노드에 명령어 실행하기

$ docker swarm join --token SWMTKN-1-0ak1au0d6flegmgdig5889l14se3rbv9ngij9ljxj6en38ngh4-0guamgmlx492ffp0g6k6b9lfi 10.106.148.138:2377
This node joined a swarm as a worker.

워커 노드에 명령어 실행하기 with ansible

Note
ansible

install

$ sudo yum install epel-release
$ sudo yum install ansible
ssh key 생성하기
$ ssh-keygen -t rsa -C "key for ansible" -f "ansible_rsa"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/.ssh/id_rsa):
Created directory '/home/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/.ssh/id_rsa.
Your public key has been saved in /home/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0g4FGbkkxKJ7qZDriIS3UPwKHgI4Iohbmp55V1NTWH4 user@host
The key's randomart image is:
+---[RSA 2048]----+
|   o. o+  o.     |
|  . o +. ...     |
| . . o .. .. E   |
|=.    .o o  .    |
|Oo+.  o S .      |
|OBo.   *         |
|X*. . . o        |
|X+++ .           |
|+*+ .            |
+----[SHA256]-----+
ssh key 복사하기
$ ssh-copy-id -i ansible_agent_rsa.pub user@host.infra.io