Target Groups Application Pipeline Setup
-
AWS console ⇒ EC2:
-
Target Groups ⇒ Create target group
-
Create 2 groups
-
Ludlow2-api-qa
-
Ludlow2-api-prod
The port doesn’t matter, keep it as default: 80.
Load Balancer setup
-
AWS console ⇒ EC2 ⇒ Load Balancers ⇒ Create Load Balancer
-
Select: Application Load Balancer
-
Add 2 Listeners: HTTP / HTTPS, Select All Availability Zones.
-
Choose a certificate
-
Select an existing security group: default
-
New target group or Select existing one: Ludlow2-api-prod. Port doesn’t matter, keep it as default: 80.
-
No need to Register Targets, which will be register automatically by our ECS Services.
-
Review and Create
-
Select the new created Load Balancer: Ludlow2 ⇒ Listeners: 80/443 ⇒ View/edit rules
-
Add a rule: If Host is qa.ludlow.io forward to Target Group: Ludlow2-api-qa
EC2 Instance setup
The EC2 instance where we need to add an inbound rule letting a Load Balancer redirect the request, should be created while creating ECS Cluster below.
-
AWS console ⇒ EC2 ⇒ Instances ⇒ Ludlow2 ⇒ click Security groups
-
Inbound ⇒ Edit
-
Add Rule, Type pick All TCP, Source input the Security Group ID(sg-964aa2ef) from Load Balancer: Ludlow2
ECS Cluster setup
-
AWS console ⇒ Elastic Container Service:
-
Clusters ⇒ Create Cluster
-
Select EC2 Linux + Networking
-
Use default EC2 instance.
-
Networking use existing VPC, Subnet, and Security group. Security group should be the same as the one in Load Balancer, i.e. default.
ECR Repositories setup
-
AWS console ⇒ Elastic Container Service ⇒ Repositories ⇒ Create repository
-
Create two repositories: ludlow2-api-qa, ludlow2-api-prod.
-
Write down the commands, which will be used in CI platform: TeamCity.
ECS Task Definitions setup
-
AWS console ⇒ Elastic Container Service ⇒ Task Definitions ⇒ Create new Task Definition
-
Select EC2 as launch type compatibility
-
Configure task and container definitions
-
Add container
-
Standard configuration:
-
Image points to the Repository we just created: ludlow2-api-qa
-
Memory Limits should set to Hard limit for qa, just in case of affecting the prod Task’s memory
-
Port mappings: Host port must be set to 0, in order to register to a Target Group with a dynamic port, which allow two different Tasks(Blue/Green Deployment) running at the same time, one for old version image, one for new version image. Container port is whatever you set in application’s Dockerfile.
-
Advanced container configuration
-
STORAGE AND LOGGING ⇒ Log configuration ⇒ check Auto-configure CloudWatch Logs, this makes sure all the console log will go to CloudWatch.
ECS Services setup
-
AWS console ⇒ Elastic Container Service ⇒ Clusters ⇒ Ludlow2
-
Services ⇒ Create
-
Configure services
-
Make sure Maximum percent * Number of tasks >= Number of tasks + 1, letting your new task can be started while the old one is stopping.
-
Configure network
-
Load balancer type: Application Load Balancer
-
Select Load Balancer: Ludlow2, Click Add to load balancer
-
Target group name, pick Ludlow2-api-qa