이 포스트는 Korea Azure User Group에서 진행하는 Docker/Container 스터디 그룹에 참여하며 작성했습니다.
스터디를 진행한 Katacoda 강좌: Docker & Containers/Orchestration
진행한 강의 목록
- Enable Maintenance Mode for a Swarm Node
- Deploying a UI Dashboard for Swarm
- Graphing Docker Metrics with Prometheus
스터디는 Katacoda의 화면을 참조하되, 실습은 제 개인 PC에서 VM을 구성해서 진행했습니다. 따라해볼 수 있는 것만 별도로 정리했습니다.
구성환경
- Windows 10 Pro 1809
- Hyper-V
- CentOS 7.6.1810 (Kernel 4.20.2-1.el7)
내용 정리
Swarm 으로 배포한 서비스의 노드에 대해 유지보수모드를 활성화 및 비활성화 하는 방법을 익혀보자.
서비스를 하나 배포한다.
[root@docker-master home]# docker service create --name lbapp1 --replicas 2 -p 80:80 katacoda/docker-http-server
mkenes2jmxbeshxe4cfhaol9s
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
[root@docker-master home]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
mkenes2jmxbe lbapp1 replicated 2/2 katacoda/docker-http-server:latest *:80->80/tcp
[root@docker-master home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9caa14258a81 katacoda/docker-http-server:latest "/app" 25 seconds ago Up 24 seconds 80/tcp lbapp1.2.4h8k7svestmmplbjmqfx1zkrn
node의 leader를 work 변수로 입력한다.
[root@docker-master home]# worker=$(docker node ls | grep -v "Leader" | awk '{print $1}' | tail -n1); echo $worker
psvof4rkv74wtd4vg6rmuqjtg
[root@docker-master home]# docker node update $worker --availability=drain # leader node를 drain으로 변경
psvof4rkv74wtd4vg6rmuqjtg
[root@docker-master home]# docker ps # 컨테이너 실행 상태 확인
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae751f151c08 katacoda/docker-http-server:latest "/app" 15 seconds ago Up 11 seconds 80/tcp lbapp1.1.suy2ejdrfll99pcy7l1vculrd
9caa14258a81 katacoda/docker-http-server:latest "/app" 2 minutes ago Up 2 minutes 80/tcp lbapp1.2.4h8k7svestmmplbjmqfx1zkrn
[root@docker-master home]# docker node ls # 하나가 drain이 되었다.
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ltdlolaft6ui125702kry34g4 * docker-master Ready Active Leader 18.09.3
psvof4rkv74wtd4vg6rmuqjtg docker-node01 Ready Drain 18.09.3
[root@docker-master home]# docker node update $worker --availability=active # 다시 활성화
psvof4rkv74wtd4vg6rmuqjtg
[root@docker-master home]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ltdlolaft6ui125702kry34g4 * docker-master Ready Active Leader 18.09.3
psvof4rkv74wtd4vg6rmuqjtg docker-node01 Ready Active 18.09.3
[root@docker-master home]# docker service scale lbapp1=3 # 컨테이너 갯수 변경
lbapp1 scaled to 3
overall progress: 3 out of 3 tasks
1/3: running [==================================================>]
2/3: running [==================================================>]
3/3: running [==================================================>]
verify: Service converged
[root@docker-master home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae751f151c08 katacoda/docker-http-server:latest "/app" About a minute ago Up About a minute 80/tcp lbapp1.1.suy2ejdrfll99pcy7l1vculrd
9caa14258a81 katacoda/docker-http-server:latest "/app" 3 minutes ago Up 3 minutes 80/tcp lbapp1.2.4h8k7svestmmplbjmqfx1zkrn
Docker를 GUI로 관리해보자. 여기서 이용할 것은 portainer 이다.
[root@docker-master home]# docker service create \
--name portainer \
--publish 9000:9000 \
--constraint 'node.role == manager' \
--mount type=bind,src=/host/data,dst=/data \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
portainer/portainer \
-H unix:///var/run/docker.sock
wywilrkbqk45g5rqbzlqzm5f1
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
Portainer를 구성하고 node IP:9000으로 접속하면 다음의 화면이 나온다. 여기서 간단하게 nginx를 배포해보자. {: .align-center}
템플릿으로 이동 {: .align-center}
Nginx 선택후, 이름입력, 포트 지정 {: .align-center} {: .align-center}
접속해서 재대로 배포되었는지 확인 {: .align-center}
Docker의 상태들을 뽑아내기위해 docker 실행 설정파일에 특정 포트로 export 하도록 설정 후 재시작한다.
[root@docker-master home]# echo '{ "metrics-addr" : "127.0.0.1:9323", "experimental" : true }' > /etc/docker/daemon.json
[root@docker-master home]# systemctl restart docker
metrics를 호출하면 겁나 많은 수치들이 뽑혀나온다.
[root@docker-master docker]# curl localhost:9323/metrics
HELP builder_builds_failed_total Number of failed image builds
TYPE builder_builds_failed_total counter
builder_builds_failed_total{reason="build_canceled"} 0
builder_builds_failed_total{reason="build_target_not_reachable_error"} 0
builder_builds_failed_total{reason="command_not_supported_error"} 0
builder_builds_failed_total{reason="dockerfile_empty_error"} 0
builder_builds_failed_total{reason="dockerfile_syntax_error"} 0
builder_builds_failed_total{reason="error_processing_commands_error"} 0
builder_builds_failed_total{reason="missing_onbuild_arguments_error"} 0
builder_builds_failed_total{reason="unknown_instruction_error"} 0
HELP builder_builds_triggered_total Number of triggered image builds
TYPE builder_builds_triggered_total counter
builder_builds_triggered_total 0
......
swarm_store_write_tx_latency_seconds_bucket{le="2.5"} 12
swarm_store_write_tx_latency_seconds_bucket{le="5"} 12
swarm_store_write_tx_latency_seconds_bucket{le="10"} 12
swarm_store_write_tx_latency_seconds_bucket{le="+Inf"} 12
swarm_store_write_tx_latency_seconds_sum 0.008350546
swarm_store_write_tx_latency_seconds_count 12
Docker 의 데이터를 수집할 Prometheus를 구성해보자.
[root@docker-master home]# vi prometheus.yml # 프로메테우스 설정
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9090', '127.0.0.1:9100', '127.0.0.1:9323']
labels:
group: 'prometheus'
프로메테우스 서버 구동
[root@docker-master home]# docker run -d --net=host -v /home/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus-server prom/prometheus
Unable to find image 'prom/prometheus:latest' locally
latest: Pulling from prom/prometheus
697743189b6d: Pull complete
f1989cfd335b: Pull complete
3b4fefe11b0e: Pull complete
0db069764249: Pull complete
2b27dfb5d438: Pull complete
db50c45adf2b: Pull complete
b4879ab320f7: Pull complete
d590dccaabde: Pull complete
c237e9813d88: Pull complete
Digest: sha256:1224ee30a3be668e0b22444773c4c1b750778af492094b6cd375c780c7526e22
Status: Downloaded newer image for prom/prometheus:latest
3d7c4400665135ae91ccdb76269344da46c687ed0d3e4fcb3c84f2891f6afbaf
프로메테우스 수집구 설정
[root@docker-master home]# docker run -d -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" --name=prometheus quay.io/prometheus/node-exporter:v0.13.0 -collector.procfs /host/proc -collector.sysfs /host/sys -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
Unable to find image 'quay.io/prometheus/node-exporter:v0.13.0' locally
v0.13.0: Pulling from prometheus/node-exporter
8ddc19f16526: Pull complete
a3ed95caeb02: Pull complete
8279f336cdd3: Pull complete
81998f54d5a6: Pull complete
Digest: sha256:8f083b308a39bdd5bd42759b67e20e19398e98b291648f397d98ef4b99d9a318
Status: Downloaded newer image for quay.io/prometheus/node-exporter:v0.13.0
4fc9642bfe33a57d96e9c5af4d93aabcd4bd2151159bbd95ca2facf7678366cb
프로메테우스에 접속해본다.
[root@docker-master home]# curl localhost:9100
<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>
metrics 을 붙여서 접속하면 데이터를 잘 뽑고 있는 것을 확인 가능하다.
[root@docker-master home]# curl localhost:9100/metrics
HELP go_gc_duration_seconds A summary of the GC invocation durations.
TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00041340800000000004
go_gc_duration_seconds{quantile="0.25"} 0.000499008
go_gc_duration_seconds{quantile="0.5"} 0.0005073090000000001
go_gc_duration_seconds{quantile="0.75"} 0.0012158210000000002
go_gc_duration_seconds{quantile="1"} 0.0012158210000000002
go_gc_duration_seconds_sum 0.0026355460000000003
go_gc_duration_seconds_count 4
HELP go_goroutines Number of goroutines that currently exist.
TYPE go_goroutines gauge
...
HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
TYPE process_start_time_seconds gauge
process_start_time_seconds 1.55348079911e+09
HELP process_virtual_memory_bytes Virtual memory size in bytes.
TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 1.9406848e+07