카타코더 도커스웜 - Load Balance and Service Discover in Swarm Mode

1 개요[ | ]

카타코더 Docker Swarm Mode
# 🔗 제목
카타코더 Docker Swarm Mode e
🔗 카타코더 도커스웜 - Getting Started With Swarm Mode
🔗 카타코더 도커스웜 - Create Overlay Network
🔗 카타코더 도커스웜 - Load Balance and Service Discover in Swarm Mode
🔗 카타코더 도커스웜 - Apply Rolling Updates Across Swarm Cluster
🔗 카타코더 도커스웜 - Add Healthcheck for Containers
🔗 카타코더 도커스웜 - Deploy Swarm Services with Compose v3
🔗 카타코더 도커스웜 - Keeping Secrets with Docker Swarm
🔗 카타코더 도커스웜 - Create Encrypted Overlay Network
🔗 카타코더 도커스웜 - Enable Maintenance Mode for a Swarm Node
🔗 카타코더 도커스웜 - Deploying a UI Dashboard for Swarm
🔗 카타코더 도커스웜 - Graphing Docker Metrics with Prometheus

2 Step 1 - Initialise Cluster[ | ]

host1
$ docker swarm init
Swarm initialized: current node (78l213o59a0qrvqaktjwzadjb) is now a manager.

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

    docker swarm join --token SWMTKN-1-17fwx9go5e9y0auo46oifetgfr63i2kyojnm5q72ntcd2m43ud-b2p4lenmbaxmml9boqcangiqj 172.17.0.34:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
host2
$ docker swarm join 172.17.0.34:2377 --token $(docker -H 172.17.0.34:2345 swarm join-token -q worker)
This node joined a swarm as a worker.

3 Step 2 - Port Load Balance[ | ]

host1
$ docker service create --name lbapp1 --replicas 2 -p 81:80 katacoda/docker-http-server
nqgl2f9ru9nunq5jpzhtjoa78
overall progress: 2 out of 2 tasks
1/2: running
2/2: running
verify: Service converged
$ curl docker:81
<h1>This request was processed by host: 6c8061751966</h1>
$ curl docker:81
<h1>This request was processed by host: bb574e93aeb9</h1>
host2
$ curl docker:81
<h1>This request was processed by host: 6c8061751966</h1>
$ curl docker:81
<h1>This request was processed by host: bb574e93aeb9</h1>

4 Step 3 - Virtual IP and Service Discovery[ | ]

host1
$ docker network create --attachable -d overlay eg1
wdslwv9vjx8s0ae4zfto3f5x1
$ docker service create --name http --network eg1 --replicas 2 katacoda/docker-http-server
laj3xa8bd7freqtyx2i186u6g
overall progress: 2 out of 2 tasks
1/2: running
2/2: running
verify: Service converged
$ docker run --name=dig --network eg1 benhall/dig dig http

; <<>> DiG 9.10.2 <<>> http
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27290
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;http.                          IN      A

;; ANSWER SECTION:
http.                   600     IN      A       10.0.0.4

;; Query time: 5 msec
;; SERVER: 127.0.0.11#53(127.0.0.11)
;; WHEN: Tue May 07 05:36:03 UTC 2019
;; MSG SIZE  rcvd: 42
$ docker run --name=ping --network eg1 alpine ping -c5 http
PING http (10.0.0.4): 56 data bytes
64 bytes from 10.0.0.4: seq=0 ttl=64 time=0.043 ms
64 bytes from 10.0.0.4: seq=1 ttl=64 time=0.079 ms
64 bytes from 10.0.0.4: seq=2 ttl=64 time=0.085 ms
64 bytes from 10.0.0.4: seq=3 ttl=64 time=0.074 ms
64 bytes from 10.0.0.4: seq=4 ttl=64 time=0.074 ms

--- http ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.043/0.071/0.085 ms
$ docker service inspect http --format="{{.Endpoint.VirtualIPs}}"
[{wdslwv9vjx8s0ae4zfto3f5x1 10.0.0.4/24}]
$ docker inspect --format="{{.NetworkSettings.Networks.eg1.IPAddress}}" $(docker ps | grep docker-http-server | head -n1 | awk '{print $1}')
10.0.0.5

5 Step 4 - Multi-Host LB and Service Discovery[ | ]

$ docker network create -d overlay app1-network
m1p1rnb1xa4cnl6xowuir58m4
$ docker service create --name redis --network app1-network redis:alpine
ou0y8gxicrmu6yuvafdm4izqz
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
$ docker service create --name app1-web --network app1-network --replicas 4 -p 80:3000 katacoda/redis-node-docker-example
2ftjpwiopav5j2lhexxuqx8as
overall progress: 4 out of 4 tasks
1/4: running
2/4: running
3/4: running
4/4: running
verify: Service converged
$ docker ps
CONTAINER ID        IMAGE                                       COMMAND                CREATED             STATUS              PORTS   NAMES
192ba316d9c6        katacoda/redis-node-docker-example:latest   "npm start"              32 seconds ago      Up 29 seconds       3000/tcp   app1-web.1.qst9qud6y0hazlluiru5rgmlz
4fe46639f9ed        katacoda/redis-node-docker-example:latest   "npm start"              32 seconds ago      Up 30 seconds       3000/tcp   app1-web.3.qkqoqt61y76bd4bylwtzz5ulz
876974d5d7e2        redis:alpine                                "docker-entrypoint.s…"   50 seconds ago      Up 48 seconds       6379/tcp   redis.1.o0i4f4zybnzdxpybuncmnv6z9
7ecc149a4f90        katacoda/docker-http-server:latest          "/app"                2 minutes ago       Up 2 minutes        80/tcp   http.1.jwuhfk5x6to8txmuut8bsfapa
bb574e93aeb9        katacoda/docker-http-server:latest          "/app"                4 minutes ago       Up 4 minutes        80/tcp   lbapp1.2.2wz39bu6y635peodhpcggzm2t
$ curl docker
This page was generated after talking to redis.

Application Build: 1

Total requests: 1

IP count:
    ::ffff:10.255.0.2: 1
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}