728x90
λ°μν
13μ₯ λ컀 μ€μ μ€νμΌλ‘ λΆμ° μ ν리μΌμ΄μ λ°°ν¬νκΈ°
- 12μ₯μμλ CLI λ₯Ό μ¬μ©νμ¬ λ§€λμ λ Έλμ μ§μ μ μνμ¬ λ컀 μ€μμ μ‘°μνμλ€.
- κ·Έλ¬λ, μ€λ¬΄μμλ YAML νμΌμ μμ±νμ¬ λ§€λμ λ Έλμκ² μ λ¬νκ³ , ν΄λΉ μ€νμ μ€μΌμ€νΈλ μ΄μ λꡬμκ² λ§‘κΈ΄λ€.
13.1 λ컀 μ»΄ν¬μ¦λ₯Ό μ¬μ©ν μ΄μ νκ²½
- μ€μ λͺ¨λμμλ μ ν리μΌμ΄μ μ λ°°ν¬ν λ μ€νμ λ§λ λ€.
- μ΄λ₯Ό λ컀 μ€νμ΄λΌκ³ λΆλ₯Έλ€.
- λ컀 μ€νμ μλΉμ€, λ€νΈμν¬, λ³Όλ₯¨ λ± μ¬λ¬κ°μ λ컀 리μμ€λ₯Ό λ¬Άμ΄ λ§λ 리μμ€λ₯Ό λ§νλ€.
- λ컀 μ€μλ λ컀 μ»΄ν¬μ¦λ₯Ό ν΅ν΄ μ ν리μΌμ΄μ μ λ°°ν¬ν μ μλ€.
version: "3.7"
services:
todo-web:
image: diamol/ch06-todo-list
ports:
- 8080:80
$ docker stack deploy -c v1.yml todo
Creating network todo_default
Creating service todo_todo-web
$ docker stack ls
NAME SERVICES
todo 1
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
lgx4shrj1zim timecheck replicated 1/1 diamol/ch12-timecheck:2.0
nkivluuthhbt todo_todo-web replicated 1/1 diamol/ch06-todo-list:latest *:8080->80/tcp
- λ³λμ μΆκ° μ€μ μμ΄ μ»΄ν¬μ¦ νμΌλ§μΌλ‘ μ€μμ μ ν리μΌμ΄μ μ λ°°ν¬ν μ μλ€.
- μ€μμ λ Έλκ° λ κ° μ΄μμ΄λΌλ©΄ κ³ κ°μ©μ±μ ν보ν μ μλ€.
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
kjbzig78v53j todo_default overlay swarm
$ doker network inspect todo_default
...
"Containers": {
"6c9a69029d95785de16796d6ca6246f1db54f13a89d6a589dcc5e62cb6b15465": {
"Name": "todo_todo-web.1.69aowjhftvrsnx5vt1w9m9yvx",
"EndpointID": "f2b19805a184b854e0d2ef7ab9899fc21639f8c5de98b8bf00de806bd024bfb2",
"MacAddress": "02:42:0a:00:01:03",
"IPv4Address": "10.0.1.3/24",
"IPv6Address": ""
},
"lb-todo_default": {
"Name": "todo_default-endpoint",
"EndpointID": "687226b6eaba16bbf30bf52987bbc48c0ae126afc87b6816bb30309d4878b61f",
"MacAddress": "02:42:0a:00:01:04",
"IPv4Address": "10.0.1.4/24",
"IPv6Address": ""
}
},
...
- lb-todo_default λ λ컀 μ€μμ λ΄μ₯λ Load Balancer μ΄λ€.
- λ컀 μ€μμμ μλΉμ€λ₯Ό λ°°ν¬ν λ, μλΉμ€μ νμν λ€νΈμν¬μ λ‘λ λ°Έλ°μκ° μλμΌλ‘ μμ±λλ€.
- μ΄κ²μ λ컀μ λΌμ°ν λ©μ¬(Routing Mesh) κΈ°λ₯μ μΌλΆλ‘, κ° μλΉμ€μ λν μμ²μ λ°μ μ μ ν λ Έλλ‘ λΌμ°ν νλ μν μ νλ€.
- μ΄λ₯Ό ν΅ν΄ ν΄λΌμ΄μΈνΈλ μ΄λ λ Έλμ μ°κ²°νλ λμΌν μλΉμ€μ μμΈμ¬ ν μ μλ€.
services:
todo-web:
image: diamol/ch06-todo-list
ports:
- 8080:80
deploy:
replicas: 2
resources:
limits:
cpus: "0.50"
memory: 10M
- ν λ νλ¦¬μΉ΄κ° CPU μ½μ΄μ κ²½μ° ν κ°μ 50%, λ©λͺ¨λ¦¬μ κ²½μ° 100MB κΉμ§ μ μ ν μ μλλ‘ μ€μ .
- λ컀 컨ν μ΄λλ μνμΉλ₯Ό μ§μ νμ§ μμΌλ©΄ νΈμ€νΈ μ»΄ν¨ν°μ CPUμ λ©λͺ¨λ¦¬λ₯Ό 무μ νμΌλ‘ μ¬μ©ν μ μλ€.
- μ΄μ νκ²½μμ μμ€ν μμμ κ³ κ°μν€λ μΌμ΄ μλλ‘ μ μ½μ λμ΄μΌ νλ€.
$ docker stack deploy -c ./todo-list/v2.yml todo
$ docker service ps todo_todo-web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
43b74g52i4sv todo_todo-web.1 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Running Running 42 seconds ago
69aowjhftvrs \\_ todo_todo-web.1 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Shutdown Shutdown 43 seconds ago
qeyvclqj6gv5 todo_todo-web.2 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Running Running 46 seconds ago
- μμ λ YAML νμΌμ 맀λμ λ Έλμ μ λ¬νλ©΄ μ ν리μΌμ΄μ μ λ°μλλ€.
μ€μ μ€νμ μ ν리μΌμ΄μ μ κ·Έλ£Ήννλ λ°©λ²μΌλ‘ νμλλ€.
ν΄λ¬μ€ν°λ λ§μ μμ μ ν리μΌμ΄μ μ μ€ννκΈ° λλ¬Έμ μ ν리μΌμ΄μ λ κ·Έλ£ΉμΌλ‘ λ§λ€μ΄ κ΄λ¦¬ν΄μΌ νλ€.
stack λͺ λ Ήμ΄λ₯Ό ν΅ν΄ κ·Έλ£Ήνλ μ ν리μΌμ΄μ μ μ μ΄ν μ μλ€.
$ docker stack services todo
ID NAME MODE REPLICAS IMAGE PORTS
nkivluuthhbt todo_todo-web replicated 2/2 diamol/ch06-todo-list:latest *:8080->80/tcp
$ docker stack ps todo
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
43b74g52i4sv todo_todo-web.1 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Running Running 3 minutes ago
69aowjhftvrs \\_ todo_todo-web.1 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Shutdown Shutdown 3 minutes ago
qeyvclqj6gv5 todo_todo-web.2 diamol/ch06-todo-list:latest ubuntu-linux-22-04-desktop Running Running 4 minutes ago
$ docker stack rm todo
Removing service todo_todo-web
Removing network todo_default
- ν΄λ¬μ€ν° λ°μ΄ν°λ² μ΄μ€μ μ ν리μΌμ΄μ μ λν λͺ¨λ μ μκ° λ€μ΄ μκΈ° λλ¬Έμ μ»΄ν¬μ¦ νμΌμ΄ μμ΄λ μ€νμ λͺ¨λ 리μμ€λ₯Ό κ΄λ¦¬ν μ μλ€.
- 맀λμ λ Έλλ λͺ¨λ μ΄ λ°μ΄ν°λ² μ΄μ€μ 볡μ¬λ³Έμ κ°μ§κ³ μκΈ° λλ¬Έμ λ€λ₯Έ 리μμ€μ λν μ 보λ₯Ό μμ νκ² λ³΄κ΄ν μ μλ€.
13.2 Config κ°μ²΄λ₯Ό μ΄μ©ν μ€μ κ° κ΄λ¦¬
- λ컀 μ€μμμλ docker config λ₯Ό ν΅ν΄ μ€μ κ°μ 컨ν μ΄λκ° μλ ν΄λ¬μ€ν°μ μ μ₯νμ¬ μ€μ μ§μ€μ κ΄λ¦¬κ° κ°λ₯νλ€.
- λ€μν νκ²½ (κ°λ°, ν μ€νΈ, μ΄μ) λ±μ λ§λ μ€μ κ°μ λ³λμ Config κ°μ²΄λ‘ κ΄λ¦¬ν μ μλ€.
- λν, μ ν리μΌμ΄μ μ λ°°ν¬μ μ€μ κ΄λ¦¬λ₯Ό λΆλ¦¬νμ¬ κ΄λ¦¬μ μ μ°μ±μ λμΈλ€.
$ docker config create todo-list-config configs/config.json
$ docker config ls
ID NAME CREATED UPDATED
cp74vnymk8x4brh7wix1fzgx3 todo-list-config 3 seconds ago 3 seconds ago
- config κ°μ²΄λ JSON, XML, Key-Value, Binary λ± λ€μν λ°μ΄ν° ν¬λ§·μ λ΄μ μ μλ€.
- config κ°μ²΄λ μ€μμ μν΄ μ»¨ν μ΄λ νμΌ μμ€ν λ΄λΆμ νμΌλ‘ μ λ¬λλ€.
- config κ°μ²΄λ CLI λ₯Ό ν΅ν΄ μμ±, μμ , νμΈμ΄ λͺ¨λ κ°λ₯νλ€. λν, μ€μ λ°μ΄ν°λ² μ΄μ€ λ΄μμ νμΌ λ΄μ©μ μνΈν λμ§ μλλ€.
- λ°λΌμ, λ―Όκ°ν¨ λ°μ΄ν°λ₯Ό 보κ΄νκΈ° μ μ νμ§ μλ€.
$ docker config inspect todo-list-config
[
{
"ID": "cp74vnymk8x4brh7wix1fzgx3",
"Version": {
"Index": 199
},
"CreatedAt": "2024-12-12T02:35:45.784057075Z",
"UpdatedAt": "2024-12-12T02:35:45.784057075Z",
"Spec": {
"Name": "todo-list-config",
"Labels": {},
"Data": "ew0KICAiTG9nZ2luZyI6IHsNCiAgICAiTG9nTGV2ZWwiOiB7DQogICAgICAiRGVmYXVsdCI6ICJJbmZvcm1hdGlvbiIsDQogICAgICAiTWljcm9zb2Z0IjogIldhcm5pbmciLA0KICAgICAgIk1pY3Jvc29mdC5Ib3N0aW5nLkxpZmV0aW1lIjogIldhcm5pbmciDQogICAgfQ0KICB9LA0KICAiQWxsb3dlZEhvc3RzIjogIioiLA0KICAiRGF0YWJhc2UiOiB7DQogICAgIlByb3ZpZGVyIjogIlBvc3RncmVzIg0KICB9DQp9DQo="
}
}
]
$ docker config inspect --pretty todo-list-config
ID: cp74vnymk8x4brh7wix1fzgx3
Name: todo-list-config
Created at: 2024-12-12 02:35:45.784057075 +0000 utc
Updated at: 2024-12-12 02:35:45.784057075 +0000 utc
Data:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Warning"
}
},
"AllowedHosts": "*",
"Database": {
"Provider": "Postgres"
}
}
- --pretty λͺ λ Ήμ΄λ₯Ό μ¬μ©ν κ²½μ° config λ΄λΆμ λ°μ΄ν°λ₯Ό νμΈν μ μλ€.
$ echo 'ew0KICAiTG9nZ2luZyI6IHsNCiAgICAiTG9nTGV2ZWwiOiB7DQogICAgICAiRGVmYXVsdCI6ICJJbmZvcm1hdGlvbiIsDQogICAgICAiTWljcm9zb2Z0IjogIldhcm5pbmciLA0KICAgICAgIk1pY3Jvc29mdC5Ib3N0aW5nLkxpZmV0aW1lIjogIldhcm5pbmciDQogICAgfQ0KICB9LA0KICAiQWxsb3dlZEhvc3RzIjogIioiLA0KICAiRGF0YWJhc2UiOiB7DQogICAgIlByb3ZpZGVyIjogIlBvc3RncmVzIg0KICB9DQp9DQo=' | base64 --decode
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Warning"
}
},
"AllowedHosts": "*",
"Database": {
"Provider": "Postgres"
}
}
- docker config inspect μμ data λΈλ‘μ κ²½μ° μμ κ°μ΄ λμλ‘ λμ΄λ³΄μ΄μ§λ§, μ€μ λ‘λ base64 λ‘ μΈμ½λ© λμ΄μλ€.
$ vi v3.yml
services:
todo-web:
image: diamol/ch06-todo-list
ports:
- 8080:80
configs:
- source: todo-list-config
target: /app/config/config.json
configs:
todo-list-config:
external: true
$ docker stack deploy -c ./todo-list/v3.yml todo
$ docker stack services todo
- configs λͺ λ Ήμ΄λ₯Ό ν΅ν΄ 컨ν μ΄λ νμΌ μμ€ν μ ν΅ν΄ μλΉμ€μ μ λ¬νλ€.
13.3 λΉλ°κ°μ μ΄μ©ν λμΈλΉ μ€μ μ 보 κ΄λ¦¬νκΈ°
A. λΉλ°κ°μ λ‘컬 νμΌλ‘ λΆν° μμ±νλ€.
B. ν΄λ¬μ€ν° λ°μ΄ν° λ² μ΄μ€μ μ μ₯ν ν, μλΉμ€ μ μμμ λΉλ°κ°μ μ°Έμ‘°νλ€.
C. 컨ν μ΄λ νμΌ μμ€ν μ λΉλ°κ°μ κ°μ΄ μ λ¬λλ€.
컨ν μ΄λμ μ λ¬λ μνμμλ§ λ³΅νΈνλ λΉλ°κ°μ λ³Ό μ μλ€.
$ docker secret create todo-list-secret ./secrets/secrets.json
odjwu3st7x9acnkuuwaqfsmxv
$ docker secret inspect --pretty todo-list-secret
ID: odjwu3st7x9acnkuuwaqfsmxv
Name: todo-list-secret
Driver:
Created at: 2024-12-12 07:23:35.210486454 +0000 utc
Updated at: 2024-12-12 07:23:35.210486454 +0000 utc
$ vi v4.yml
services:
todo-web:
image: diamol/ch06-todo-list
ports:
- 8080:80
configs:
- source: todo-list-config
target: /app/config/config.json
secrets:
- source: todo-list-secret
target: /app/config/secrets.json
deploy:
replicas: 1
resources:
limits:
cpus: "0.50"
memory: 100M
networks:
- app-net
todo-db:
image: diamol/postgres:11.5
deploy:
replicas: 1
resources:
limits:
cpus: "0.50"
memory: 500M
networks:
- app-net
configs:
todo-list-config:
external: true
secrets:
todo-list-secret:
external: true
networks:
app-net:
$ docker stack deploy -c v4.yml todo
- config κ°μ²΄μ λΉλ°κ°μ μμ μ΄ λΆκ°νλ€.
- λ§μ½, λ³κ²½ν κ²½μ° μλ‘μ΄ config κ°μ²΄λ λΉλ°κ°μ λ§λ€μ΄μΌ νλ€.
- λν, κΈ°μ‘΄μ μ¬μ©νλ config κ°μ²΄μ λΉλ°κ°μ λ³κ²½νμ¬ λ³κ²½λ docker-compose νμΌλ‘ μ€νμ λ°°ν¬ν΄μΌ νλ€.
- μ¦, μ€μ κ°μ μμ ν κ²½μ° μλ‘ λ°°ν¬ν΄μΌλλ©°, 컨ν μ΄λλ₯Ό μ κ²μΌλ‘ κ΅μ²΄ν΄μΌ νλ€.
13.4 μ€μμμ λ³Όλ₯¨ μ¬μ©νκΈ°
- ν΄λ¬μ€ν° == μ¬λ¬ κ°μ λ Έλ
- κ°μ₯ κ°λ¨ν λ°©λ²μ κ° λ Έλλ κ°μμ λ‘컬 λ³Όλ₯¨μ μ¬μ©νμ¬ λ°μ΄ν°λ₯Ό μ μ₯.
- κ·Έλ¬λ, μλ‘μ΄ λ νλ¦¬μΉ΄κ° λ€λ₯Έ λ Έλμμ μ€νλ κ²½μ°. κΈ°μ‘΄μ κ° λ νλ¦¬μΉ΄κ° μ¬μ©νλ λ‘컬 λ³Όλ₯¨μ μ κ·Όν μ μλ€.
- λν, λ ν리카λ§λ€ λ°μ΄ν°κ° λ€λ₯Ό μλ μλ λ‘컬 λ³Όλ₯¨μ μ¬λ¬ λ Έλμ κ±Έμ³ μνλ₯Ό 곡μ ν΄μΌ νλ μ ν리μΌμ΄μ μμλ μ¬μ©ν μ μλ€.
- μ΄λ₯Ό ν΄κ²°νλ €λ©΄ λ Έλμ λ μ΄λΈμ λΆμ¬νκ³ μ»΄ν¬μ¦ νμΌμμ ν΄λΉ λ Έλμμλ§ λ ν리카λ₯Ό μ€ννλλ‘ κ°μ νλ©΄ λλ€.
$ docker node update --label-add storage=raid $(docker node ls -q)
nnhjjc81yf5s7oegxl90ks9a3
- λ Έλμ μλ³μλ₯Ό μ°Ύμ, ν΄λΉ λ Έλμ λ μ΄λΈμ λΆμ¬.
- μ΄λ₯Ό μ΄μ©ν΄ μλΉμ€ λ νλ¦¬μΉ΄κ° μ€νλλ λ Έλλ₯Ό μ ν.
$ vi v5.yml
services:
...
todo-db:
image: diamol/postgres:11.5
volumes:
- todo-db-data:/var/lib/postgresql/data
deploy:
placement:
constraints:
- node.labels.storage == raid
...
volumes:
todo-db-data:
$ docker stack deploy -c ./todo-list/v5.yml todo
$ docker volume ls -q
f0de882b5d123c16edc48181ddfc8275fb5b86e334b74b8cf007effb02749e59
f2a8643d59c8393a997f6dbca50cc52a869f38aee75d29defdc98483767f4d85
todo_todo-db-data
- constraints μ€μ μ ν΅ν΄ μ μ½ μ‘°κ±΄μ μ€μ ν μ μλ€.
- κΈ°λ³Έ λ³Όλ₯¨μ μ€νμ μ κ±°νλ©΄ μμ λλ€.
- κ·Έλ¬λ, μ΄λ¦μ΄ λΆμ¬λ λ³Όλ₯¨μ μ€νμ μ κ±°ν΄λ μμ λμ§ μλλ€.
- μ΄λ κ² λ°°ν¬λ μ ν리μΌμ΄μ μ μ€νμ μ κ±°νλλΌλ, λ°μ΄ν°κ° μ μ€λμ§ μμΌλ©°, 컨ν μ΄λκ° κ΅μ²΄λμ΄λ μ 컨ν μ΄λ μμ κ°μ λ Έλμμ κ°μ λ³Όλ₯¨μ μ°κ²°ν΄ μ¬μ©νλ€.
13.5 ν΄λ¬μ€ν°λ μ€νμ μ΄λ»κ² κ΄λ¦¬νλκ°?
λ컀 μ€μμμ μ€νμ ν΄λ¬μ€ν°κ° κ΄λ¦¬λ₯Ό λ΄λΉνλ 리μμ€μ λͺ¨μμ΄λ€.
- μ€μλ λ³Όλ₯¨μ μμ±, μμ ν μ μλ€.
- μλΉμ€ μ΄λ―Έμ§μ λ³Όλ₯¨μ μ μκ° ν¬ν¨λ κ²½μ°, μ€νλ κΈ°λ³Έ λ³Όλ₯¨μ μμ±νμ§λ§, κΈ°λ³Έ λ³Όλ₯¨μ μ€νμ μ κ±°νλ©΄ ν¨κ» μ κ±°λλ€.
- μ€ν μ μμ μ΄λ¦μ΄ λΆμ λ³Όλ₯¨μ μ¬μ©νλ©΄ μ€ν λ°°ν¬μ ν¨κ» λ³Όλ₯¨μ΄ μμ±λμ§λ§, μ€νμ μ κ±°ν΄λ μμ λμ§ μλλ€.
- λΉλ°κ°κ³Ό config κ°μ²΄λ μ€μ κ°μ΄ λ νμΌμ ν΄λ¬μ€ν°μ μ
λ‘λνλ λ°©λ²μΌλ‘ μμ±νλ€.
- ν΄λ¬μ€ν° DB → 컨ν μ΄λ μ€ν → 컨ν μ΄λ νμΌ μμ€ν μμ±.
- read-only λ‘ μμ μ΄ λΆκ°.
- μ€μ νκ²½μμ μ ν리μΌμ΄μ μ€μ κ΄λ¦¬λ λ°°ν¬ νλ‘μΈμ€μ λ³κ°.
- λ€νΈμν¬λ μ ν리μΌμ΄μ
κ³Ό λ³λλ‘ κ΄λ¦¬λλ€.
- λͺ μμ λ€νΈμν¬ μμ±, λ컀 μ€μμ νμμ μν μμ±.
- λͺ¨λ μ€νμ μ»΄ν¬μ¦ νμΌμ λ€νΈμν¬κ° μ μλμ§ μλλΌλ, ν¬ν¨λμ΄ μλ μλΉμ€λ₯Ό μ°κ²°ν λ€νΈμν¬μ ν¨κ» λ°°ν¬λλ€.
- μλΉμ€λ μ€νμ΄ λ°°ν¬λ λ μμ±λκ±°λ μ κ±°λλ€.
- μ€νκ³Ό μμ μ£ΌκΈ°λ₯Ό ν¨κ»νλ€.
- ν¬μ€ 체ν¬λ₯Ό ν΅ν΄ μ΄μμ΄ κ²μΆλ 컨ν μ΄λλ μλ‘μ΄ μ»¨ν μ΄λλ‘ κ΅μ²΄λλ€.
728x90
λ°μν