血と汗となみだを流す

個人の思ったこと、やったことの吐き出し口です。

Developers.ioの記事を読んでやってみる「RancherOS で ECS Cluster を構築してみた」(2018/02/28)

対象

やってみる

ECS CLI

  • ecs-cliインストール
    • インストール済みなので割愛

RancherosのAMI確認

ECSクラスターを作成する

  • ecs-cli configure
    • コマンドではやらずにdirenvで環境変数にセット
      • region: AWS_DEFAULT_REGION
      • cluster: ECS_CLUSTER
  • ECSクラスター作成(1台のみ)
$ ecs-cli up --keypair [キーペア名] --capability-iam --size 1 --instance-type t2.micro --image-id ami-01881e67
INFO[0000] Created cluster                               cluster=test-cluster region=ap-northeast-1
INFO[0001] Waiting for your cluster resources to be created...
INFO[0001] Cloudformation stack status                   stackStatus="CREATE_IN_PROGRESS"
INFO[0062] Cloudformation stack status                   stackStatus="CREATE_IN_PROGRESS"
INFO[0122] Cloudformation stack status                   stackStatus="CREATE_IN_PROGRESS"
VPC created: vpc-xxxxxxxx
Security Group created: sg-xxxxxxxx
Subnet created: subnet-xxxxxxx1
Subnet created: subnet-xxxxxxx2
Cluster creation succeeded.
  • AWSコンソールからECSインスタンス確認 f:id:Anorlondo448:20180227065334p:plain
  • defaultって名前のクラスターが起動している
    • RancherOS の AMI に、/etc/ecs ディレクトリが無いため ecs.config ファイルが作成されなかったことが原因の模様。

RancherOSにSSH接続

  • AWSコンソールから、作成されたセキュリティグループのssh:22を開放
  • ssh
$ ssh -i key rancher@<ip-of-ec2-instance>
rancher@<ip-of-ec2-instance>'s password:

パスワード聞かれる・・・なぜ?! SSHでコンテナインスタンスに入るなってこと・・・? いったんpendingにして先に進む

コンテナをデプロイ

  • docker-compose.ymlを作る
version: '2'

services:
  nginx:
    image: nginx
    expose:
      - 80
    ports:
      - "80:80"
  • タスク起動
$ ecs-cli compose up
WARN[0000] Skipping unsupported YAML option...           option name=networks
WARN[0000] Skipping unsupported YAML option for service...  option name=expose service name=nginx
WARN[0000] Skipping unsupported YAML option for service...  option name=networks service name=nginx
INFO[0000] Using ECS task definition                     TaskDefinition="ecs:4"
INFO[0000] Starting container...                         container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx"
INFO[0000] Describe ECS container status                 container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecs:4"
INFO[0012] Started container...                          container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx" desiredStatus=RUNNING lastStatus=RUNNING taskDefinition="ecs:4"
  • docker-compose.ymlを別名(nginx.yml)とかにしている場合は
$ ecs-cli compose --file nginx.yml up

確認

  • コンテナ確認
$ ecs-cli ps
Name                                        State    Ports                      TaskDefinition
28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx  RUNNING  [<ip-of-ec2-instance>]:80->80/tcp  ecs:4
  • ブラウザからECSインスタンスの<ip-of-ec2-instance>でアクセスしてみる f:id:Anorlondo448:20180228070948p:plain

後始末

  • タスク停止
$ ecs-cli compose  --file nginx.yml down
WARN[0000] Skipping unsupported YAML option...           option name=networks
WARN[0000] Skipping unsupported YAML option for service...  option name=expose service name=nginx
WARN[0000] Skipping unsupported YAML option for service...  option name=networks service name=nginx
INFO[0000] Stopping container...                         container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx"
INFO[0000] Describe ECS container status                 container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx" desiredStatus=STOPPED lastStatus=RUNNING taskDefinition="ecs:4"
INFO[0006] Stopped container...                          container="28d5d0d7-67fa-47a7-ae2a-7702fb3215c4/nginx" desiredStatus=STOPPED lastStatus=STOPPED taskDefinition="ecs:4"
$ ecs-cli down --force
INFO[0000] Waiting for your cluster resources to be deleted...
INFO[0000] Cloudformation stack status                   stackStatus="DELETE_IN_PROGRESS"
INFO[0066] Cloudformation stack status                   stackStatus="DELETE_IN_PROGRESS"
INFO[0126] Cloudformation stack status                   stackStatus="DELETE_IN_PROGRESS"
INFO[0187] Deleted cluster 

できなかったこと

プライバシーポリシー