copilot을 이용하여 폭속으로 현대 ECS 환경을 구축할 수 있다
이 문장에 관하여
AWS & Game Advent Calendar 2020 23일째 기사입니다.
AWS에서 컨테이너를 옮길 때 가장 먼저 후보가 되는 서비스는 ECS라고 생각합니다.
굉장히 편리한 서비스인 건 맞지만 일단 사용하게 되면 여러모로 고려해볼 부분이 많습니다.
다른 한편, ECS는 광범위하게 사용되고 있으며, 어떤'이용에 대한 최선의 실천'이 일어나고 있다.
매번 1부터 구축할 수 있으니 가능하다면 최선의 실천을 따라 더욱 간단하게 구축하면 편리하다.
이러한 소망을 실현할 수 있는 도구는 2020/11/23에 정식으로 출시된다.AWS Copilot이라고 합니다.
무슨 일이야?
https://aws.amazon.com/jp/blogs/news/introducing-aws-copilot/
실제 사용
설치
GitHub에서 최신 바이너리 파일 삭제$ curl -Lo /usr/local/bin/copilot https://github.com/aws/copilot-cli/releases/download/v0.1.0/copilot-darwin-v0.1.0 && chmod +x /usr/local/bin/copilot
$ copilot --help
👩✈️ Launch and manage applications on Amazon ECS and AWS Fargate.
Commands
Getting Started 🌱
init Create a new ECS application.
docs Open the copilot docs.
Develop ✨
app Commands for applications.
Applications are a collection of services and environments.
env Commands for environments.
Environments are deployment stages shared between services.
svc Commands for services.
Services are long-running Amazon ECS services.
Release 🚀
pipeline Commands for pipelines.
Continuous delivery pipelines to release services.
deploy Deploy your service.
Settings ⚙️
version Print the version number.
completion Output shell completion code.
Flags
-h, --help help for copilot
-v, --version version for copilot
Examples
Displays the help menu for the "init" command.
`$ copilot init --help`
예제 애플리케이션 클론
$ git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git aws-copilot-example
인증 설정
aws configure
에서 구성 파일을 만들고 환경 변수AWS_PROFILE
로 설정합니다.$ aws configure --profile copilot-example
$ export AWS_PROFILE=copilot-example
응용 프로그램 설정
Git에서 Clone으로 이동하는 디렉토리를 설정합니다.copilot init
AWS에 필요한 리소스를 대화식으로 입력할 수 있습니다.$ cd aws-copilot-example
$ copilot init
Note: It's best to run this command in the root of your Git repository.
Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with an application on ECS. An application is a collection of
containerized services that operate together.
What would you like to name your application? [? for help] copilot-example-app
Application name: copilot-example-app
Which service type best represents your service's architecture? [Use arrows to move, type to filter, ? for more help]
> Load Balanced Web Service
Backend Service
Application name: copilot-example-app
Service type: Load Balanced Web Service
What do you want to name this Load Balanced Web Service? [? for help] copilot-example-service
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Which Dockerfile would you like to use for copilot-example-service? [Use arrows to move, type to filter, ? for more help]
> ./Dockerfile
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Dockerfile: ./Dockerfile
no EXPOSE statements in Dockerfile ./Dockerfile
Which port do you want customer traffic sent to? [? for help] (80) 80
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Dockerfile: ./Dockerfile
no EXPOSE statements in Dockerfile ./Dockerfile
Port: 80
Ok great, we'll set up a Load Balanced Web Service named copilot-example-service in application copilot-example-app listening on port 80.
✔ Created the infrastructure to manage services under application copilot-example-app.
✔ Manifest file for service copilot-example-service already exists at copilot/copilot-example-service/manifest.yml, skipping writing it.
Your manifest contains configurations like your container size and port (:80).
✔ Created ECR repositories for service copilot-example-service.
All right, you're all set for local development.
Would you like to deploy a test environment? [? for help] (y/N) y
All right, you're all set for local development.
Deploy: Yes
All right, you're all set for local development.
Deploy: Yes
✔ Created the infrastructure for the test environment.
- Virtual private cloud on 2 availability zones to hold your services [Complete]
- Virtual private cloud on 2 availability zones to hold your services [Complete]
- Internet gateway to connect the network to the internet [Complete]
- Public subnets for internet facing services [Complete]
- Private subnets for services that can't be reached from the internet [Complete]
- Routing tables for services to talk with each other [Complete]
- ECS Cluster to hold your services [Complete]
- Application load balancer to distribute traffic [Complete]
✔ Linked account XXXXXXXXXXXX and region ap-northeast-1 to application copilot-example-app.
✔ Created environment test in region ap-northeast-1 under application copilot-example-app.
Sending build context to Docker daemon 88.06kB
Step 1/2 : FROM nginx
---> ae2feff98a0c
Step 2/2 : COPY index.html /usr/share/nginx/html
---> Using cache
---> ad1b08cb2bb0
Successfully built ad1b08cb2bb0
Successfully tagged XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/copilot-example-app/copilot-example-service:cee7709
Login Succeeded
The push refers to repository [XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/copilot-example-app/copilot-example-service]
2e8160029ff7: Pushed
4eaf0ea085df: Pushed
2c7498eef94a: Pushed
7d2b207c2679: Pushed
5c4e5adc71a8: Pushed
87c8a1d8f54f: Pushed
cee7709: digest: sha256:fe7757f53a6d9a90c57cafd32578e5b5290430cf0a06067ba92b0031fb00c873 size: 1570
✔ Deployed copilot-example-service, you can access it at http://{ELB_ENDPOINT}
실행이 완료되면 테스트 환경이 생성되고 ELB 끝점의 URL이 반환됩니다.한번 방문해보세요.
떴네.이번에는 샘플 응용 프로그램으로 실제 개발에서 이 화면을 보여주기 전에 구축해야 할 AWS 자원이 상당히 많다.
명령의 집행 자체가 10분 정도면 완성되기 때문에 짧은 시간 안에 필요한 것을 수집할 수 있다는 것이 매력적이다.
참고로 뒷면에서 CloudFormation 스택을 실행하고 있습니다.
논리 식별자
유형
AdministrationRole
AWS::IAM::Role
ExecutionRole
AWS::IAM::Role
CloudformationExecutionRole
AWS::IAM::Role
Cluster
AWS::ECS::Cluster
DefaultHTTPTargetGroup
AWS::ElasticLoadBalancingV2::TargetGroup
DefaultPublicRoute
AWS::EC2::Route
EnableLongARNFormatAction
Custom::EnableLongARNFormatFunction
EnableLongARNFormatFunction
AWS::Lambda::Function
EnvironmentManagerRole
AWS::IAM::Role
EnvironmentSecurityGroup
AWS::EC2::SecurityGroup
EnvironmentSecurityGroupIngressFromPublicALB
AWS::EC2::SecurityGroupIngress
EnvironmentSecurityGroupIngressFromSelf
AWS::EC2::SecurityGroupIngress
HTTPListener
AWS::ElasticLoadBalancingV2::Listener
InternetGateway
AWS::EC2::InternetGateway
InternetGatewayAttachment
AWS::EC2::VPCGatewayAttachment
PrivateSubnet1
AWS::EC2::Subnet
PrivateSubnet2
AWS::EC2::Subnet
PublicLoadBalancer
AWS::ElasticLoadBalancingV2::LoadBalancer
PublicLoadBalancerSecurityGroup
AWS::EC2::SecurityGroup
PublicRouteTable
AWS::EC2::RouteTable
PublicSubnet1
AWS::EC2::Subnet
PublicSubnet1RouteTableAssociation
AWS::EC2::SubnetRouteTableAssociation
PublicSubnet2
AWS::EC2::Subnet
PublicSubnet2RouteTableAssociation
AWS::EC2::SubnetRouteTableAssociation
ServiceDiscoveryNamespace
AWS::ServiceDiscovery::PrivateDnsNamespace
VPC
AWS::EC2::VPC
ECRRepocopilotDASHexampleDASHservice
AWS::ECR::Repository
KMSKey
AWS::KMS::Key
PipelineBuiltArtifactBucket
AWS::S3::Bucket
PipelineBuiltArtifactBucketPolicy
AWS::S3::BucketPolicy
CustomResourceRole
AWS::IAM::Role
DiscoveryService
AWS::ServiceDiscovery::Service
ExecutionRole
AWS::IAM::Role
HTTPListenerRule
AWS::ElasticLoadBalancingV2::ListenerRule
HTTPRulePriorityAction
Custom::RulePriorityFunction
HTTPWaitHandle
AWS::CloudFormation::WaitConditionHandle
LogGroup
AWS::Logs::LogGroup
RulePriorityFunction
AWS::Lambda::Function
Service
AWS::ECS::Service
TargetGroup
AWS::ElasticLoadBalancingV2::TargetGroup
TaskDefinition
AWS::ECS::TaskDefinition
TaskRole
AWS::IAM::Role
WaitUntilListenerRuleIsCreated
AWS::CloudFormation::WaitCondition
이렇게 많은 자원을 구축했다.
현재 부팅 유형은 Fargate 뿐입니다. EC2에서 부팅하려면 수동으로 작성해야 할 수 있습니다.
copilot을 ECS 환경을 구축하는 시작 도구 패키지로 사용하려면 작은 필요조건과 자신의 추가 사용 방법을 설정하는 것이 가장 적합하다.
응용 프로그램의copilot 작업
copilot app show
에서copilot에 구축된 응용 프로그램/환경/서비스에 대한 정보를 볼 수 있습니다.$ copilot app show
About
Name copilot-example-app
URI
Environments
Name AccountID Region
test XXXXXXXXXXXX ap-northeast-1
Services
Name Type
copilot-example-service Load Balanced Web Service
시작된 작업에서 출력된 로그가 클라우드 지갑에 저장됩니다.
관리 콘솔에서 로그 copilot svc logs
를 볼 수 있습니다.$ copilot svc logs
Showing logs of service copilot-example-service deployed in environment test
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:01 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:12 +0000] "GET / HTTP/1.1" 200 3165 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:12 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
지금은 테스트 환경밖에 없으니 생산 환경을 만들어 보세요.
새로운 prod
환경을 만들고 방금 만든 copilot-example-service
환경을 배치합니다.$ copilot env init --name prod
$ copilot svc deploy --name copilot-example-service --env prod
배포가 완료되면 테스트 환경을 만드는 것처럼 ELB 노드를 통해 ECS에 액세스할 수 있습니다.
응용 프로그램의 정보와 로그를 보십시오.$ copilot app show
About
Name copilot-example-app
URI
Environments
Name AccountID Region
test XXXXXXXXXXXX ap-northeast-1
prod XXXXXXXXXXXX ap-northeast-1
Services
Name Type
copilot-example-service Load Balanced Web Service
$ copilot svc logs copilot-example-service --env prod
Showing logs of service copilot-example-service deployed in environment prod
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:25 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
방문은 정상입니다. 문제가 없는 것 같습니다.copilot app show
이면 정보가 좀 적고copilot svc status
서비스 상태를 확인할 수 있다.$ copilot svc status copilot-example-service --env prod
Showing status of service copilot-example-service deployed in environment prod
Service Status
ACTIVE 1 / 1 running tasks (0 pending)
Last Deployment
Updated At 6 minutes ago
Task Definition arn:aws:ecs:ap-northeast-1:XXXXXXXXXXXX:task-definition/copilot-example-app-prod-copilot-example-service:1
Task Status
ID Image Digest Last Status Health Status Started At Stopped At
7788f7bc fe7757f5 RUNNING UNKNOWN 7 minutes ago -
Alarms
Name Health Last Updated Reason
동작을 한 번 확인했다.돈 쓸 거니까 청소 좀 하자.실행copilot app delete
.$ copilot app delete
Are you sure you want to delete application copilot-example-app? Yes
✔ Deleted service copilot-example-service from environment test.
✔ Deleted service copilot-example-service from environment prod.
✔ Deleted service copilot-example-service resources from application copilot-example-app.
✔ Deleted service copilot-example-service from application copilot-example-app.
✔ Deleted environment test from application copilot-example-app.
✔ Deleted environment prod from application copilot-example-app.
✔ Cleaned up deployment resources.
✔ Deleted application resources.
✔ Deleted application configuration.
✔ Deleted local .workspace file.
청소를 마쳤습니다. Cloud Formation에서 관리하기 때문에 거기서 삭제하면 필요 없는 물건은 모두 깨끗해집니다.
총결산
copilot을 사용하면 모범 사례에 맞는 ECS 환경을 쉽게 구축할 수 있습니다.
이번 기사에서는 소개되지 않았지만 배포에 사용된 Code Pipeline 등 Code 계열 서비스도 copilot에서 구축한 것이다
Git에 대한 푸시를 트리거로 자동 배치하는 프로세스를 조정할 수 있기 때문에 다음에 기회가 되면 시도해 보고 싶습니다.
아직 출시된 지 얼마 되지 않았기 때문에 앞으로 더욱 편리한 업데이트를 진행할 것입니다.
나도 정기적으로copilot의 업데이트를 감시하고 싶다.
Reference
이 문제에 관하여(copilot을 이용하여 폭속으로 현대 ECS 환경을 구축할 수 있다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/yktr_sre/items/e8d554d2467e8a13fab3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ curl -Lo /usr/local/bin/copilot https://github.com/aws/copilot-cli/releases/download/v0.1.0/copilot-darwin-v0.1.0 && chmod +x /usr/local/bin/copilot
$ copilot --help
👩✈️ Launch and manage applications on Amazon ECS and AWS Fargate.
Commands
Getting Started 🌱
init Create a new ECS application.
docs Open the copilot docs.
Develop ✨
app Commands for applications.
Applications are a collection of services and environments.
env Commands for environments.
Environments are deployment stages shared between services.
svc Commands for services.
Services are long-running Amazon ECS services.
Release 🚀
pipeline Commands for pipelines.
Continuous delivery pipelines to release services.
deploy Deploy your service.
Settings ⚙️
version Print the version number.
completion Output shell completion code.
Flags
-h, --help help for copilot
-v, --version version for copilot
Examples
Displays the help menu for the "init" command.
`$ copilot init --help`
$ git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git aws-copilot-example
$ aws configure --profile copilot-example
$ export AWS_PROFILE=copilot-example
$ cd aws-copilot-example
$ copilot init
Note: It's best to run this command in the root of your Git repository.
Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with an application on ECS. An application is a collection of
containerized services that operate together.
What would you like to name your application? [? for help] copilot-example-app
Application name: copilot-example-app
Which service type best represents your service's architecture? [Use arrows to move, type to filter, ? for more help]
> Load Balanced Web Service
Backend Service
Application name: copilot-example-app
Service type: Load Balanced Web Service
What do you want to name this Load Balanced Web Service? [? for help] copilot-example-service
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Which Dockerfile would you like to use for copilot-example-service? [Use arrows to move, type to filter, ? for more help]
> ./Dockerfile
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Dockerfile: ./Dockerfile
no EXPOSE statements in Dockerfile ./Dockerfile
Which port do you want customer traffic sent to? [? for help] (80) 80
Application name: copilot-example-app
Service type: Load Balanced Web Service
Service name: copilot-example-service
Dockerfile: ./Dockerfile
no EXPOSE statements in Dockerfile ./Dockerfile
Port: 80
Ok great, we'll set up a Load Balanced Web Service named copilot-example-service in application copilot-example-app listening on port 80.
✔ Created the infrastructure to manage services under application copilot-example-app.
✔ Manifest file for service copilot-example-service already exists at copilot/copilot-example-service/manifest.yml, skipping writing it.
Your manifest contains configurations like your container size and port (:80).
✔ Created ECR repositories for service copilot-example-service.
All right, you're all set for local development.
Would you like to deploy a test environment? [? for help] (y/N) y
All right, you're all set for local development.
Deploy: Yes
All right, you're all set for local development.
Deploy: Yes
✔ Created the infrastructure for the test environment.
- Virtual private cloud on 2 availability zones to hold your services [Complete]
- Virtual private cloud on 2 availability zones to hold your services [Complete]
- Internet gateway to connect the network to the internet [Complete]
- Public subnets for internet facing services [Complete]
- Private subnets for services that can't be reached from the internet [Complete]
- Routing tables for services to talk with each other [Complete]
- ECS Cluster to hold your services [Complete]
- Application load balancer to distribute traffic [Complete]
✔ Linked account XXXXXXXXXXXX and region ap-northeast-1 to application copilot-example-app.
✔ Created environment test in region ap-northeast-1 under application copilot-example-app.
Sending build context to Docker daemon 88.06kB
Step 1/2 : FROM nginx
---> ae2feff98a0c
Step 2/2 : COPY index.html /usr/share/nginx/html
---> Using cache
---> ad1b08cb2bb0
Successfully built ad1b08cb2bb0
Successfully tagged XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/copilot-example-app/copilot-example-service:cee7709
Login Succeeded
The push refers to repository [XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/copilot-example-app/copilot-example-service]
2e8160029ff7: Pushed
4eaf0ea085df: Pushed
2c7498eef94a: Pushed
7d2b207c2679: Pushed
5c4e5adc71a8: Pushed
87c8a1d8f54f: Pushed
cee7709: digest: sha256:fe7757f53a6d9a90c57cafd32578e5b5290430cf0a06067ba92b0031fb00c873 size: 1570
✔ Deployed copilot-example-service, you can access it at http://{ELB_ENDPOINT}
$ copilot app show
About
Name copilot-example-app
URI
Environments
Name AccountID Region
test XXXXXXXXXXXX ap-northeast-1
Services
Name Type
copilot-example-service Load Balanced Web Service
$ copilot svc logs
Showing logs of service copilot-example-service deployed in environment test
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:01 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:12 +0000] "GET / HTTP/1.1" 200 3165 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
copilot-example-service/0 10.0.1.45 - - [24/Dec/2020:18:03:12 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
$ copilot env init --name prod
$ copilot svc deploy --name copilot-example-service --env prod
$ copilot app show
About
Name copilot-example-app
URI
Environments
Name AccountID Region
test XXXXXXXXXXXX ap-northeast-1
prod XXXXXXXXXXXX ap-northeast-1
Services
Name Type
copilot-example-service Load Balanced Web Service
$ copilot svc logs copilot-example-service --env prod
Showing logs of service copilot-example-service deployed in environment prod
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:25 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
copilot-example-service/7 10.0.0.206 - - [24/Dec/2020:18:20:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "XXX.XXX.XXX.XXX"
$ copilot svc status copilot-example-service --env prod
Showing status of service copilot-example-service deployed in environment prod
Service Status
ACTIVE 1 / 1 running tasks (0 pending)
Last Deployment
Updated At 6 minutes ago
Task Definition arn:aws:ecs:ap-northeast-1:XXXXXXXXXXXX:task-definition/copilot-example-app-prod-copilot-example-service:1
Task Status
ID Image Digest Last Status Health Status Started At Stopped At
7788f7bc fe7757f5 RUNNING UNKNOWN 7 minutes ago -
Alarms
Name Health Last Updated Reason
$ copilot app delete
Are you sure you want to delete application copilot-example-app? Yes
✔ Deleted service copilot-example-service from environment test.
✔ Deleted service copilot-example-service from environment prod.
✔ Deleted service copilot-example-service resources from application copilot-example-app.
✔ Deleted service copilot-example-service from application copilot-example-app.
✔ Deleted environment test from application copilot-example-app.
✔ Deleted environment prod from application copilot-example-app.
✔ Cleaned up deployment resources.
✔ Deleted application resources.
✔ Deleted application configuration.
✔ Deleted local .workspace file.
Reference
이 문제에 관하여(copilot을 이용하여 폭속으로 현대 ECS 환경을 구축할 수 있다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yktr_sre/items/e8d554d2467e8a13fab3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)