用語集

ECS独自

FargateEC2の管理不要
タスクコンテナ1つに対応する。タスク定義とタスクはクラスとインスタンスの関係。タスク定義はVersion管理されており、更新すると別のタスクが立ち上がり入れ替わる
サービスタスクが幾つ必要かとかALBと紐づけるとか。
クラスタEC2の塊、Fargateだと意識することはない。

Docker

CMDDocker起動時に実施するCMD。起動時に指定するものと同じものが定義できると考えるべし。docker exec -it xxx /bin/bashの/bin/bashの部分だ
ENTRYPOINTDocker起動時に実施するコマンドではCMDと一緒だが、上書き不可能だったりもできる。ENTRYPOINTを指定したときは、runの後の記述は起動するプロセスを特定する指示としては機能しない

Task role/ Task Execution Role

aws-cli ecs編

aws ecs list-task-definitionsタスク定義の一覧
aws ecs describe-task-definition --task-definition test-mysql:2タスク定義の詳細。このままではRegisterできない。

Blue/Greenの時のために整形

aws ecs describe-task-definition --task-definition test-mysql:2 |  jq '.taskDefinition | del(.status, .compatibilities, .taskDefinitionArn, .requiresAttributes, .revision) '

https://dev.classmethod.jp/articles/describe-task-definition-to-register-task-definition/

firelens

ポイント

https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/using_firelens.html

https://qiita.com/neruneruo/items/b3fb35ad5064c045a15b

Fluentdへ

       "options": {
         "exclude-pattern": "^.*(hoge|open).*$",
         "Port": "24224",
         "Host": "HOST",
         "Name": "forward"
       }

直接Cloudwatchlogsへ

https://github.com/aws-samples/amazon-ecs-firelens-examples/tree/mainline/examples/fluent-bit/cloudwatchlogs

https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/using_firelens.html#firelens-filtering-logs

  1. 試しに最小構成のnginx/firelensで実施。
  2. CloudWatchLogsにロググループ作成権限が必要で、初回は起動失敗。
  3. 起動失敗しても繰り返し上がってくるのでポリシー更新後成功
   "options": {
         "awslogs-group": "firelens-container",
         "awslogs-region": "ap-northeast-1",
         "awslogs-create-group": "true",
         "awslogs-stream-prefix": "firelens"
       }

以下のロググループとストリーム名で出力される。これはFluentBitの起動ログである。ngixのログは出ないので注意

log-group/firelens-container/log-events/firelensXXXXX

     "options": {
         "log_group_name": "firelens-testing-fluent-bit",
         "auto_create_group": "true",
         "log_stream_prefix": "from-fluent-bit",
         "region": "ap-northeast-1",
         "exclude-pattern": "^.*(hoge|open).*$",
         "Name": "cloudwatch"
       }

log-group/firelens-testing-fluent-bit/log-events/from-fluent-bitapp-firelens-XXXXX

参考 Docker標準のログドライバ

json-file標準 Docker logsで見れる
syslogSyslogに転送
journald
fluentd

CMDとENTRYPOINT

ENTRYPOINT

固定で与えるものなので、docker run -it xxx 'コマンド'が実行時にentrypointに加わる

/bin/bash -cdocker run it xxx 'ls'ls
/usr/bin/gitdocker run it xxx 'log'git log

CMD

Docker runで何も指定しなかったときの実行コマンド。またはentrypointでのデフォルト引数。

EntryPoint設定値CMD設定値docker runコマンド実際のコマンド
なしlsdocker run -it xxxls
/bin/bash -clsdocker run -it xxxls

Sidecar

https://y-ohgi.com/2019-aws-handson/datadog/ecs/ https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition

Tips

起動したPublic IPの確認。タスクから詳細(タスク定義ではない!)

ローカルでECSタスク定義実行

https://dev.classmethod.jp/articles/ecs-local/

https://dev.classmethod.jp/articles/aws-devday-2019-fargate-deploy/

Secret Managerとの連携

https://dev.classmethod.jp/articles/try-to-protect-aws-fargate-container-environment-variable-with-aws-secrets-manager/


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-08-09 (水) 21:28:01