AWSåå¿è ãElastic Beanstalkç°å¢ãFargateåããã¡ã¢
åªå 度ãé«ãä»äºãè½ã¡çãã¦ããããããã£ã¨ããããã£ãæ¬çªç°å¢ã³ã³ããåã«çæãã¾ããã
ãã¶ããä¼ã¿ã§å ¨é¨å¿ããã®ã§ç¤¾å ã«èª¬æç¨ãå ¼ãã¦ã¡ã¢ã
ä¸è¨ã®è¨äºã®ããã«ç¾å¨ã®ã·ãã¢ã¸ã§ãã«å ¥ç¤¾ãã¦ãããéçºç°å¢ã¯Dockeråãã¦ãã¾ããã
シニアジョブに入社して1ヶ月でやったこととこれから - GAミント至上主義
ç¾å¨ãæ¬çªç°å¢ã¯Elastic Beanstalkã§åãã¦ãã¾ãããDockerfileã§ç®¡çã§ããããããã¤ãã¯æãã¦ã³ã³ããåããããªãã¨æã£ã¦ãã¾ããã
AWS Fargateã¨ã¯
AWS ECSããEC2ã®ç®¡çãï¼ã§ãï¼ãªããããµã¼ãã¼ã¬ã¹çãªãã®ã»ã»ã»ã¨ããéãªèªèã詳細ã¯å
¬å¼ã
AWS Fargate(サーバーやクラスターの管理が不要なコンテナの使用)| AWS
å°ç¨ãã¼ã¸ã¯ãããã®ã®ãã³ã³ã½ã¼ã«ã®ä¸ã ã¨ãECSãEKSã®èµ·åã¿ã¤ãã¨ãã¦åå¨ãã¦ãã ãã§æå¤ã¨å°å³ãªåå¨ã§ããã
ãªãFargateã使ãã
ã³ã³ããåã«éãã¦ã¯ãã¿ã¤ãã«ã®Fargateã®ä»ãä¸è¨ã®é¸æè¢ãããã¾ããã
- AWS ECS (Elastic Container Service) ã®èµ·åã¿ã¤ãã«EC2
- AWS EKS (Elastic Kubernetes Service)
- GCP GKE (Google Kubernetes Engine)
ä¸è¨ãFargateã«ããçç±ã§ãã
AWSã®ãããããªãµã¼ãã¹ã使ã£ã¦ããããï¼GCPã使ããªãçç±ï¼
ã·ãã¢ã¸ã§ãã§ã¯ãç¾å¨ã®ã·ã¹ãã ãåããå½åï¼2016å¹´ããï¼ï¼ããAWSä¸ã§æ±äººãµã¤ãã管çã·ã¹ãã ãåããã¦ãã¾ããã
ãã®ããRDSï¼MySQLï¼ãã¯ãããElasticsearchãDynamoDBãSQSãªã©ã使ç¨ãã¦ãã¾ãã
ãã®ãããå人çã«ã¯GCPã®GKEã¯ä½¿ãæ
£ãã¦ããã®ã§ä½¿ãããæ°æã¡ã¯ãããã®ã®ãããããGCPã«ç§»ãã¨ããé¸æè¢ã¯ããã¾ããã§ããã
ãããªã«å¿ è¦ãªã³ã³ããæ°ãå¤ããªãï¼Kubernetesã使ããªãçç±ï¼
ããã¾ã§è§¦ã£ããã¨ã¯ãªããã®ã®ããããä¸ã®è¨äºã¨ãã®å°è±¡ã ã¨ãAWSã§ããã¾ã§å¤§è¦æ¨¡ãããªãã·ã¹ãã ã ã£ããFargateããªãã¨ããã¤ã¡ã¼ã¸ã§ããã
ã·ãã¢ã¸ã§ãã®ã·ã¹ãã ã§å¿
è¦ã«ãªããããªã³ã³ããã¯ä¸è¨3ã¤ã ãã§ãã»ãã¯RDS, Redisãªã©ã¯AWSã®ããã¼ã¸ãã§æ¸ã¿ã¾ãã
- ã¢ããªã±ã¼ã·ã§ã³ (Laravel)
- ã¯ã¼ã«ã¼ (php artisan queue:workerãããã¤) (Laravel)
- WEBãµã¼ãã¼ï¼Nginxï¼
ããã ãã ã¨Kubernetesã®æ©è½ã¯ã¡ãã£ã¨ãªã¼ãã¼ããªãã¨ããå°è±¡ããã¨AWSã§Kubernetesã¯GKEã¨æ¯è¼ããã¨é«ãã¤ãã¨ããã®ãããã¾ãã
å®éæ§ç¯ãã¦ã¿ãæãããã¼ãã¦ã§ã¢ãªã½ã¼ã¹ãæè»ã§ãFargateã§ååã§ããã
管çã楽ããã ããï¼EC2ã¿ã¤ãã使ããªãçç±ï¼
EC2ã¿ã¤ãã使ã£ããã¨ã¯ãªãã®ã§æ¯è¼ã¯ã§ããªãã®ã§ãããEC2ãæèããã«ä½¿ããã¨ããã®ã¯ãã¨ã³ã¸ãã¢3人ã§ä½ã¨ããã¦ããç¾ç¶ã§ã¯ãã¡ã³ããã³ã¹ã³ã¹ããåæ¸ã§ããããªã®ã§ã大ããªä¾¡å¤ãããã¾ããã
ãµã¼ãã¼ã¬ã¹ã¨ããã®ã§ãGCPã§ããCloud Runã¿ãããªæãããªãã¨æã£ã¦ãããã©ã¡ããã¨ããã¨Kubernetesで最近出たAutopilot的ãªãã®ã§ããã
Fargateåããããã«å¿ è¦ãªç»å ´äººç©
GCPã§ã¯ããããæ§ç¯ãããã¨ããããã®ã®AWSã§è¤æ°ãµã¼ãã¼ã®ã·ã¹ãã æ§ç¯ã¯åãã¦ã§ããã
ãã®ããFargateã使ç¨ããã«ããããAWSã®ä»ã®ãµã¼ãã¹ãæ©è½ãç¥ãå¿
è¦ãããã¾ããã
ECR (Elastic Container Registry)
ã¾ãã¯Dockerã§ä½ã£ãã³ã³ãããAWSã«ç½®ãã¦ããå¿
è¦ãããã¾ãããã®ç½®ãå ´æãECRã
Amazon ECR(Docker イメージの保存と取得)| AWS
æå1åã ãæä½æ¥ã§ãã¼ã«ã«ãããã«ãï¼ããã·ã¥ãã¾ããããé¢åãªã®ã§Circle CIã§èªååãã¾ããï¼å¾è¿°ï¼
ECS (Elastic Container Service)
ãããä»å使ãã¡ã¤ã³ã®ãµã¼ãã¹ã«ãªãã¾ãã
Amazon ECS(Docker コンテナを実行および管理)| AWS
ECSã®ä¸ã«ä¸è¨ãããã¾ã
ECS ã¯ã©ã¹ã¿ã¼
ECSã®ä¸çªå¤å´ãEC2ãã²ã¨ã¾ã¨ãã«ãããã®ãKubernetesã®ã¯ã©ã¹ã¿ã¼ã¨åãæãã§ããã
ä»åã¯Fargateã使ãã®ã§ããããã¯ã¼ãã³ã°ã®ã¿ã使ç¨ãã¾ãã
ECS ãµã¼ãã¹
å¾è¿°ããã¿ã¹ã¯ã管çãããã®ã§ãã¿ã¹ã¯å®ç¾©ããèµ·åæ°ãæå®ãããã®ç¶æ
ã«å¤æ´ãç¶æãã¦ããã¾ãã
1ãµã¼ãã¹ã«å¯¾ãã1ã¿ã¹ã¯å®ç¾©ã£ã½ãã
ã¾ãå¾è¿°ãããã¼ããã©ã³ãµã¼ããµã¼ãã¹ã¨ç´ã¥ãããã¨ã«ãªãã¾ãã
Amazon ECS サービス - Amazon ECS
ä½æå¾ã«å¤æ´ã§ããªãè¨å®ãå¤ã ããã5åãããã¯ä½ãç´ããè¨æ¶ãããã¾ãã
ã¿ã¹ã¯å®ç¾©
ã¿ã¹ã¯ã®è¨è¨æ¸ã®ãããªãã®ã§ãããã«ä½¿ç¨ããã³ã³ããï¼è¤æ°å¯ï¼ããã³ã³ãããã¨ã®ç°å¢å¤æ°ãªã©ã®è¨å®ãå¿
è¦ãªãªã½ã¼ã¹ï¼CPUãã¡ã¢ãªçï¼ãæå®ãã¾ãã
ãã¡ããä½ææã«èµ·åã¿ã¤ãã«Fargateãæå®ãã¾ãï¼ããä¸ã¤ã¯EC2ï¼ã
æ´æ°ã®éã¯ãä¸æ¸ãã§ã¯ãªãããªãã¸ã§ã³ãå¢ããã¦ããå½¢ã«ãªãã¾ãã
Amazon ECS タスク定義 - Amazon Elastic Container Service
ã³ã³ããå®ç¾©
å
·ä½çãªã³ã³ããå®ç¾©ã¯ã¿ã¹ã¯å®ç¾©å
ã«ããã¾ããéãããã¼ãã®æå®ãããã
åãã¿ã¹ã¯å®ç¾©å
ã§ããã°ã127.0.0.1ã§éä¿¡ã§ãããããªã®ã§ãnginxããappã¸ã®ãããã·è¨å®ã§ã¯127.0.0.1ã使ç¨ãã¾ããã
Kubernetesã ã¨Serviceãä½ãå¿
è¦ããã£ããé¢åãªã®ã§ãä»åã¯ããã§ååã ããã·ã³ãã«ã«æãã¾ãã
â»ãã¨ã§queueã¯å¥ãµã¼ãã¹ã«åãã¾ãã
ãµã¼ãã¹ã§ã®ãã¼ããã©ã³ãµã¼è¨å®ã¯ãããã§è¨å®ããnginxã³ã³ããã®ãã¼ã80ãæå®ãã¾ããã
ã¿ã¹ã¯
ä¸è¨ã®ã¿ã¹ã¯ããµã¼ãã¹ãèµ·åãããã®ãããã°ã©ãã³ã°ã ã¨ã¿ã¹ã¯å®ç¾©ãã¯ã©ã¹ãã¿ã¹ã¯ãã¤ã³ã¹ã¿ã³ã¹ãã¿ãããªã¤ã¡ã¼ã¸ï¼
å¤æ´ã®éã¯ã¿ã¹ã¯å®ç¾©ã®ãªãã¸ã§ã³ãæå®ãã¦æ´æ°ãã¾ãã
ã¹ã±ã¼ã«ãããã®ããã®ã¿ã¹ã¯åä½
é »ç¹ã«æ¶ããããä½ã£ãããããã®ãªã®ã§ãã¿ã¹ã¯IDã¯
32034c0a56d84d5eb95908090cdec44c
ã¿ãããªã©ã³ãã ãª16é²æååã«ãªãã¾ãï¼å¾è¿°ã®ã·ã§ã«ã§å ¥ãã¨ãã«ä½¿ãï¼ã
ãµã¼ãã¹ãæ´æ°ããã¨æ°ããã®ãã§ãããå¤ãã®ãæ¶ããããã¾ãã
ECS以å¤
ECSã¨é¢ä¿ããã®ã以ä¸ã®ãµã¼ãã¹ï¼æ©è½ã«ãªãã¾ãã
VPC (Virtual Private Cloud)
Amazon VPC(仮想ネットワーク内での AWS リソースの起動)| AWS
ã¯ã©ã¹ã¿ã¼ä½¿ç¨æã«é¸æãã¾ãã¯ä½æãã¾ããä»®æ³ã®ãããã¯ã¼ã¯ã§ãã»ãã¥ãªãã£è¨å®ãªã©ã«å½±é¿ãã¾ãã
æ°è¦ã®ã¨ãã¯ä¸ç·ã«ä½ãã°ããã§ãããæ¢åã®ã·ã¹ãã ãããã¨ãã¯åããã®ã使ç¨ããªãã¨ãããããç¹ããã®ãé¢åã«ãªãã®ã§ã注æãå¿
è¦ã§ããã
ãã¼ããã©ã³ãµã¼ï¼Application Load Balancerï¼
ã³ã³ã½ã¼ã«ä¸ã§ã¯EC2ã®ä¸ã«ããæ©è½ã§ãã
Elastic Load Balancing(複数のターゲットにわたる着信トラフィックの分配)| AWS
ä¸è¨ãµã¼ãã¹ãã¤ã³ã¿ã¼ãããã«å
¬éããéã«ä½¿ç¨ãã¾ãã
ããã¤ã種é¡ãããã¾ãããECSã§ã¯Application Load Balancerã使ç¨ãã¾ãã
詳細ã¯çç¥ãã¾ãããSSL証ææ¸ã¯ããã§è¨å®ã§ãããããECSå´ã§ã®HTTPSå¦çã¯ä¸è¦ã§ãã
è¨ç½®ããVPCã¯ECSã¯ã©ã¹ã¿ã¼ã¨åãã«ãã¦ãããæ¹ãããããã§ãï¼ä¸å¯è½ã§ã¯ãªãããï¼ã
ãã¼ããã©ã³ãµã¼ã®ãªã¹ãã¼
ãã¼ããã©ã³ãµã¼ããªã¯ã¨ã¹ããåãããã¼ãã§ãã
ä»åã¯ä¸è¬çãªWEBã¢ããªãªã®ã§80ã¨443ãä½ããä¸è¨ECSãµã¼ãã¹ã¨é£æºããã¿ã¼ã²ããã°ã«ã¼ãã転éå
ã«ãã¾ãã
ããã80ã¯ãµã¼ãã¹ä½ææã«ä½ããã¾ããããHTTPSã®443ã®æ¹ã¯æä½æ¥ã§è¿½å ããå¿
è¦ããã£ãæ°ããã¾ãã
Route 53
Amazon Route 53(スケーラブルなドメインネームシステム (DNS))| AWS
è¨ããã¨ãããDNSãµã¼ãã¹ã
ä¸è¨ãã¼ããã©ã³ãµã¼ã§ã¯
foobar-4580172169.ap-northeast-1.elb.amazonaws.com
ã®ãããªé·ãã®URLãæ¯ããããããç¬èªãã¡ã¤ã³ã使ç¨ããéã¯Route53ã§ç´ä»ãã¾ãã
Aã¬ã³ã¼ãããé¸æå½¢å¼ã§ç°¡åã«æå®ã§ãã¾ãã
ã¿ã¼ã²ããã°ã«ã¼ã
ãã¼ããã©ã³ãµã¼ããä»åã®ECSã®ãµã¼ãã¹ã«ç¹ãã転éå
ï¼å®ä½ã¯ã¿ã¹ã¯ã®ãã¼ã«ã«IPï¼ã«ä½¿ç¨ããã¾ãã
ãã¼ããã©ã³ãµã¼ã®æ°è¦ä½ææããECSã§ãµã¼ãã¹ãä½ãéã«èªåã§ã§ãã¦ãã¾ãã®ã§ããµã¼ãã¹ãä½ãç´ãããããã¨ãä½è¨ãªãã®ãæ®ã£ã¦ãã¦éªéã«ãªãæ¶ãã®ãé¢åã§ããã
ECSã®ãµã¼ãã¹ã¯ãã¿ã¹ã¯ãæ´æ°ããããã«ã¹ãã§ãã¯ãéãã¨ããã®ã¿ã¼ã²ããã°ã«ã¼ãã®IPãèªåã§å¤æ´ãããã¨ã§ãã¦ã¼ã¶ã¼å´ã¸ãå¤æ´ããã¾ãã
ã»ãã¥ãªãã£ã°ã«ã¼ã
ECSã®ãµã¼ãã¹ãæã¡ã¾ãã
IPã¯å¤ãã£ã¦ãã¾ãã®ã§ãããã使ã£ã¦ãVPCå
ã®é信許å¯ãªã©ãè¡ãã¾ãã
ç¾ç°å¢ã§ã¯æ¢åã®ã»ãã¥ãªãã£ã°ã«ã¼ãã«ããµã¼ãã¹ããRDSãRedisã¸ã®è¨±å¯ã追å ãã¾ããã
Secrets Manager
ã³ã³ããã§ä½¿ããã¹ã¯ã¼ãçã®æ©å¯æ
å ±ãä¿æãã¾ãã
ã¨ããããLaravelã§.envãã¡ã¤ã«ã§ä½¿ç¨ãã¦ããé
ç®ã移ãã¾ããã
AWS Secrets Manager(シークレットのローテーション、管理、取得)| AWS
ã¿ã¹ã¯å®ç¾©ã§ãã³ã³ãããã¨ã«è¨å®ããç°å¢å¤æ°ã¨ãã¦ä½¿ããã¨ãã§ãã¾ãã
JSONå½¢å¼ã®ãªãã¸ã§ã¯ãå½¢å¼ã§è¤æ°æã¤ãã¨ãã§ãã¾ãããèªåã§ç°å¢å¤æ°ã«å±éãããã¨ã¯ã§ããªããããªã®ã§
valueFromã§ä¸ã¤ãã¤
arn:aws:secretsmanager:ap-northeast-1:user-id:secret:secret-name-AAAAAA:YOURENV::
ã®ããã«æå®ãã¦èªã¿è¾¼ãå¿ è¦ãããã¾ããã
ãã®ãã¥ã¼ããªã¢ã«ã®ããã«IAMãã¼ã«ã®è¿½å ãå¿
è¦ã§ãã
チュートリアル: Secrets Manager シークレットを使用した機密データの指定 - Amazon Elastic Container Service
ãã®ä»
åããããã«ããããªè¨å®ãç解ãä¿®æ£ããå¿ è¦ããããç¬èªãã¡ã¤ã³ããã³ã³ããã®WEBã¢ããªã±ã¼ã·ã§ã³ã¾ã§ç¹ããã®ã«å¹¾åº¦ã¨ãªãã¯ã¾ãã3æ¥ããããããã¾ããããªãã¨ãåãããã¨ãã§ãã¾ããã
Circle CIã§ECRã«ããã·ã¥ï¼ã¢ãããã¼ã
ã³ã³ããå¤æ´ã®ãã³ã«æä½æ¥ã§ãã«ããããã·ã¥ããã®ã¯ç¾å®çã§ã¯ãªãã®ã§ãªãã¹ãæ©ã段éã§ãã£ãæ¹ãããããã§ãã
ã·ãã¢ã¸ã§ãã§ã¯Circle CIã使ã£ã¦ããã®ã§ããã®ã¾ã¾å©ç¨ãã¾ãããGitHub Actionsã§ããã£ã¦ã¿ãããªãã
Circle CIã®ããããªå¦çãã¾ã¨ããOrbsã使ãã¨ãã£ã¡ãç°¡åã§ããã
ã»ã¼å
¬å¼ã¾ãã¾ã§ãããservice-nameã ãå
¬å¼ããã¥ã¡ã³ãã«ãªããããã©ã«ãå¤ã§ã¯ãã¾ããããªãã£ãã®ã§ãorbã®ã½ã¼ã¹ãè¦ã¦è¿½å ãã¾ããã
ã¾ãfamilyããããã«ããã§ãããã¿ã¹ã¯å®ç¾©ãJSONã§ç¢ºèªããã¨familyã®é
ç®ãè¦ã¤ããã¾ãã
ã¾ã ã¹ãã¼ã¸ã³ã°ç°å¢ã ããªã®ã§tagã®å é ã«stageãåºå®ã§ã¤ãã¦ã¾ãã
.circleci/config.yml
version: 2.1 orbs: aws-ecr: circleci/[email protected] aws-ecs: circleci/[email protected] workflows: build_and_push_image_app: jobs: - aws-ecr/build-and-push-image: account-url: AWS_ECR_ACCOUNT_URL aws-access-key-id: AWS_ACCESS_KEY_ID aws-secret-access-key: AWS_SECRET_ACCESS_KEY dockerfile: ./Dockerfiles/app/Dockerfile path: . region: AWS_REGION repo: senior-job/app create-repo: true tag: "stage-$CIRCLE_SHA1" - aws-ecs/deploy-service-update: cluster-name: 'example' service-name: 'example-service' container-image-name-updates: 'container=app-container,tag=stage-${CIRCLE_SHA1}' family: 'example' requires: - aws-ecr/build-and-push-image - aws-ecs/deploy-service-update: cluster-name: 'example' service-name: 'example-service' container-image-name-updates: 'container=queue-container,tag=stage-${CIRCLE_SHA1}' family: 'example' requires: - aws-ecr/build-and-push-image
ã³ã³ããã«ã·ã§ã«ã§å ¥ã
ãªãããã¾ãè¡ããªãæã¯ãä¸ã§ç°å¢å¤æ°ãã©ããªã£ã¦ããã¨ãããã¡ã¤ã«ã¡ããã¨ãããã¨ãããã£ã±ãã³ã³ããã®ä¸ã«å ¥ã£ã¦ç¢ºèªããããã®ã
Kubernetesã ã¨`kubectl exec -it pod_name bash`ã¿ããã«ãµã©ã£ã¨å ¥ãã¾ãããä¸çç¸ã§ã¯è¡ãã¾ããã§ããã
ç¹ã«Fargateã¯EC2ã触ããªããã¨ãããé£ããã£ãã¿ããã§ããæè¿(2021/3)å
¬å¼ãªæ段ãæºåãããããã§ãã
ãã®ããã¸ã§ã¯ãã2ã¶ææ©ãã£ããè©°ãã§ãããã5年以ä¸åã§ãexecã¯ã§ãã¦ãã®ã§ãå
¨ä½çãªå®æ度ã¨ãã¦ã¯Kubernetesããã£ã±é²ãã§ããªãã¨æã£ãã§ããã¨ã§ããã
New – Amazon ECS Exec による AWS Fargate, Amazon EC2 上のコンテナへのアクセス | Amazon Web Services ブログ
権éä»ä¸ããµã¼ãã¹ã®è¨å®å¤æ´ãCLIã®ã¢ãããã¼ããªã©ããããé¢åã§ãããããã¡ãã®è¨äºãã¾ã¨ã¾ã£ã¦ãã¦ããããããã£ãã§ãã
[アップデート] 実行中のコンテナに乗り込んでコマンドを実行できる「ECS Exec」が公開されました | DevelopersIO
ãããã
ã¾ã ã¹ãã¼ã¸ã³ã°ç°å¢ãåããã ããªã®ã§ãããã¤ãã¾ã ãããªããããã¤ããã»ã¹ã®è¿½å ããæ»æ´»ç£è¦é¢ä¿ãæ¬çªã§ã®ãªã½ã¼ã¹èª¿æ´ããªã¼ãã¹ã±ã¼ã«è¨å®ãªã©ãã¾ã ã¾ã ããããããããã§ãã
ãã¨AWSã ãã ã¨èªååã¤ããã®ã§Terraformã使ã£ãæ¹ãããã®ããªãã¨ãã
2021/4/15 追è¨
appã®ãµã¼ãã¹ï¼php-fpmã¨nginxï¼ã¨queueãå®è¡ãããµã¼ãã¹ï¼ã¿ã¹ã¯ã¯åããæ¹ãè¯ãã¨æã£ã