
Fargeteを覚えると
オンプレでDockerを使わなくても、bashログインもできて本当に便利になった。
ところが、突然bashログインできなくなった♫ その顛末です。
そもそものbashログイン方法(正常時) 参考
- 環境設定
CLUSTER_NAME={ClusterName}
SERVICE_NAME={ServiceName}
TASK_DEF={Task定義Name}
TASK_NAME={ConntaiterRuntimeID}
CONNTAINER_NAME={ConntainerName}
- bash有効の確認
$ aws ecs describe-services \
–cluster ${CLUSTER_NAME} \
–services ${SERVICE_NAME} \
–query ‘services[0].enableExecuteCommand’
true ※falseなら、bash有効設定を♫
- bashログイン
$ aws ecs execute-command \
–cluster ${CLUSTER_NAME} \
–task ${TASK_NAME} \
–container ${CONNTAINER_NAME} \
–interactive –command “bash”
The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.
Starting session with SessionId: ecs-execute-command-i9n3gcyk4bqgis4y34nsuozgbu
[root@ip-{IPAddress} /]#
ログインできなくなったときの状況
The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.
An error occurred (InvalidParameterException) when calling the ExecuteCommand operation: The execute command failed because execute command was not enabled when the task was run or the execute command agent isn’t running. Wait and try again or run a new task with execute command enabled and try again.
結論と行ったこと
結論
Dockerfile内にProxy記述があったためだった♫
根が深いのが、利用するDockerImageにもProxy設定があるとNGだった♫
#Name:Webシステム
# CentOS 7.8
FROM *.amazonaws.com/baseimg-repository:latest <= この中の「Dockerfile」にProxy記載があってもNG
他に行った事(案内されたこと)
-
別の方法でログインする
## 繋がらないときの対応
====================
###1. ECS マネージメントコンソールのタスク ID のリンク、もしくは AWS CLI (describe-tasks) コマンドにて runtimeId (コンテナランタイム ID) を取得します。
aws ecs describe-tasks –cluster ${CLUSTER_NAME} –tasks ${TASK_NAME} | grep “runtimeId”
###2. ECS Exec の代わりに、SSM セッションマネージャーでセッションを開始します。
aws ssm start-session –target ecs:${CLUSTER_NAME}_${TASK_NAME}_<runtimeId>
====================
-
fargateのCPU、メモリを大きくする。
Bashを有効にする方法
環境設定
事前に、session-manager-plugin をインストールしておく
[Redhut]
$ sudo yum install -y https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm
[Ubuntu]
curl “https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb” -o “session-manager-plugin.deb”
sudo dpkg -i session-manager-plugin.deb
[Windows]
https://s3.amazonaws.com/session-manager-downloads/plugin/latest/windows/SessionManagerPluginSetup.exe
まず稼働中タスクの確認
aws ecs list-tasks \
–cluster ${CLUSTER_NAME} \
–service ${SERVICE_NAME}
※タスクIDを確認する
ECS Execの有効化
task-definition の確認
aws ecs list-task-definitions –family-prefix ${TASK_DEF} –sort desc –max-items 10
設定
aws ecs update-service \
–cluster ${CLUSTER_NAME} –service ${SERVICE_NAME} \
–task-definition ${TASK_DEF} \
–desired-count 1 –enable-execute-command –force-new-deployment
(省略:色々、出力される)
有効になったことを確認
aws ecs describe-services \
–cluster ${CLUSTER_NAME} \
–services ${SERVICE_NAME} \
–query ‘services[0].enableExecuteCommand’
true
ログイン
再度、タスク名を確認し設定する。(変更されている)
aws ecs list-tasks –cluster ${CLUSTER_NAME} –service ${SERVICE_NAME}
TASK_NAME=655125878dd0434cb027971eb9152da0
aws ecs execute-command \
–cluster ${CLUSTER_NAME} \
–task ${TASK_NAME} \
–container ${CONNTAINER_NAME} \
–interactive –command “bash”
無事、rootでログインできているハズ