まず、ALB用のロールを作成(自動的には作成されないので要注意)
こんな感じでAmazonEC2ContainerServiceRole
をアタッチしたecsServiceRole
を作成。
新しいタスク定義は以下の通り。
- hello-hako.yml
scheduler: type: ecs region: ap-northeast-1 cluster: hello-hako desired_count: 2 role: ecsServiceRole elb_v2: vpc_id: vpc-... listeners: - port: 80 protocol: HTTP subnets: - subnet-... - subnet-... security_groups: - sg-... app: image: nginx memory: 300 cpu: 256 essential: true mount_points: - container_path: /usr/share/nginx/html source_volume: vol #port_mappings: # - host_port: 0 # container_port: 80 additional_containers: front: image_tag: nginx memory: 32 cpu: 32 port_mappings: - host_port: 0 container_port: 80 mount_points: - container_path: /var/log/httpd source_volume: log volumes_from: - source_container: app busybox: image_tag: busybox cpu: 64 memory: 256 env: MSG: hello volumes_from: - source_container: app # entry_pointはまだ使えないっぽい command: - /bin/sh - -c - | while true; do date >> /usr/share/nginx/html/index.html echo $MSG >> /usr/share/nginx/html/index.html echo '<br>' >> /usr/share/nginx/html/index.html sleep 3 done volumes: vol: {} log: source_path: /var/log/httpd
今回のappコンテナはnginxだけど、ただのボリューム置き場です。
frontコンテナは必須。
この状態で、hako deploy hello-hako.yml
すると
ELBが作られて
ターゲットグループが作られて
で、サービスができる。
ALBにアクセス。
~$ curl -s hako-hello-hako-910297360.ap-northeast-1.elb.amazonaws.com | head Thu Sep 8 04:16:59 UTC 2016 hello <br> Thu Sep 8 04:17:02 UTC 2016 hello <br> Thu Sep 8 04:17:05 UTC 2016 hello <br> Thu Sep 8 04:17:08 UTC 2016
おけおけ。