Description: In the previous topic, I explained how to create containers using ECS in the AWS console. In this topic, I am going to explain how to create ECS clusters using Amazon ECS CLI.
Pre-requisites:
- IAM user with AdministratorAccess
- Keypair for accessing the container machine
- Install Amazon ECS CLI. We can install by referencing this link
- Install and configure Amazon CLI. We can configure by referencing this link
Configure the Amazon ECS CLI
After installing Amazon ECS CLI and Amazon CLI. Configure Amazon account either by this link or you can configure it manually by using the aws configure command as follow
Creating cluster configuration
ecs-cli configure --cluster HTTPDCluster --default-launch-type EC2 --config-name HTTPDConfig --region us-east-1
Here,
HTTPDCluster = Cluster Name
HTTPDConfig = ECS configuration Name
us-east-1 = Region Name
Creating profile using your access key and secret key
ecs-cli configure profile --access-key AWS_ACCESS_KEY_ID --secret-key AWS_SECRET_ACCESS_KEY --profile-name HTTP-Profile
Create Cluster in ECS: After setting up cluster configuration, Now it's time to create the cluster in ECS using the ecs-cli up command. There are many options to configure different aspects like the number of instances, Security group,
open port, key-pair to access ssh of the machine, etc...
Here, I have defined, VPC subnets and security groups because I have already created them. If you don't define it. It will create it automatically.
ecs-cli up --keypair docker --capability-iam --size 1 --vpc vpc-64ff7119 --subnets subnet-ba16908b,subnet-658e8c28 --instance-type t2.micro --cluster-config HTTPDConfig --ecs-profile HTTP-Profile -security-group sg-0e3d5d8b98b008d77 --port 80
You will find a cluster under ECS
Create Docker Compose file: After creating the cluster, I am going to create Docker compose file to create an Apache container from the Docker hub image which we have created in the previous blog.
Here is the docker-compose file with version 3 docker-compose.yml it publishes port 80 and uses a custom docker hub repository.
version: '3' services: web: image: harpalgohilon/opensource:httpd ports: - "80:80" logging: driver: awslogs options: awslogs-group: HTTPD-tutorial awslogs-region: us-east-1 awslogs-stream-prefix: web
In version '3', CPU and memory need to define in a separate configuration file. So created a new file for the same with the name ecs-config.yml as follow:
version: 1 task_definition: services: web: cpu_shares: 100 mem_limit: 524288000
Deploy Container file to the cluster
ecs-cli compose up --create-log-groups --cluster-config HTTPDConfig --ecs-profile HTTP-Profile
You can find task details with URL
Browse this URL, you will get a custom page that I have used in the docker image
No comments:
Post a Comment