Bỏ qua tới nội dung
CloudDojo
Phần 5/7 · 7 phút

Termination policy khi scale in

0/1
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

Khi tải giảm, Auto Scaling group scale in; instance bị terminate trước được chọn theo một thứ tự cố định, có thể dự đoán được.

Sau đợt khuyến mãi, ASG thực hiện scale in. Với default termination policy, ASG đánh giá theo một thứ tự cố định. Chọn kịch bản, dự đoán instance bị terminate, sau đó quan sát từng bước.

Kịch bản
AZ-A
AZ-B

ASG chuẩn bị scale in 1 instance. Chọn instance dự đoán sẽ bị terminate, sau đó quan sát từng bước đánh giá của ASG.

Xem đội xây chọn nhà máy nào để dỡ khi scale in: khu đông nhất, cấu hình cũ nhất, rồi giờ tính phí.

Kịch bản thứ hai có thêm lựa chọn loại cấu hình của nhóm. Với nhóm dùng launch template, mọi instance còn chạy bằng launch configuration đều bị xem là lỗi thời và được xét trước (B và C), sau đó mới tới tiêu chí giờ tính phí. Với nhóm dùng launch configuration, ASG chọn instance dùng launch configuration cũ nhất (B). Launch configuration là cơ chế cũ: từ 01/01/2023 không hỗ trợ instance type mới, account tạo từ 01/10/2024 không tạo được launch configuration mới bằng bất kỳ cách nào, và AWS khuyến nghị chuyển sang launch template.

Kịch bản thứ ba dùng instance scale-in protection: instance được bảo vệ không bị chọn khi scale in. Có thể bật cho cả nhóm (instance mới kế thừa thiết lập) hoặc cho từng instance. Scale-in protection không bảo vệ instance khỏi health check replacement, Spot interruption hay thao tác terminate thủ công. Khi kỹ sư cần log của một instance đã bị scale in, giải pháp bền vững là gửi log ra CloudWatch Logs bằng CloudWatch agent (bài Monitoring), không phải giữ instance lại.

Ghi nhớ:
  • Thứ tự mặc định: AZ có nhiều instance nhất → instance dùng cấu hình lỗi thời (nhóm dùng launch template: launch configuration trước, sau đó launch template khác template hiện tại, rồi phiên bản cũ nhất của template hiện tại; nhóm dùng launch configuration: launch configuration cũ nhất) → nếu còn nhiều instance: gần giờ tính phí tiếp theo nhất (AWS lưu ý tiêu chí này ít tác dụng vì phần lớn EC2 tính phí theo giây).
  • ASG cũng tự động cân bằng lại giữa các AZ và thay thế instance unhealthy.
Part 5/7 · 7 phút

Termination policies for scale in

0/1
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

When load falls, the Auto Scaling group scales in; the instance terminated first is chosen in a fixed, predictable order.

After the sale, the ASG scales in. With the default termination policy, the ASG evaluates in a fixed order. Pick a scenario, predict which instance will be terminated, then follow each step.

Kịch bản
AZ-A
AZ-B

ASG chuẩn bị scale in 1 instance. Chọn instance dự đoán sẽ bị terminate, sau đó quan sát từng bước đánh giá của ASG.

Xem đội xây chọn nhà máy nào để dỡ khi scale in: khu đông nhất, cấu hình cũ nhất, rồi giờ tính phí.

The second scenario adds a choice of how the group is configured. In a group that uses a launch template, every instance still running from a launch configuration counts as outdated and is considered first (B and C), and only then the billing-hour criterion applies. In a group that uses a launch configuration, the ASG picks the instances with the oldest launch configuration (B). Launch configurations are legacy: since January 1, 2023 they do not support new instance types, accounts created on or after October 1, 2024 cannot create new launch configurations by any method, and AWS recommends migrating to launch templates.

The third scenario uses instance scale-in protection: a protected instance is not selected on scale in. It can be enabled for the whole group (new instances inherit the setting) or for individual instances. Scale-in protection does not protect an instance from health check replacement, Spot interruptions or manual termination. When engineers need the logs of an instance that was scaled in, the durable solution is to ship logs to CloudWatch Logs with the CloudWatch agent (Monitoring lesson), not to keep the instance around.

Ghi nhớ:
  • Default order: the AZ with the most instances → instances with an outdated configuration (group with a launch template: launch configuration first, then a launch template other than the current one, then the oldest version of the current template; group with a launch configuration: the oldest launch configuration) → if several instances remain: the one closest to the next billing hour (AWS notes this criterion has little effect because most EC2 usage is billed per second).
  • The ASG also automatically rebalances across AZs and replaces unhealthy instances.

Kiểm tra nhanh

Trả lời để ghi nhận đã đọc phần này. Câu trả lời sai sẽ được nhắc ôn lại vào những ngày sau.

ASG dùng launch template, default termination policy. AZ-A có 2 instance, AZ-B có 3 instance; ở AZ-B một instance còn chạy bằng launch configuration. Instance nào bị terminate trước khi scale in?
Một instance đã bật instance scale-in protection. Trong trường hợp nào instance đó vẫn có thể bị terminate?

Đã trả lời 0/2 câu