-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
20250207/aws ecs 김진우 기술블로그 제출 #120
Open
KJU3
wants to merge
1
commit into
main
Choose a base branch
from
20250207/amazon-ecs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
layout: post | ||
title: "Amazon ECS(Elastic Container Service)을 활용한 운영 환경 구성" | ||
author: "김진우" | ||
categories: "백엔드 기술블로그" | ||
banner: | ||
background: "#000" | ||
height: "100vh" | ||
min_height: "38vh" | ||
heading_style: "font-size: 4.25em; font-weight: bold; text-decoration: underline" | ||
tags: ["AWS", "ECS", "ECR", "Docker", "CI/CD", "Jenkins"] | ||
--- | ||
|
||
# Amazon ECS를 활용한 무중단 배포 파이프라인 구축 | ||
|
||
저희는 운영 환경에 **Amazon ECS(Amazon Elastic Container Service)**를 도입하여 컨테이너 오케스트레이션을 활용하고 있습니다. 또한, **GitHub와 Jenkins를 연동**하여 CI/CD 파이프라인을 구축함으로써 효율적인 배포 환경을 구성했습니다. | ||
|
||
이 글에서는 **GitHub에서 메인 브랜치에 코드가 머지되었을 때 ECS가 최신 이미지를 자동으로 가져와 롤링 업데이트 방식으로 무중단 배포되는 과정**을 설명합니다. | ||
|
||
--- | ||
|
||
## 1. ECS 기반 CI/CD 파이프라인 개요 | ||
|
||
### 🔹 전체 배포 흐름 | ||
|
||
1. **GitHub에서 코드가 메인 브랜치에 머지**되면 Jenkins가 파이프라인을 실행합니다. | ||
2. Jenkins에서 **Docker로 애플리케이션을 빌드**합니다. | ||
3. 빌드된 Docker 이미지를 **Amazon Elastic Container Registry(ECR)**에 Push합니다. | ||
4. ECS는 **ECR에 등록된 최신 이미지를 가져와 실행**합니다. | ||
5. **Application Load Balancer(ALB)를 이용해 롤링 업데이트 방식으로 무중단 배포**를 진행합니다. | ||
|
||
--- | ||
|
||
## 2. Jenkins와 ECS를 활용한 배포 과정 | ||
|
||
### 🏗 1. Docker로 애플리케이션 빌드 | ||
```sh | ||
# Jenkins에서 실행될 Docker 빌드 명령어 | ||
docker build -t my-app:latest . | ||
``` | ||
|
||
### 📌 2. ECR에 Docker 이미지 Push | ||
```sh | ||
# AWS ECR 로그인 (Jenkins에서 수행) | ||
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.ap-northeast-2.amazonaws.com | ||
|
||
# ECR에 태그 및 Push | ||
docker tag my-app:latest <AWS_ACCOUNT_ID>.dkr.ecr.ap-northeast-2.amazonaws.com/my-app:latest | ||
docker push <AWS_ACCOUNT_ID>.dkr.ecr.ap-northeast-2.amazonaws.com/my-app:latest | ||
``` | ||
|
||
### 🚀 3. ECS에서 최신 이미지 가져오기 | ||
ECS 서비스는 태스크 정의(Task Definition)의 컨테이너 이미지를 **ECR에서 가져와 업데이트**합니다. | ||
```sh | ||
aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment | ||
``` | ||
|
||
### 🔄 4. 롤링 업데이트를 통한 무중단 배포 | ||
ECS는 **ALB(Application Load Balancer)**를 활용하여 트래픽을 점진적으로 신규 컨테이너로 전환하는 **롤링 업데이트(Rolling Update)** 방식으로 무중단 배포를 수행합니다. | ||
- 새로운 컨테이너가 실행되면 ALB는 헬스 체크(Health Check)를 수행합니다. | ||
- 정상 상태가 확인되면 기존 컨테이너에서 새로운 컨테이너로 트래픽을 이동합니다. | ||
- 기존 컨테이너는 종료됩니다. | ||
|
||
```sh | ||
# ECS 서비스 업데이트 | ||
aws ecs update-service --cluster my-cluster --service my-service --desired-count 2 | ||
``` | ||
|
||
--- | ||
|
||
## 3. ECS CI/CD 파이프라인 구성의 장점 | ||
|
||
### ✅ 자동화된 배포 | ||
GitHub, Jenkins, ECS, ECR을 연동하여 **CI/CD 파이프라인을 구축**함으로써 코드 변경 사항이 자동으로 배포됩니다. | ||
|
||
### ✅ 무중단 배포 | ||
ALB와 롤링 업데이트를 활용하여 **배포 중에도 애플리케이션이 정상 동작**합니다. | ||
|
||
### ✅ 효율적인 리소스 관리 | ||
Fargate 기반 ECS를 사용하면 **서버 관리 없이 컨테이너 실행**이 가능하며, EC2 기반 ECS를 사용하면 **비용 최적화 및 유연한 확장**이 가능합니다. | ||
Comment on lines
+71
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ECS CI/CD 파이프라인 구성의 장점과 더불어 단점도 소개하면 좋을 것 같습니다(EKS와의 비교). 특히 Fargate 기반 ECS같은 경우에는 서버리스의 장점이 있긴하지만 비용 때문에 현업에서 활용을 안하는 곳도 많습니다. |
||
|
||
--- | ||
|
||
## 4. 결론 | ||
|
||
Amazon ECS와 CI/CD 파이프라인을 활용하면 **자동화된 컨테이너 배포 환경을 구축**할 수 있습니다. 특히 **GitHub, Jenkins, ECR, ECS, ALB를 조합**하면 코드 변경 사항을 신속하고 안전하게 배포할 수 있습니다. | ||
|
||
현재 운영 중인 환경에서 **배포 자동화를 고민하고 있다면, 무중단 배포가 가능한 롤링 업데이트 방식의 CI/CD 파이프라인을 구축**하는 것을 추천드립니다. | ||
|
||
> **🔎 참고**: Amazon ECS 공식 문서를 확인하려면 [AWS ECS 공식 문서](https://docs.aws.amazon.com/ecs/)를 참고하세요. | ||
|
||
--- | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
롤백 전략은 구축하셨죠?
배포상 문제가 발생했을 때 롤백 프로세스를 어떻게 구축했는지 포함하면 좋을 것 같습니다.