ããã«ã¡ã¯ãã¤ã³ãã©ã¨ã³ã¸ãã¢ã®æ°¸äº(shnagai)ã§ãã
re:inventçã£æä¸ã§ãEKS for Fargateãçºè¡¨ããããFargate Spotãçºè¡¨ããããä»å¹´ãæ¿ç±ã§ããï¼ï¼
ä»åã¯ãæ¥ã ã¢ãããã¼ãããã¦ããECSã®æ°æ©è½ã®ä¸ããä»å¹´å°å ¥ãããã®ã¨ä»å¾å°å ¥ãæ¤è¨ãã¦ããããã¨æã£ã¦ãããã®ã«ã¤ãã¦æ¸ããã¨æãã¾ãã
å 容ã¯ãã£ããã¨ä¸è¨3é ç®ã§ãã
- ãã©ã¡ã¼ã¿ã¹ãã¢ã«ä¿ç®¡ããå¤ã®ç°å¢å¤æ°ã¸ã®æ³¨å ¥æ¹æ³å¤æ´
- Container Insightsã使ã£ãã¿ã¹ã¯ã®ç£è¦
- ä»å¾å°å
¥ãã¦ãããããã¨
- Savings Plansã§ã®Fargateã®ã³ã¹ãåæ¸
- FireLensã使ã£ã¦è±CWLã®æè»ãªãã°ã«ã¼ãã£ã³ã°
ãã®è¨äºã¯ã³ããã Advent Calendar 2019 4æ¥ç®ã®è¨äºã§ãã
ãã©ã¡ã¼ã¿ã¹ãã¢ã«ä¿ç®¡ããå¤ã®ç°å¢å¤æ°ã¸ã®æ³¨å ¥æ¹æ³å¤æ´
ã¢ããªã±ã¼ã·ã§ã³ã§å©ç¨ããç§å¿å¤æ°(DBæ¥ç¶æ å ±ç)ã¯ããã©ã¡ã¼ã¿ã¹ãã¢ã«æå·åãã¦ä¿ç®¡ããã³ã³ããèµ·åæã«å¾©å·åã¨ç°å¢å¤æ°ã¸ã®ã»ããããã¦ãã¾ãã
åè: The Twelve Factors
ããã¾ã§ã¯ãå¥ã®ãã¼ã«ã使ã£ã¦ã³ã³ããèµ·åæã«ç°å¢å¤æ°ã®ã»ããã¨å¾©å·åãè¡ã£ã¦ããã®ã§ãããä¸è¨çç±ããä»åæ°è¦ãµã¼ãã¹ã§ã¯ãAmazon ECS ã·ã¼ã¯ã¬ããã®ãµãã¼ãã¨ãã¦å¯¾å¿ãããã¿ã¹ã¯å®ç¾©ã§ã®ãã©ã¡ã¼ã¿ã¹ãã¢å¤ã®ç°å¢å¤æ°ã¸ã®æå ¥ãå°å ¥ãã¾ããã
- ã¡ã³ããã³ã¹ãããã¼ã«ãå°ãã§ãå°ãªãæ¹ãè¯ã(åããã¨ãããç°¡åã«åºæ¥ããªãã°ãã¡ããæ¡ç¨)
- åºæ¥ãã ãã·ã³ãã«ãªæ§æã«ããã
AWSãééãåãã¦ãããã¨ãã話ã¯ã以åã«ã¤ãã¯ã®è¤åããã®ã¹ã©ã¤ããè¦ã¦ãããå ±æããã®ãæãåºãã¾ããã
AWSの「隙間」を埋める隙間家具 OSS 開発 / AWS DevDay Tokyo 2019 - Speaker Deck
æé çã¯ãå ¬å¼ããã¥ã¡ã³ãã«è©³ããæ¸ãã¦ããã®ã§å²æãã¦ãä¸ç¹æ³¨æç¹ã ãæ¸ãã¦ãããã¨æãã¾ãã
ãã¿ã¡ã¼ã¿ã¹ãã¢ã§ã¯ãAWSä¸ã§ç®¡çããç§å¯éµ(KMSãã¼)ã使ã£ãå¤ã®æå·åã«å¯¾å¿ãã¦ãããç§å¿å¤æ°ã¯ãã®æ©è½ã使ããã¨ãå¤ãããªã¨æãã¾ãã æå·åããå¤ã使ãã«ã¯å¾©å·ãå¿ è¦ã§ãã¿ã¹ã¯ã«å¯¾ãã¦ãã®å¤ãç°å¢å¤æ°ã«ã»ããããã«ã¯ã復å·ã«ä½¿ãKMSãã¼ã¸ã®ã¢ã¯ã»ã¹æ¨©ãæã£ãIAMãã¼ã«ã使ã£ã¦ãã©ã¡ã¼ã¿ã¹ãã¢ã«ã¢ã¯ã»ã¹ããå¿ è¦ãããã¾ãã
ã©ã¡ãã®æ¹æ³ã§ããã®æ©è½ã使ããã¨ã¯ãã¡ããåºæ¥ãã®ã§ãããç°å¢å¤æ°ã«å¤ãã»ããããã¿ã¤ãã³ã°ãç°ãªããããã¿ã¹ã¯å®ç¾©ã§KMSã¸ã®ã¢ã¯ã»ã¹æ¨©ãè¨å®ãããã¼ã«ãç°ãªãã¾ãã æåãã®é¨åãç解åºæ¥ãå°ããããã¾ããã
ã¾ã¨ããã¨ã
- ãã¼ã«çã§ãã©ã¡ã¼ã¿ã¹ãã¢ã«ã¢ã¯ã»ã¹ãããã¿ã¼ã³
ã¿ã¹ã¯ãèµ·åããå¾ã®Dockerã®CMDå¥ã®å½ä»¤ã«ã¦ãã©ã¡ã¼ã¿ã¹ãã¢ã«ã¢ã¯ã»ã¹ããã®ã§ãECSã®ã¿ã¹ã¯ãã¼ã«ã«KMSãã¼ã¸ã®ã¢ã¯ã»ã¹æ¨©ãå¿ è¦
- ã¿ã¹ã¯å®ç¾©ã§ã®ãã©ã¡ã¼ã¿ã¹ãã¢å¤ã®ç°å¢å¤æ°æå ¥ã使ããã¿ã¼ã³
ã¿ã¹ã¯èµ·åæã«ãECSã³ã³ããã¨ã¼ã¸ã§ã³ãããã©ã¡ã¼ã¿ã¹ãã¢ã«ã¢ã¯ã»ã¹ããã®ã§ãECSã®ã¿ã¹ã¯å®è¡ãã¼ã«ã«KMSãã¼ã¸ã®ã¢ã¯ã»ã¹æ¨©ãå¿ è¦
ã¾ã ãã©ã¡ã¼ã¿ã¹ãã¢ã®ãã¹ããã©ã¯ãã£ã¹ã¨ããã¦ãããé層åãã©ã¡ã¼ã¿(aws ssm get-parameters-by-pathç¸å½)ã®å¤ã®å±éã«ã¯å¯¾å¿ããã¦ãªãã§ãããã®ãã¡ãµãã¼ããããããªæ°ããã¾ãã
Container Insightsã使ã£ãã¿ã¹ã¯ã®ç£è¦
ããã¾ã§ã³ã³ããã®ç´°ããã¡ããªã¯ã¹ãåå¾ããã«ã¯ãDatadogçã®å¥ã®ã¢ãã¿ãªã³ã°ãã¼ã«ã使ãå¿ è¦ããã£ãã®ã§ãããä»å¹´Container Insightsãçºè¡¨ããã¦ãã詳細ãªã¡ããªã¯ã¹ã®åå¾ãå¯è½ã«ãªãã¾ããã
Amazon ECS Container Insights ã®ã¡ããªã¯ã¹ - Amazon CloudWatch
Container Insightsãã¾ã ãã«æ´»ç¨ã¯åºæ¥ã¦ããªãã®ã§ãããä¸é¨ã®ç£è¦ã追å ããã®ã§ãã¡ããç´¹ä»ãã¾ãã
æ®æ®µã®ã³ã³ããã®ç£è¦ã¨ãã¦ã¯ãECSãµã¼ãã¹ãã¶ãä¸ããALBã® UnHealthyHostCount
ãããããå¤ä»¥ä¸ããå ´åã«ã¢ã©ã¼ããéãå½¢ã§ã¿ã¹ã¯ãèµ·åãã¦ããªãç¶æ
ãç£è¦ãã¦ãã¾ããã â»UnHealthyHostCountãã¦ã¼ã¶ç®ç·ã§ãµã¼ãã¹æä¾åºæ¥ã¦ããªãç¶æ
ãæ¤ç¥åºæ¥ã¦ããã®ã§ããã¯ããã§æå³ãããã¾ãã
æè¿ããèãDesign for Failureã®ç²¾ç¥ã«åããã»ã«ããã¼ãªã³ã°ãåæã¨ãã¦ã¿ã¹ã¯ãè½ã¡ãæ°ã§ã¯ãªãã¿ã¹ã¯å®ç¾©ã§å®£è¨ããç¶æ ãç¶æåºæ¥ã¦ããããç£è¦ããã¹ãã¨ã®ææ³ã®å ãã¿ã¹ã¯ã宣è¨æ°èµ·åãã¦ããããã確èªããç£è¦ã追å ãã¾ããã
ãã£ãã説æããã¨ã
- Container Insightsãã該å½Serviceã®
RunningTaskCount
(ç¾å¨èµ·åãã¦ããã¿ã¹ã¯æ°)ã¨DesiredTaskCount
(Serviceã§å®£è¨ããã¦ããã¿ã¹ã¯æ°)ãåå¾ - ããããã«idãæ¯ãã
RunningTaskCount
/DesiredTaskCount
ã®å¤ãã¡ããªã¯ã¹ã¨ãã - èµ·åãã¦ããã¿ã¹ã¯æ°ã宣è¨ãã¦ããã¿ã¹ã¯æ°ãä¸åã£ã¦ããå ´åã¯ãæå¾ ããç¶æ ã§ã¯ãªãã®ã§ãããç¶ãããã§ããã°ç°å¸¸ãçºçãã¦ããã¨è¨ãã
以ä¸ãContainer Insightsã®è¨å®æé ãæ¸ãã¦ããã¾ãã
Container Insightsã®æå¹å
ã¾ãã¯ãæ¢åã®ã¯ã©ã¹ã¿ã«å¯¾ãã¦Container Insightsãæå¹åãã¾ãã æ¢åã¯ã©ã¹ã¿ã«å¯¾ãã¦ã¯ãAWSã³ã³ã½ã¼ã«ããã®å¤æ´ã¯ã¾ã ãµãã¼ãããã¦ããªãã®ã§ä¸è¨ã®ããã«aws cliçµç±ã§å®è¡ãã¾ãã
$ aws ecs update-cluster-settings --cluster ã¯ã©ã¹ã¿å --settings name=containerInsights,value=enabled { "cluster": { "clusterArn": "arn:aws:ecs:ap-northeast-1:xxx:cluster/ã¯ã©ã¹ã¿å", "clusterName": "ã¯ã©ã¹ã¿å", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ] } }
CloudWatchã§ã®å®ç¾©ã¨ã¡ããªã¯ã¹ã®ãµã³ãã«
CloudWatchã®ã¡ããªã¯ã¹ã§ä¸è¨ã®ãããªJSONããçºä¿¡å ãã«è¿½å ãã¾ãã
{ "metrics": [ [ { "expression": "m0r1 / m0r0", "label": "hoge-task-count-health", "id": "e0", "region": "ap-northeast-1", "color": "#1f77b4" } ], [ "ECS/ContainerInsights", "RunningTaskCount", "ServiceName", "ãµã¼ãã¹å", "ClusterName", "ã¯ã©ã¹ã¿å", { "id": "m0r1", "label": "RTC", "visible": false, "color": "#ff7f0e" } ], [ ".", "DesiredTaskCount", ".", ".", ".", ".", { "id": "m0r0", "label": "DTC", "visible": false } ], [ { "expression": "m1r1 / m1r0", "label": "hoge1-task-count-health", "id": "e1", "region": "ap-northeast-1", "color": "#e377c2" } ], [ "ECS/ContainerInsights", "RunningTaskCount", "ServiceName", "ãµã¼ãã¹å", "ClusterName", "ã¯ã©ã¹ã¿å", { "id": "m1r1", "label": "RTC", "visible": false, "color": "#ff7f0e" } ], [ ".", "DesiredTaskCount", ".", ".", ".", ".", { "id": "m1r0", "label": "DTC", "visible": false } ] ], "id": "DesiredTaskCount", "legend": { "position": "right" }, "region": "ap-northeast-1", "stat": "Minimum", "title": "ECS-Check-Task-Status", "view": "timeSeries", "period": 60, "yAxis": { "left": { "min": 0 } } }
ããã¨ä¸è¨ã®ãããªå½¢ã§ãã¡ããªã¯ã¹ã追å ããã¾ãã
éç¥
å¾ã¯ãã¡ããªã¯ã¹ã§ä½ã£ãe0
,e1
ãCLoudWatchã¢ã©ã¼ã ã§ããããç£è¦ãã¾ãã
- 1ååä½ã§ç£è¦ãã¦ã3åä¸2å以ä¸1ãä¸åã£ããéç¥(ã»ã«ããã¼ãªã³ã°ãèæ ®ãé£ç¶çã«ä¸åã£ã¦ãªããã°OK)
- éç¥ã¯ãAWS Chatbotãå©ç¨(ããã¾ã§Lambdaã§ãã£ã¦ãããããªã³ã¼ãã£ã³ã°ä¸è¦ã«)
éç¥ãµã³ãã«
Container Insightsããã¾ã使ããã¨ã§ããä¸è¨ã®ããã°ã«ãããããã«ãECSéç¨ã«ããããµã¤ã¸ã³ã°ãæè»ãªã¹ã±ã¼ãªã³ã°ãè¡ããã¨æãã®ã§ãã¾ã使ã£ã¦ãªã½ã¼ã¹ã®æé©åã«ãåãçµãã§ããããã¨èãã¦ãã¾ãã
Amazon ECS向けAmazon CloudWatch Container Insightsについて | Amazon Web Services ブログ
ä»å¾å°å ¥ãã¦ãããããã¨
æå¾ã«ä»å¾åãå ¥ãã¦ããããã¨æã£ã¦ããECSé¢é£ã®ã¢ãããã¼ãã«ã¤ãã¦å°ã触ãããã¨æãã¾ãã
Savings Plansã§ã®Fargateã®ã³ã¹ãåæ¸
â»Fargate Spotãçºè¡¨ãããã®ã§ããã¡ããå å³ããªããããããæé©ãªãã©ã³ãæ¢ããã¨æãã¾ã
Fargateå©ç¨è ãããã¯æ¤è¨ãã¦ããæ¹ã«ã¯å¾ æã®Savings Plansã¨ããå²å¼ãã©ã³ãçºè¡¨ããã¾ããã ã³ãããã§ã¯ãEC2ããã¯ã¨ã³ãã§åããã¦ããECSã«é¢ãã¦RIã使ããã¨ã§ã³ã¹ãåæ¸ãå®ç¾ãã¦ããã®ã§ãããFargateã¯RIã«å¯¾å¿ãã¦ãããéç¨ã³ã¹ãé¢ãèããã¨Fargateã¯ã¨ã¦ãé åçãªã®ã§ããå¿ è¦ãªãªã½ã¼ã¹ã大ãããµã¼ãã¹ã§ã¯è²»ç¨é¢ããFargateå°å ¥ã«è¸ã¿åãã¦ãã¾ããã§ããã Savings Plansã¯ãRIã¨ã¯æ¦å¿µãç°ãªããã³ã³ãã¥ã¼ãã£ã³ã°ãªã½ã¼ã¹ã®ä½¿ç¨éãã³ãããããã¨ããèãæ¹ã§æ¨ªã¸ã®èªåé©ç¨ãå¹ããããªã®ã§EC2/Fargateãæèããã«å²å¼ã®æ©æµãåãããã¨ãåºæ¥ã¾ãã
å æ¥ãAWSã«Savings Plansã®è©±ãèãã«è¡ã£ãã¨ããã3å¹´ãã©ã³ã¯å²å¼çãé«ãã®ã§3å¹´éãæ³å®ããæä½å©ç¨éé¡ãã³ãããããã®ãããããã¨ãã話ãèããã®ã§ã試ç®ãã¦RIåããã¿ã¤ãã³ã°ã§Savings Plansãè³¼å ¥ãããã¨è¨ç»ãã¦ãã¾ãã
FireLensã使ã£ã¦è±CWLã®æè»ãªãã°ã«ã¼ãã£ã³ã°
ã³ã³ãããæ¨æºåºåãããã°ãCloudWatchLogsã«åºåãã¦ããã®ã§ãããåããã°ã°ã«ã¼ãã«æ°ç¨®é¡ã®ãã°ãããæã«Lambdaã§å å·¥ããããCWLã§ãã£ã«ã¿ããã®ãé¢åã¨ãã課é¡ãããã¾ãã FireLensã使ãã¨ããã°ã®ã«ã¼ãã£ã³ã°ã«Fluentdã使ã£ãæè»ãªãã°ã«ã¼ãã£ã³ã°ãåºæ¥ãã¨æãã®ã§ãã¡ããä»å¾è©¦ãã¦å°å ¥ãã¦ããããã¨æ¤è¨ä¸ã§ãã å¥ã³ã³ããã§éç¨ãã¦ãããã¢ã°ãªã²ã¼ã¿çã«Fluentdã«éç´ãã¦ããå¦çãFireLensã«ç½®ãæãã¦éç¨ã³ã¹ããä¸ããããªãããåæã«æ¤è¨ãããã¨æã£ã¦ãã¾ãã
ã«ã¹ã¿ã ãã°ã«ã¼ãã£ã³ã° - Amazon ECS
ã³ãããã§ã¯ã³ã³ããå¨ãã®åºç¤ãæ´åããããµã¼ãã¹æ¹åãè¡ãã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãã å°ãã§ãèå³ããããæ¹ã¯ãæ¯éæ°è»½ã«ãªãã£ã¹ã«éã³ã«ãã¦ããã ããã¨ããããã§ãã
AWSやDockerを駆使してサービスの信頼性を向上させるエンジニア募集 - コネヒト株式会社のインフラエンジニアの求人 - Wantedly