☁️ Cloud
Elastic
Elastic
A cloud characteristic of automatically scaling resources up and down with demand. Cost efficiency.
Elastic
A cloud characteristic of automatically scaling resources up and down with demand. Cost efficiency.
Elastic (elasticity) is one of the core characteristics of cloud computing, referring to the ability to automatically expand (Scale Out/Up) or reduce (Scale In/Down) computing resources according to workload demand. This makes it possible to optimize costs while maintaining performance.
Two approaches to elasticity:
Services that implement elasticity in the cloud:
When "Elastic" appears in an AWS service name (EC2, ELB, EBS, EKS, etc.), it means the service offers this elasticity as a core characteristic.
# AWS Auto Scaling Group 생성
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-template LaunchTemplateId=lt-0123456789abcdef0 \
--min-size 2 \
--max-size 10 \
--desired-capacity 3 \
--vpc-zone-identifier "subnet-1234,subnet-5678" \
--target-group-arns arn:aws:elasticloadbalancing:region:account:targetgroup/my-tg/xxx
# CPU 기반 Target Tracking 정책 (자동 Scale In/Out)
aws autoscaling put-scaling-policy \
--auto-scaling-group-name my-asg \
--policy-name cpu-target-tracking \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ASGAverageCPUUtilization"
},
"TargetValue": 50.0
}'
# 예약 스케일링 (야간 축소)
aws autoscaling put-scheduled-action \
--auto-scaling-group-name my-asg \
--scheduled-action-name scale-down-night \
--recurrence "0 22 * * *" \
--min-size 1 \
--max-size 2 \
--desired-capacity 1
# 주간 확장
aws autoscaling put-scheduled-action \
--auto-scaling-group-name my-asg \
--scheduled-action-name scale-up-day \
--recurrence "0 8 * * 1-5" \
--min-size 2 \
--max-size 10 \
--desired-capacity 3
# DynamoDB 테이블 자동 스케일링
aws application-autoscaling register-scalable-target \
--service-namespace dynamodb \
--resource-id "table/my-table" \
--scalable-dimension "dynamodb:table:ReadCapacityUnits" \
--min-capacity 5 \
--max-capacity 100
# Kubernetes Horizontal Pod Autoscaler (HPA)
# CPU 기반 자동 스케일링
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 20
metrics:
# CPU 50% 기준
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
# 메모리 70% 기준
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
behavior:
# 빠른 Scale Up
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15
# 느린 Scale Down (안정성)
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
---
# Vertical Pod Autoscaler (VPA) - 리소스 요청량 자동 조정
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-app-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
updatePolicy:
updateMode: "Auto" # 자동 Pod 재시작하며 조정
resourcePolicy:
containerPolicies:
- containerName: "*"
minAllowed:
cpu: 100m
memory: 128Mi
maxAllowed:
cpu: 4
memory: 8Gi
---
# KEDA - 이벤트 기반 스케일링 (Kafka, SQS 등)
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: kafka-consumer-scaler
spec:
scaleTargetRef:
name: kafka-consumer
minReplicaCount: 1
maxReplicaCount: 50
triggers:
- type: kafka
metadata:
bootstrapServers: kafka:9092
consumerGroup: my-group
topic: my-topic
lagThreshold: "100" # 메시지 지연 100개당 스케일
# Terraform으로 탄력적 인프라 구성
# Auto Scaling Group
resource "aws_autoscaling_group" "web" {
name = "web-asg"
vpc_zone_identifier = var.private_subnets
target_group_arns = [aws_lb_target_group.web.arn]
min_size = 2
max_size = 20
desired_capacity = 3
# 혼합 인스턴스 정책 (온디맨드 + 스팟)
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 2 # 최소 2개 온디맨드
on_demand_percentage_above_base_capacity = 25 # 나머지 25% 온디맨드
spot_allocation_strategy = "capacity-optimized"
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.web.id
version = "$Latest"
}
override {
instance_type = "t3.medium"
}
override {
instance_type = "t3a.medium"
}
override {
instance_type = "m5.large"
}
}
}
# 인스턴스 새로고침 (무중단 배포)
instance_refresh {
strategy = "Rolling"
preferences {
min_healthy_percentage = 75
}
}
}
# Target Tracking 스케일링 정책
resource "aws_autoscaling_policy" "cpu_policy" {
name = "cpu-target-tracking"
autoscaling_group_name = aws_autoscaling_group.web.name
policy_type = "TargetTrackingScaling"
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
target_value = 50.0
}
}
# 예약 스케일링 (비용 최적화)
resource "aws_autoscaling_schedule" "night" {
scheduled_action_name = "scale-down-night"
autoscaling_group_name = aws_autoscaling_group.web.name
min_size = 1
max_size = 5
desired_capacity = 2
recurrence = "0 22 * * *" # 매일 22시
}
# Aurora Serverless v2 (자동 용량 조절)
resource "aws_rds_cluster" "aurora" {
cluster_identifier = "my-aurora"
engine = "aurora-mysql"
engine_mode = "provisioned"
serverlessv2_scaling_configuration {
min_capacity = 0.5 # 최소 0.5 ACU
max_capacity = 64 # 최대 64 ACU
}
}
# DynamoDB 자동 스케일링
resource "aws_appautoscaling_target" "dynamodb_read" {
max_capacity = 100
min_capacity = 5
resource_id = "table/${aws_dynamodb_table.main.name}"
scalable_dimension = "dynamodb:table:ReadCapacityUnits"
service_namespace = "dynamodb"
}
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free