Aws ECS
- ecs elastic container service is fully managed by aws and used for container orchestration service which will help run, stopm and scale Docker container
core componets:
- cluster: A logical grouping of tasks or services
- Task defination: A json/configuration of your container or blue print of container
- service: Automatically manage containers like upgrade, rollback, loadblancer and replicas
lanch Types in ECS
- aws fargate: serverless compute which will managed by aws
- Amazon EC2-instance type: managed ec2 instance
create ec2 instance and install docker and awscli
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
sudo apt install unzip -y
curl -fsSL https://awscli.amazonaws.com/v2/install.sh | bash
curl -fsSL https://awscli.amazonaws.com/v2/install.sh | sudo bash -s -- --system
curl -fsSL https://awscli.amazonaws.com/v2/install.sh | bash -s -- --help
aws update
aws configure
AWS Access Key ID [None]: AKIAXHXSL4MX********
AWS Secret Access Key [None]: 2opqbBilS3UvCKkSpc*************
Default region name [None]: us-east-1
Default output format [None]: json
pull image and push public ECR
docker pull httpd:latest
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/i7p5t6j4
docker images
docker tag httpd:latest public.ecr.aws/i7p5t6j4/dev/apache2:latest
docker push public.ecr.aws/i7p5t6j4/dev/apache2:latest
steps to deploy httpd in ecs
- create cluster and select type fargate
- create task defination
{
"family": "apache2",
"containerDefinitions": [
{
"name": "httpd",
"image": "497650754350.dkr.ecr.us-east-1.amazonaws.com/dev/apache2@sha256:3a1e0bbe28c4673a03b7a3fbc71a56325eacb1a8d11c1ad696fbf9678f07febd",
"cpu": 2048,
"memory": 3072,
"memoryReservation": 1024,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"name": "httpd-80-tcp",
"appProtocol": "http"
}
],
"essential": true,
"restartPolicy": {
"enabled": true
},
"environment": [
{
"name": "container_type",
"value": "fargate"
},
{
"name": "enviroment",
"value": "dev"
},
{
"name": "project",
"value": "demo"
}
],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/apache2",
"awslogs-create-group": "true",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": []
}
],
"executionRoleArn": "arn:aws:iam::497650754350:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"volumes": [],
"placementConstraints": [],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "2048",
"memory": "4096",
"ephemeralStorage": {
"sizeInGiB": 21
},
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"enableFaultInjection": false
}
- create service with application loadbalancer
- open http, https port for loadbalancer secuirty group
- test ALB endpoint and access ecs apache2 container
Task
- create own image and push image ECR and deploy in ECS follow class recording.
- try both service and express service and run task.
- try to do it in terraform