docker-compose.ymlを作る
version: '3.3'
services:
db:
build: db
image: dockersamples/k8s-wordsmith-db
words:
build: words
image: dockersamples/k8s-wordsmith-api
deploy:
replicas: 5
web:
build: web
image: dockersamples/k8s-wordsmith-web
ports:
- "33000:80"
docker stack deploy --orchestrator=kubernetes -c docker-compose.yml composek8s
実行結果
Ignoring unsupported options: build
service "db": build is ignored
service "words": build is ignored
service "web": build is ignored
Waiting for the stack to be stable and running...
db: Ready [pod status: 1/1 ready, 0/1 pending, 0/1 failed]
db: Ready [pod status: 1/1 ready, 0/1 pending, 0/1 failed]
web: Ready [pod status: 1/1 ready, 0/1 pending, 0/1 failed]
words: Ready [pod status: 1/5 ready, 4/5 pending, 0/5 failed]
Stack composek8s is stable and running
ブラウザからアクセスできるようになりますhttp://localhost:33000
実行状況を調べてみます
# docker stack ps --orchestrator=kubernetes composek8s
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
598abba7-0f6 composek8s_db-74444fddf7-s8nxf dockersamples/k8s-wordsmith-db docker-desktop Running Running 4 minutes ago
598f1b70-0f6 composek8s_web-6d968c7bf6-mxjxt dockersamples/k8s-wordsmith-web docker-desktop Running Running 4 minutes ago *:0->80/tcp
59931520-0f6 composek8s_words-58bcc78668-2fpkt dockersamples/k8s-wordsmith-api docker-desktop Running Running 4 minutes ago
5994ca2c-0f6 composek8s_words-58bcc78668-b8spk dockersamples/k8s-wordsmith-api docker-desktop Running Running 4 minutes ago
59984bde-0f6 composek8s_words-58bcc78668-q4675 dockersamples/k8s-wordsmith-api docker-desktop Running Running 4 minutes ago
5994b923-0f6 composek8s_words-58bcc78668-v5b7s dockersamples/k8s-wordsmith-api docker-desktop Running Running 4 minutes ago
59983152-0f6 composek8s_words-58bcc78668-z92cj dockersamples/k8s-wordsmith-api docker-desktop Running Running 4 minutes ago
# docker stack services --orchestrator=kubernetes composek8s
ID NAME MODE REPLICAS IMAGE PORTS
598fcb50-0f6 composek8s_db replicated 1/1 dockersamples/k8s-wordsmith-db
5992bb76-0f6 composek8s_web replicated 1/1 dockersamples/k8s-wordsmith-web *:33000->80/tcp
599e9c71-0f6 composek8s_words replicated 5/5 dockersamples/k8s-wordsmith-api
別途 kubectl get all
など kubectl
コマンドも使える模様。
コンテナを停止します
$ docker stack rm --orchestrator=kubernetes composek8s
Removing stack: composek8s