Fargate Pod 라이프사이클
문서 도구
Fargate Pod 라이프사이클 특수 고려사항
AWS Fargate는 서버리스 컴퓨팅 엔진으로, 노드 관리 없이 Pod을 실행합니다. Fargate Pod은 EC2 기반 Pod과 다른 라이프사이클 특성을 가집니다.
Fargate vs EC2 vs Auto Mode 아키텍처 비교
Fargate Pod OS 패치 자동 Eviction
Fargate는 보안 패치를 위해 주기적으로 Pod을 자동 evict합니다.
동작 방식:
- 패치 가용성 감지: AWS가 새로운 OS/런타임 패치 감지
- Graceful Eviction: Fargate가 Pod에 SIGTERM 전송 →
terminationGracePeriodSeconds내에 종료 대기 - 강제 종료: Timeout 시 SIGKILL 전송
- 재스케줄링: Kubernetes가 새로운 Fargate Pod에 재스케줄링 (업데이트된 런타임 사용)
주요 특징:
- 예측 불가능한 타이밍: 사용자가 제어할 수 없음 (AWS 관리)
- 사전 알림 없음: EC2 Scheduled Events와 달리 사전 경고 없음
- 자동 재시작: PodDisruptionBudget(PDB) 존중하지만, 보안 패치는 우선순위 높음
대응 전략:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fargate-app
namespace: fargate-namespace
spec:
replicas: 3 # 최소 3개 이상 권장 (자동 eviction 대비)
selector:
matchLabels:
app: fargate-app
template:
metadata:
labels:
app: fargate-app
spec:
containers:
- name: app
image: myapp:v1
resources:
requests:
cpu: 500m
memory: 1Gi
startupProbe:
httpGet:
path: /healthz
port: 8080
failureThreshold: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- sleep 10 # Fargate eviction 대비 더 긴 대기
# Fargate는 시작 시간이 길 수 있음
terminationGracePeriodSeconds: 60
---
# PDB로 동시 eviction 제한 (최선 노력, 보안 패치 시 무시될 수 있음)
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: fargate-app-pdb
namespace: fargate-namespace
spec:
minAvailable: 2
selector:
matchLabels:
app: fargate-app
Fargate는 PDB를 최선 노력(best effort) 으로만 존중합니다. 중요한 보안 패치의 경우 PDB를 무시하고 강제 eviction할 수 있습니다. 따라서 Fargate 환경에서는 최소 3개 이상의 replica로 고가용성을 보 장해야 합니다.
Fargate Pod 시작 시간 특성
Fargate Pod은 EC2 기반 Pod보다 시작 시간이 깁니다.
| 단계 | EC2 (Managed Node) | Fargate | 이유 |
|---|---|---|---|
| 노드 프로비저닝 | 0초 (이미 실행 중) | 20-40초 | MicroVM 생성 + ENI 연결 |
| 이미지 풀 | 5-30초 | 10-60초 | 레이어 캐시 없음 (첫 실행 시) |
| 컨테이너 시작 | 1-5초 | 1-5초 | 동일 |
| 총 시작 시간 | 6-35초 | 31-105초 | Fargate 오버헤드 추가 |
Startup Probe 조정 예시:
# EC2 Pod
startupProbe:
httpGet:
path: /healthz
port: 8080
failureThreshold: 6 # 6 × 5초 = 30초
periodSeconds: 5
# Fargate Pod (더 긴 시간 허용)
startupProbe:
httpGet:
path: /healthz
port: 8080
failureThreshold: 20 # 20 × 5초 = 100초
periodSeconds: 5
이미지 풀 최적화 (Fargate):
apiVersion: v1
kind: Pod
metadata:
name: fargate-pod
namespace: fargate-namespace
spec:
containers:
- name: app
image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
imagePullPolicy: IfNotPresent # Always 대신 IfNotPresent 권장
imagePullSecrets:
- name: ecr-secret
Fargate는 동일 이미지를 반복 사용 시 레이어 캐싱을 수행하지만, Pod이 evict되면 캐시가 사라집니다. ECR Image Scanning과 Image Replication을 활용하여 이미지 풀 시간을 단축하세요.
Fargate DaemonSet 미지원으로 인한 사이드카 패턴
Fargate는 DaemonSet을 지원하지 않으므로, 노드 레벨 에이전트가 필요한 경우 사이드카 패턴을 사용해야 합니다.
EC2 vs Fargate 모니터링 패턴 비교:
| 기능 | EC2 (DaemonSet) | Fargate (Sidecar) |
|---|---|---|
| 로그 수집 | Fluent Bit DaemonSet | Fluent Bit Sidecar + FireLens |
| 메트릭 수집 | CloudWatch Agent DaemonSet | CloudWatch Agent Sidecar |
| 보안 스캔 | Falco DaemonSet | Fargate는 AWS 관리 (사용자 제어 불가) |
| 네트워크 정책 | Calico/Cilium DaemonSet | NetworkPolicy 미지원 (Security Groups for Pods 사용) |
Fargate 로깅 패턴 (FireLens):
apiVersion: apps/v1
kind: Deployment
metadata:
name: fargate-logging-app
namespace: fargate-namespace
spec:
replicas: 2
selector:
matchLabels:
app: logging-app
template:
metadata:
labels:
app: logging-app
spec:
containers:
# 메인 애플리케이션
- name: app
image: myapp:v1
ports:
- containerPort: 8080
resources:
requests:
cpu: 500m
memory: 512Mi
# FireLens 로그 라우터 (사이드카)
- name: log-router
image: public.ecr.aws/aws-observability/aws-for-fluent-bit:stable
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 256Mi
env:
- name: FLB_LOG_LEVEL
value: "info"
firelensConfiguration:
type: fluentbit
options:
enable-ecs-log-metadata: "true"
Fargate는 CloudWatch Container Insights를 네이티브 지원하며, 별도 사이드카 없이 메트릭을 자동 수집합니다. Fargate 프로파일 생성 시 자동으로 활성화됩니다.
aws eks create-fargate-profile \
--cluster-name my-cluster \
--fargate-profile-name my-profile \
--pod-execution-role-arn arn:aws:iam::123456789012:role/FargatePodExecutionRole \
--selectors namespace=fargate-namespace \
--tags 'EnableContainerInsights=enabled'
Fargate Graceful Shutdown 타이밍 권장사항
Fargate는 자동 eviction 및 긴 시작 시간으로 인해 EC2와 다른 Graceful Shutdown 전략이 필요합니다.
| 시나리오 | terminationGracePeriodSeconds | preStop sleep | 이유 |
|---|---|---|---|
| EC2 Pod | 30-60초 | 5초 | Endpoints 제거 대기 |
| Fargate Pod (일반) | 60-90초 | 10-15초 | 더 긴 네트워크 전파 시간 |
| Fargate + ALB | 90-120초 | 15-20초 | ALB deregistration delay 고려 |
| Fargate 장기 작업 | 120-300초 | 10초 | 배치 작업 완료 시간 확보 |
Fargate 최적화 예시:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fargate-web-app
namespace: fargate-namespace
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: app
image: myapp:v1
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5
failureThreshold: 3
successThreshold: 1
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
# Fargate는 네트워크 전파가 느릴 수 있음
echo "PreStop: Waiting for network propagation..."
sleep 15
# Readiness 실패 신호 (선택 사항)
# curl -X POST http://localhost:8080/shutdown
echo "PreStop: Graceful shutdown initiated"
terminationGracePeriodSeconds: 90 # EC2는 60초, Fargate는 90초
Fargate vs EC2 vs Auto Mode 비교표: Probe 관점
| 항목 | EC2 Managed Node Group | Fargate | EKS Auto Mode |
|---|---|---|---|
| 노드 관리 | 사용자 관리 | AWS 관리 | AWS 관리 |
| Pod 밀도 | 높음 (여러 Pod/노드) | 낮음 (1 Pod = 1 MicroVM) | 중간 (AWS 최적화) |
| 시작 시간 | 빠름 (5-35초) | 느림 (30-105초) | 빠름 (10-40초) |
| Startup Probe failureThreshold | 6-10 | 15-20 | 8-12 |
| terminationGracePeriodSeconds | 30-60초 | 60-120초 | 30-60초 |
| preStop sleep | 5초 | 10-15초 | 5-10초 |
| 자동 OS 패치 | 수동 (AMI 업데이트) | 자동 (예측 불가 eviction) | 자동 (계획된 eviction) |
| PDB 지원 | 완전 지원 | 제한적 (최선 노력) | 완전 지원 |
| DaemonSet 지원 | 완전 지원 | 미지원 (사이드카 필요) | 제한적 (AWS 관리) |
| 비용 모델 | 인스턴스당 (항상 실행) | Pod당 (실행 시간만) | Pod당 (최적화됨) |
| Spot 지원 | 완전 지원 (Termination Handler) | Fargate Spot 제한적 | 자동 최적화 |
| 네트워크 정책 | Calico/Cilium 지원 | Security Groups for Pods만 | AWS 관 리 네트워크 정책 |
선택 가이드:
- Replica 수: 최소 3개 이상 (자동 eviction 대비)
- Startup Probe: failureThreshold 15-20 설정 (긴 시작 시간 고려)
- terminationGracePeriodSeconds: 60-120초 설정
- preStop sleep: 10-15초 설정 (네트워크 전파 대기)
- PDB: minAvailable 설정 (최선 노력이지만 권장)
- 이미지 최적화: ECR 사용, 레이어 최소화
- 로깅: FireLens 사이드카 또는 CloudWatch Logs 통합
- 모니터링: CloudWatch Container Insights 활성화
- 비용 최적화: Fargate Spot 검토 (장애 허용 워크로드)