I am planning to use ALB, ECS, and EC2.
Could you confirm if the following understanding is correct? I would greatly appreciate it if you could point out any inaccuracies, no matter how small.
Setting up ALB and ECS (Connection)
- Create an ECS Cluster
- Create an ECS Task Definition
- Define the container image.
- Create an ECS Service
- Select the Task Definition in the ECS Service (set the desired number of tasks, etc.).
- Create an ALB (Application Load Balancer)
- Add a Listener to ALB
- Create an ALB Target Group
- Select the Target Type:
IP
or Instance
.
- Connect ECS Service and ALB
- Modify ECS Service → Enable Load Balancing → Select Application Load Balancer → Select Target Group → Map to Container and Port.
- Verify that the running Tasks are automatically registered in the ALB Target Group (ECS Tasks become the Targets of the ALB).
Relationship Between ECS Task and Container
- An ECS Task is an execution unit that contains one or more containers.
- Containers within a Task share the same network namespace.
- The Target of the ALB is the ENI or IP address of the ECS Task.
- This setup registers the Task itself as the Target.
- The ALB forwards requests to the Task's ENI and routes traffic based on the port.
How Does ALB Deliver Requests to Containers?
- The Listener on ALB receives the request.
- The Listener routes the request to the specified Target Group.
- The Target Group delivers traffic to the ECS Task (Target).
- While the Task is the ALB's Target, additional configurations are required to route requests to a specific container within the Task:
- By setting Port Mapping in the ECS Task Definition, the ALB forwards requests to the Host Port mapped to the Task's ENI through the Target Group. The Task routes these requests to the Container Port to handle them.
Relationship Between ECS Service and ALB
- The ECS Service is a controller that manages Tasks running on an ECS Cluster (it automatically registers Tasks in the Target Group and executes them).
- ECS Service automates the process of connecting ECS Tasks to the ALB's Target Group.
- The ALB routes traffic to Tasks managed by the ECS Service.
⇒ In summary, the ECS Service registers ECS Tasks into the ALB's Target Group.
Additionally, I am planning to deploy a Spring Boot application as a container using GitHub Actions, ECS, and ALB with a canary deployment strategy. In this context, "deployment" means pushing to the main branch, which indicates that a different version is being deployed. However, I’m not sure if deploying creates a new service each time or if it simply adds a new target. This makes me unsure whether the health check should be performed on the service or on the target. Honestly, I’m a complete beginner, so I might only have theoretical knowledge without practical experience. I would really appreciate it if you could explain this to me in detail.
제가 이해한 내용이 맞는지 여쭤보고 싶습니다.
ALB와 ECS 설정 (연결) 과정
- ECS 클러스터 생성
- ECS 태스크 정의 생성
- ECS 서비스 생성
- ECS 서비스에서 생성한 태스크 정의를 선택하고, 원하는 태스크 개수 등을 설정합니다.
- ALB (Application Load Balancer) 생성
- ALB에 Listener 추가
- ALB 대상 그룹(Target Group) 생성
- 대상 유형(Target Type):
IP
또는 Instance
를 선택합니다.
- ECS 서비스와 ALB 연결
- ECS 서비스에서 Load Balancing 활성화 → ALB 선택 → 대상 그룹(Target Group) 선택 → 컨테이너 및 포트를 맵핑합니다.
- 실행 중인 **태스크(Task)**가 자동으로 ALB **대상 그룹(Target Group)**에 등록되는지 확인합니다. (ECS 태스크는 ALB의 대상(Target)이 됩니다.)
ECS 태스크와 컨테이너 간의 관계
- ECS 태스크는 하나 이상의 컨테이너를 포함하는 실행 단위입니다.
- 태스크 내 컨테이너는 동일한 네트워크 네임스페이스를 공유합니다.
- ALB의 **대상(Target)**은 ECS 태스크의 ENI 또는 IP 주소입니다.
- 따라서, 설정에 따라 **태스크 자체가 ALB의 대상(Target)**으로 등록됩니다.
- ALB는 요청을 태스크의 ENI로 전달하고, 포트를 기반으로 트래픽을 라우팅합니다.
ALB가 컨테이너로 요청을 전달하는 방법
- ALB의 Listener가 요청을 수신합니다.
- Listener는 요청을 지정된 **대상 그룹(Target Group)**으로 라우팅합니다.
- 대상 그룹은 요청을 **ECS 태스크(Target)**로 전달합니다.
- ALB의 대상은 태스크이지만, 특정 태스크 내부 컨테이너로 요청을 전달하려면 추가 설정이 필요합니다:
- ECS 태스크 정의에서 **포트 매핑(Port Mapping)**을 설정하면, ALB가 요청을 대상 그룹을 통해 태스크의 ENI에 매핑된 **호스트 포트(Host Port)**로 전달합니다. 태스크는 이 요청을 **컨테이너 포트(Container Port)**로 라우팅하여 처리합니다.
ECS 서비스와 ALB 간의 관계
- ECS 서비스는 ECS 클러스터에서 실행 중인 태스크를 관리하는 컨트롤러 역할을 합니다.
(자동으로 태스크를 대상 그룹에 등록하고 실행합니다.)
- ECS 서비스는 ECS 태스크를 ALB의 대상 그룹에 연결하는 과정을 자동화합니다.
- ALB는 ECS 서비스가 관리하는 태스크로 트래픽을 라우팅합니다.
⇒ ECS 서비스는 ECS 태스크를 ALB의 대상 그룹에 등록합니다.
추가 질문: Spring Boot 애플리케이션 배포와 관련된 내용
Spring Boot 애플리케이션을 컨테이너로 배포하고 GitHub Actions, ECS, ALB를 사용하여 카나리아 배포 전략을 구현하려고 합니다.
이 경우, “배포”는 main 브랜치로 푸시할 때 새로운 버전이 배포되는 것을 의미합니다.
다만, 배포 시마다 새로운 ECS 서비스를 생성하는 것인지, 아니면 기존 서비스에 새로운 대상을 추가하는 것인지 확신이 없습니다.
이에 따라 **헬스 체크(Health Check)**를 서비스에 수행해야 하는지, 아니면 대상(Target)에 수행해야 하는지도 불분명합니다.
솔직히 저는 초보자라 실전 경험보다는 이론에만 의존하고 있을 수도 있습니다. 자세히 설명해 주시면 정말 감사하겠습니다.