{"componentChunkName":"component---src-templates-post-template-js","path":"/posts/2019-08-09-ECS_LB/","webpackCompilationHash":"f084a54ccd61922cab08","result":{"data":{"markdownRemark":{"id":"c6607578-d67b-54c7-9b1c-266eaa0cff0c","html":"<h2 id=\"ecs---alb\"><a href=\"#ecs---alb\" aria-label=\"ecs   alb permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ECS -> ALB</h2>\n<h2 id=\"목적--ecs를-이용하여-docker-container의-이미지를-가져와-instance를-구성하고-application-load-balancer로-트래픽을-분산한다\"><a href=\"#%EB%AA%A9%EC%A0%81--ecs%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%98%EC%97%AC-docker-container%EC%9D%98-%EC%9D%B4%EB%AF%B8%EC%A7%80%EB%A5%BC-%EA%B0%80%EC%A0%B8%EC%99%80-instance%EB%A5%BC-%EA%B5%AC%EC%84%B1%ED%95%98%EA%B3%A0-application-load-balancer%EB%A1%9C-%ED%8A%B8%EB%9E%98%ED%94%BD%EC%9D%84-%EB%B6%84%EC%82%B0%ED%95%9C%EB%8B%A4\" aria-label=\"목적  ecs를 이용하여 docker container의 이미지를 가져와 instance를 구성하고 application load balancer로 트래픽을 분산한다 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>목적 : ECS를 이용하여 docker container의 이미지를 가져와 instance를 구성하고 Application Load Balancer로 트래픽을 분산한다</h2>\n<p><img src=\"/aed86a0faae671a6e968f9acf0491dc5/ecs_diagram.svg\" alt=\"ECS diagram!\" title=\"ECS diagram\"></p>\n<h3 id=\"1--vpc-구성---regionap-northeast-2-에-한개의-vpc를-구성\"><a href=\"#1--vpc-%EA%B5%AC%EC%84%B1---regionap-northeast-2-%EC%97%90-%ED%95%9C%EA%B0%9C%EC%9D%98-vpc%EB%A5%BC-%EA%B5%AC%EC%84%B1\" aria-label=\"1  vpc 구성   regionap northeast 2 에 한개의 vpc를 구성 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1.  VPC 구성 - Region(ap-northeast-2) 에 한개의 VPC를 구성</h3>\n<ul>\n<li>Create VPC</li>\n<li>IPv4 CIDR block -> 10.0.0.0/16 으로 설정함</li>\n<li>name : myVPC</li>\n</ul>\n<h3 id=\"2--internet-gateway-작성vpc-internet-gateways\"><a href=\"#2--internet-gateway-%EC%9E%91%EC%84%B1vpc-internet-gateways\" aria-label=\"2  internet gateway 작성vpc internet gateways permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2.  Internet gateway 작성(VPC->Internet Gateways)</h3>\n<ul>\n<li>Create internet gateway</li>\n<li>Attach to VPC (작성된 internet gateway -> actions -> attach to vpc)</li>\n<li>myVPC에 연결</li>\n</ul>\n<h3 id=\"3--route-table-작성\"><a href=\"#3--route-table-%EC%9E%91%EC%84%B1\" aria-label=\"3  route table 작성 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3.  Route Table 작성</h3>\n<ul>\n<li>\n<p>Create public route</p>\n<ol>\n<li>Create route table</li>\n<li>Name tag : public</li>\n<li>VPC : myVPC</li>\n<li>Routes (작성된 route table을 누르고 Routes 탭)</li>\n<li>Edit routes -> Add route\ndestination (0.0.0.0/0) Target  internet Gateway 선택 후 위의 igw 선택</li>\n<li>Save routes</li>\n</ol>\n</li>\n<li>\n<p>Create private route</p>\n<ol>\n<li>Create route table</li>\n<li>Name tag : public</li>\n<li>VPC : myVPC</li>\n<li>Routes (작성된 route table을 누르고 Routes 탭)</li>\n<li>Save routes</li>\n</ol>\n</li>\n</ul>\n<h3 id=\"4-subnet-구성---각각-az에-public-subnet과-private-subnet을-작성vpc-subnets\"><a href=\"#4-subnet-%EA%B5%AC%EC%84%B1---%EA%B0%81%EA%B0%81-az%EC%97%90-public-subnet%EA%B3%BC-private-subnet%EC%9D%84-%EC%9E%91%EC%84%B1vpc-subnets\" aria-label=\"4 subnet 구성   각각 az에 public subnet과 private subnet을 작성vpc subnets permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>4. subnet 구성 - 각각 AZ에 public subnet과 private subnet을 작성(VPC->Subnets)</h3>\n<ul>\n<li>Create subnet AZ별 public private 총 6개</li>\n<li>VPC - myVPC 선택</li>\n<li>Name Tag -> [AZ1<em>pb, AZ2</em>pb, AZ3<em>pb, AZ1</em>pr, AZ2<em>pr, AZ3</em>pr]</li>\n<li>Available Zone -> ap-northeast-2a 선택</li>\n<li>IPv4 CIDR block : [10.0.1.0/24, 10.0.2.0/24, 10.0.3.0/24, 10.0.4.0/24, 10.0.5.0/24, 10.0.6.0/24]\n10.0.1.0/24 는 ( 10.0.1.0~10.0.1.255 )앞의 24bit 고정된 ip address할당</li>\n</ul>\n<h3 id=\"5--nat-gateway-작성\"><a href=\"#5--nat-gateway-%EC%9E%91%EC%84%B1\" aria-label=\"5  nat gateway 작성 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>5.  NAT Gateway 작성</h3>\n<ul>\n<li>Create NAT Gateway( VPC Dashboard -> NAT Gateways)</li>\n<li>Subnet : AZ1_pb</li>\n<li>Elastic IP Allocation ID : Create New EIP</li>\n</ul>\n<h3 id=\"6--private-route-table에-nat-gateway-routing-추가\"><a href=\"#6--private-route-table%EC%97%90-nat-gateway-routing-%EC%B6%94%EA%B0%80\" aria-label=\"6  private route table에 nat gateway routing 추가 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>6.  Private Route table에 NAT Gateway routing 추가</h3>\n<h3 id=\"7--elastic-container-service-구성\"><a href=\"#7--elastic-container-service-%EA%B5%AC%EC%84%B1\" aria-label=\"7  elastic container service 구성 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>7.  Elastic Container Service 구성</h3>\n<ul>\n<li>\n<p>Create new Task Definition(Amazon ECS-> Task Definitions)</p>\n<ol>\n<li>EC2 선택</li>\n<li>\n<p>Configure task and container definitions</p>\n<ul>\n<li>Task Definition Name : example</li>\n<li>Task Role : ecsTaskExecutionRole</li>\n<li>Network Mode : default\ndefault로 안하면 cluster에서 instance 선택이 안됨</li>\n<li>Task execution role : ecsTaskExecutionRole</li>\n<li>Task memory : 4 gb</li>\n<li>Task CPU(unit) : 1024</li>\n<li>Add container : ecr에 등록된 container id 작성</li>\n<li>container에서 사용할 port와 host에서 사용할 port를 작성</li>\n</ul>\n</li>\n</ol>\n</li>\n</ul>","fields":{"slug":"/posts/2019-08-09-ECS_LB/","tagSlugs":["/tag/aws/","/tag/terraform/"]},"frontmatter":{"date":"2019-08-09","description":"AWS에서 ECS와 ALB를 구성하고 terraform으로 재구성하기","tags":["aws","terraform"],"title":"AWS에서 ECS와 ALB를 구성하고 terraform으로 재구성하기","socialImage":null}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/posts/2019-08-09-ECS_LB/"}}}