ã©ããECS ã¯æè¿å ¨ç¶è§¦ãã¦ããªããã£ã±ã§ãã
追è¨
AWS CLI ã®ã§ãæä½ãã¦ã¿ãã
tl;dr
å æ¥ãAWS Application Load Balancer ããªãªã¼ã¹ããã¦ãAmazon ECS ã® Dynamic Port Mapping ã«ã対å¿ãããã¨ã®ãã¨ã§ãECS 㨠Application Load Balancer ã®çµã¿åããã試è¡é¯èª¤ãã¦ãããå 容ãªèªèçã«èª¤ãããããããããªãã®ã§ã容赦ä¸ããã
- https://aws.amazon.com/jp/blogs/aws/powerful-aws-platform-features-now-for-containers/
- https://aws.amazon.com/jp/blogs/aws/new-aws-application-load-balancer/
試ããç°å¢
æå ã®ç°å¢
% sw_vers ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G24b % ecs-cli --version ecs-cli version 0.4.2 (9159726)
ECS
- amzn-ami-2016.03.f-amazon-ecs-optimized (ami-ed26e78c)
- ECS ã®ã¯ã©ã¹ã¿ã¯ ecs-cli ã§ä½ææ¸ã¿
- ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ãã ECS ã® Service ãä½æãã¦ãã
- Service å ã§èµ·åãã Task ã¯ã³ã³ããèªèº«ã®ãã¹ãåãè¿ã Sinatra ã¢ããªã±ã¼ã·ã§ã³ï¼ã³ã³ããå 㧠4567 ãã¼ã㧠Listen ããï¼
memo
以ä¸ãæ®´ãæ¸ããï¼å¾ã§æ´çããããï¼
- äºåã« Application Load Balancer ãä½ã£ã¦ããï¼ä»¥å¾ãApplication Load Balancer ã ALB ã¨è¨ãï¼
- ALB ä½æã®éã«ã¯ã¿ã¼ã²ããã°ã«ã¼ããä¸ã¤ä½ãå¿ è¦ãããï¼ã¿ã¼ã²ããã«ã¤ã³ã¹ã¿ã³ã¹ãç»é²ããå¿ è¦ã¯ç¡ãï¼
ã¿ã¼ã²ããã°ã«ã¼ããæ¶ãæã«ã¯ALB ãæ¶ãã¦ããã¿ã¼ã²ããã°ã«ã¼ããåé¤ããæ¹ãè¯ãããï¼ãªã¹ãã¼ã®å®ç¾©ãå ã«æ¶ãã°è¯ãï¼- ä¸å³ã®ããã« ECS ã® Service ä½ææã« ALB ãæå®ãããã¨ãåºæ¥ãï¼ã¿ã¼ã²ããã°ã«ã¼ããçæãããï¼
ecsServiceRole ã¨ãã IAM Role ãä»ä¸ãããããã® Role ã«ã¯ AmazonEC2ContainerServiceRole ã¨ããããã¸ã¡ã³ãããªã·ã¼ãé©ç¨ããã¦ããã
- æ¢åã® ECS Service ã«ã¯è¿½å åºæ¥ãªãï¼ï¼Service ä½ææã®ã¿ ELB å®ç¾©ãåºæ¥ãããã ï¼
- Container Instance ã«ä»ãã Security Group 㯠ALB ã«ä»ä¸ãã Security Group ãã Container ã® Dynamic Port ã«ã¢ã¯ã»ã¹åºæ¥ããããªã«ã¼ã«ãå®ç¾©ãã¦ãã
source: public-access protocol: TCP port range: 0-65535
- ALB ããã¯ã³ã³ããã¯ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦è¦ãã¦ãã
- ã«ã¼ãã£ã³ã°ã®ã«ã¼ã«ã¯ãã¼ããã©ã³ãµã¼ã®ä¸è¦§ã«ã¦è©²å½ã® ALB ãæå®ãã¦ãªã¹ãã¼ã§ä¿®æ£ãã
/*
ã¨ãã¦ããã¨ã¯ã©ã¤ã¢ã³ãã®ãªã¯ã¨ã¹ãããã®ã¾ã¾ããã¯ã¨ã³ãã«æµããããªæåã«ãªã£ãã
- ALB ã«ç»é²ãããã³ã³ããã«ã¢ã¯ã»ã¹ãã¦ã¿ã
% curl -v alb-ecs-demo-xxxxxxxxxxxxxx.ap-northeast-1.elb.amazonaws.com/hostname * Trying 54.xx.xxx.xxx... * Connected to alb-ecs-demo-xxxxxxxxxxxxxx.ap-northeast-1.elb.amazonaws.com (54.xx.xxx.xxx) port 80 (#0) > GET /hostname HTTP/1.1 > Host: alb-ecs-demo-xxxxxxxxxxxxxx.ap-northeast-1.elb.amazonaws.com > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 200 OK < Date: Sat, 13 Aug 2016 01:39:01 GMT < Content-Type: text/html;charset=utf-8 < Content-Length: 12 < Connection: keep-alive < X-XSS-Protection: 1; mode=block < X-Content-Type-Options: nosniff < X-Frame-Options: SAMEORIGIN < * Connection #0 to host alb-ecs-demo-xxxxxxxxxxxxxx.ap-northeast-1.elb.amazonaws.com left intact 59294f32f412
- å½ããåã ã®ã¯ã©ãã«ã¼ã ãã© Task ã®ã¹ã±ã¼ã«ã¢ã¦ãã«ã追éãã¦ããã
# # Task ã 3 ã¤ã«å¢ãããå¾ã«ã¢ã¯ã»ã¹ # % curl alb-ecs-demo-1930795025.ap-northeast-1.elb.amazonaws.com/hostname 79a796b62150% % curl alb-ecs-demo-1930795025.ap-northeast-1.elb.amazonaws.com/hostname 68cb8177a441% % curl alb-ecs-demo-1930795025.ap-northeast-1.elb.amazonaws.com/hostname 59294f32f412%
ã¾ã¨ã¾ã£ã¦ãªããã©ã¾ã¨ã
- ã¾ãã«ç£æ¥é©å½
- Dynamic Port Mapping ããããããçºã« HAProxy ã¨ãå ¥ããªãã¦ãè¯ããªã£ãã®ã¯å¬ãã
- å¾ã§ CLI ã§ããã£ã¦ã¿ã