Docker/K8S実践コンテナ開発入門@11日目

前回の続きです。

lawrence-twin.hateblo.jp

■デプロイ

docker container exec -it manager \
docker stack deploy -c /stack/todo-mysql.yml todo_mysql

(ymlの書き方でめっちゃ苦戦しました。多分スペルミスとか原因です。
ymlチェッカーでエラーなかったのですが、難しいですね。。。)


■デプロイ後の状態チェック

docker container exec -it manager \
> docker service ls

MySQLコンテナを確認して、初期データを投入する

■MasterコンテナのSwarmの配置先ノード特定

docker container exec -it manager \
docker service ps todo_mysql_master --no-trunc \
--filter "desired-state=running"
<||

■特定したノード情報を元にコンテナに入る
>||
docker container exec -it manager \
docker container exec -it <Name>.<ID> bash

■コンテナに入るコマンドの便利な生成方法
docker container exec -it manager \
docker service ps todo_mysql_master \

    • no-trunc \
    • filter "desired-state=running" \
    • format "docker container exec -it {{.Node}} docker container exec -it {{.Name}}.{{.ID}} bash"

formatオプションは便利ですね。
今後も使いそうなので、よく覚えておいた方が良さそうです。


しかし、10秒ごとにノードが切り替わってコマンドがうまくいかない
■エラー確認

lawrence@Chocolate stack % docker container exec -it manager \
docker service ps todo_mysql_master
ID                  NAME                      IMAGE                              NODE                DESIRED STATE       CURRENT STATE                     ERROR                       PORTS
huc00dk61va0        todo_mysql_master.1       registry:5000/ch04/tododb:latest   9faf7c495460        Running             Starting less than a second ago                               
vfuazbxk9pwu         \_ todo_mysql_master.1   registry:5000/ch04/tododb:latest   df3dbe8791b9        Shutdown            Failed 1 second ago               "task: non-zero exit (1)"   
zxrq6zvedeg0         \_ todo_mysql_master.1   registry:5000/ch04/tododb:latest   c48536c0b727        Shutdown            Failed about a minute ago         "task: non-zero exit (1)"   
zs0o8i02se3n         \_ todo_mysql_master.1   registry:5000/ch04/tododb:latest   9faf7c495460        Shutdown            Failed 3 minutes ago              "task: non-zero exit (1)"   
zv7zgub5hbaf         \_ todo_mysql_master.1   registry:5000/ch04/tododb:latest   df3dbe8791b9        Shutdown            Failed 36 minutes ago             "task: non-zero exit (1)"   
zrslk58wuqj5         \_ todo_mysql_master.1   registry:5000/ch04/tododb:latest   9faf7c495460        Shutdown            Failed 3 hours ago                "task: non-zero exit (1)"  

各タスクが起動しては死んでいるのを繰り返していることがわかります。

■エラー内容チェック

docker container exec -it manager \
docker service logs -f todo_mysql_master

■エラーログ

todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:50+00:00 [Note] [Entrypoint]: Initializing database files
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:50.342301Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:50.548101Z 0 [Warning] InnoDB: New log files created, LSN=45790
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:50.588831Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:50.657169Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0e4178de-8ed5-11ea-8a5a-02420a000220.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:50.659443Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:51.703694Z 0 [Warning] CA certificate ca.pem is self signed.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:51.928162Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:54+00:00 [Note] [Entrypoint]: Database files initialized
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:54+00:00 [Note] [Entrypoint]: Starting temporary server
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:54+00:00 [Note] [Entrypoint]: Waiting for server startup
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.740861Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.742478Z 0 [Note] mysqld (mysqld 5.7.29-log) starting as process 89 ...
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749229Z 0 [Note] InnoDB: PUNCH HOLE support available
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749449Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749491Z 0 [Note] InnoDB: Uses event mutexes
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749573Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749592Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.749602Z 0 [Note] InnoDB: Using Linux native AIO
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.750070Z 0 [Note] InnoDB: Number of pools: 1
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.750382Z 0 [Note] InnoDB: Using CPU crc32 instructions
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.757003Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.768911Z 0 [Note] InnoDB: Completed initialization of buffer pool
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.771980Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.785851Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.799383Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.799513Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.836490Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.837702Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.837729Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.838748Z 0 [Note] InnoDB: Waiting for purge to start
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.889319Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 2629923
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.890109Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.890109Z 0 [Note] Plugin 'FEDERATED' is disabled.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.897249Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200505 13:33:54
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.911070Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.911135Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.914315Z 0 [Warning] CA certificate ca.pem is self signed.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.914428Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.917766Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.923191Z 0 [Note] Failed to start slave threads for channel ''
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.930956Z 0 [Note] Event Scheduler: Loaded 0 events
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05T13:33:54.931529Z 0 [Note] mysqld: ready for connections.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | Version: '5.7.29-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:55+00:00 [Note] [Entrypoint]: Temporary server started.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:58+00:00 [Note] [Entrypoint]: Creating database tododb
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:58+00:00 [Note] [Entrypoint]: Creating user gihyo
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:58+00:00 [Note] [Entrypoint]: Giving user gihyo access to schema tododb
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | 2020-05-05 13:33:58+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/prepare.sh
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | this container is master
todo_mysql_master.1.pvuagvcv51us@c48536c0b727    | /docker-entrypoint-initdb.d/prepare.sh: line 6: return: can only `return' from a function or sourced script

上記のうち、以下ログが気になる。

[Note] Failed to start slave threads for channel ''
/docker-entrypoint-initdb.d/prepare.sh: line 6: return: can only `return' from a function or sourced script

failed エラーは色々調べてますがエラー解消まではたどり着けていません。
returnについては、sourceで呼び出されるとfunctionと誤認してしまって起きるエラーのようです。
解消するとなると、exitを使えば良いのかな?
明日以降また調べてみます。