Scaling
스케일링
시스템 용량 조절. 수직(더 큰 서버), 수평(더 많은 서버).
스케일링
시스템 용량 조절. 수직(더 큰 서버), 수평(더 많은 서버).
Scaling(스케일링)은 시스템의 처리 용량을 조절하여 변화하는 부하에 대응하는 것입니다. 크게 수직 스케일링(Vertical Scaling, Scale-Up)과 수평 스케일링(Horizontal Scaling, Scale-Out) 두 가지 방식이 있습니다.
수직 스케일링은 단일 서버의 CPU, 메모리, 스토리지를 증가시키는 방식으로, 간단하지만 물리적 한계가 있습니다. 수평 스케일링은 서버 인스턴스 수를 늘리는 방식으로, 이론상 무한한 확장이 가능하지만 애플리케이션이 분산 환경에 적합하게 설계되어야 합니다. 클라우드 환경에서는 Auto Scaling을 통해 트래픽에 따라 자동으로 인스턴스를 조절하여 비용 효율성과 성능을 동시에 확보합니다.
# hpa.yaml - CPU/메모리 기반 자동 스케일링
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-server-hpa
namespace: production
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-server
minReplicas: 3
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
- type: Pods
pods:
metric:
name: http_requests_per_second
target:
type: AverageValue
averageValue: "1000"
behavior:
scaleDown:
stabilizationWindowSeconds: 300 # 5분간 안정화
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15
- type: Pods
value: 4
periodSeconds: 15
selectPolicy: Max
# autoscaling.tf
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 = 10
desired_capacity = 3
health_check_type = "ELB"
health_check_grace_period = 300
launch_template {
id = aws_launch_template.web.id
version = "$Latest"
}
tag {
key = "Name"
value = "web-server"
propagate_at_launch = true
}
}
resource "aws_autoscaling_policy" "scale_out" {
name = "scale-out"
autoscaling_group_name = aws_autoscaling_group.web.name
adjustment_type = "ChangeInCapacity"
scaling_adjustment = 2
cooldown = 300
}
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
alarm_name = "high-cpu-utilization"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 70
alarm_actions = [aws_autoscaling_policy.scale_out.arn]
dimensions = {
AutoScalingGroupName = aws_autoscaling_group.web.name
}
}