[AWS ASG] Auto Scaling Group์—์„œ EC2 Scale-in/๋ถ„๋ฆฌ ๋ฐ ASG ์‚ญ์ œํ•˜๊ธฐ (+์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •)

2022. 8. 24. 23:02ใ†AWS

๐ŸŒŽ As-Is Architecture

As-Is Architecture
์‚ฌ์šฉ์ž๊ฐ€ ALB Endpoint ์ ‘์†์‹œ ๋œจ๋Š” ํ™”๋ฉด

  • As-is Auto Scaling Group ์„ค์ • ์ƒํƒœ

  • Desired capacity: 2
  • Minimum capacity: 2
  • Maximum capacity: 2

 

โ˜„๏ธ To-Be Architecture

To-Be Architecture

  • ๋ณ€๊ฒฝ ๋ชฉํ‘œ : Auto Scale-in/out ๊ธฐ๋Šฅ ๋ฏธํ•„์š”๋กœ ์ธํ•œ Auto Scaling Group์—์„œ ์„œ๋ฒ„ ๋ถ„๋ฆฌ ๋ฐ ASG ์‚ญ์ œ

 

 


 

 

๐Ÿ”ซ Process

0. ๋ฐฑ์—…์„ ์œ„ํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ

1. ์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •

  • Auto Scaling Group ์ฝ˜์†” > Instance management ํƒญ > Actions ๋ฒ„ํŠผ > [Set scale-in protection] ์„ ํƒ

์œ„์™€ ๊ฐ™์ด Instances์˜ [Protected from] ์„ค์ •์ด Scale in์œผ๋กœ ๋ณ€๊ฒฝ๋œ๋‹ค.

๐Ÿšจ ๋ฐ˜๋“œ์‹œ ์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •์„ ํ†ตํ•ด Scale-in์ด ๋˜๋”๋ผ๋„ EC2๊ฐ€ ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•ด์•ผ๋งŒ ํ•œ๋‹ค.
Scale-out ๋˜๋Š” Subnet ์ถ”๊ฐ€ ์‹œ์—๋„ AZ๊ฐ„ ๋ฐธ๋Ÿฐ์Šค๋ฅผ ์œ„ํ•ด ๊ธฐ์กด ๋…ธ๋“œ๊ฐ€ ์‚ญ์ œ๋˜๋Š” ๊ฒฝ์šฐ ๋“ฑ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋…ธ๋“œ ์‚ญ์ œ์— ๋Œ€ํ•œ ๋ฐฉ์ง€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
๐Ÿ’ก ์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •์„ ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, EC2 ์ธ์Šคํ„ด์Šค ์ž์ฒด์— ์ข…๋ฃŒ ๋ณดํ˜ธ(termination protection) ์„ค์ •์„ ํ•œ ๊ฒฝ์šฐ๋„ ์˜ˆ์™ธ ์—†์ด ์ข…๋ฃŒ๋œ๋‹ค.

 

2. Min Capacity ๋ณ€๊ฒฝ

๐Ÿšจ ๋ฐ˜๋“œ์‹œ Min ๊ฐ’๋งŒ ๋ณ€๊ฒฝํ•œ๋‹ค.

Desired capacity๋ฅผ ์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •ํ•œ ์ธ์Šคํ„ด์Šค ์ˆ˜๋ณด๋‹ค ์ ์€ ์ˆ˜๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒฝ์šฐ, ์œ„์™€ ๊ฐ™์ด cancel ๋˜๋ฉฐ ์ œ๋Œ€๋กœ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค.

์บก์ฒ˜๋Š” 1๋ฒˆ์—์„œ 2๊ฐœ์˜ ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•ด ์ถ•์†Œ ๋ณดํ˜ธ ์„ค์ •์„ ํ•˜์˜€๋Š”๋ฐ Desired Capacity๋ฅผ 0์œผ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒฝ์šฐ์ด๋‹ค. Activity History์—์„œ Auto Scaling Group์˜ ๋ชจ๋“  activity๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

3. ASG์—์„œ ์ธ์Šคํ„ด์Šค ๋ถ„๋ฆฌ

  • Auto Scaling Group ์ฝ˜์†” > Instance management ํƒญ > Actions ๋ฒ„ํŠผ > [Detach] ์„ ํƒ

Detach ํด๋ฆญ ์‹œ, ์œ„์™€ ๊ฐ™์€ ์•Œ๋žŒ์ฐฝ์ด ๋œฌ๋‹ค.

[Add a new instance to the Auto Scaling group to balance the load(์ƒˆ ์ธ์Šคํ„ด์Šค๋ฅผ Auto Scaling ๊ทธ๋ฃน์— ์ถ”๊ฐ€ํ•˜์—ฌ ๋กœ๋“œ ๊ท ํ˜• ์œ ์ง€)]๋ฅผ default ๊ทธ๋Œ€๋กœ ๋น„ํ™œ์„ฑํ™”ํ•œ ์ƒํƒœ๋กœ, ์šฐ์ธก ํ•˜๋‹จ์˜ [Detach Instance]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

์ฒดํฌ๋ฐ•์Šค์— ์ฒดํฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์€ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ Auto Scaling Group์— ์ถ”๊ฐ€๋ฅผ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํ•ด๋‹น ์ƒํ™ฉ์—์„œ์˜ detach์˜ ์˜๋ฏธ๊ฐ€ ์—†๋‹ค.

Detach ์„ ํƒ ์‹œ, ์ธ์Šคํ„ด์Šค์˜ Lifecycle์€ Detaching์œผ๋กœ ๋ณ€๊ฒฝ๋œ๋‹ค.

 

4. ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ํƒ€๊ฒŸ ๊ทธ๋ฃน์— ์ธ์Šคํ„ด์Šค ์ถ”๊ฐ€

๐Ÿ“ข Load balancer target groups๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์€ ASG๋Š” 4๋ฒˆ ํ•ญ๋ชฉ์„ ๊ฑด๋„ˆ๋›ฐ์–ด๋„ ๋œ๋‹ค.

AWS ASG

Auto Scaling Group์ด Load Balancer์˜ Target Group๊ณผ ์—ฐ๊ฒฐ์ด ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ, ์œ„์™€ ๊ฐ™์ด Detach๋ฅผ ์‹œ๋„ํ•œ EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ์ฆ‰์‹œ ELB Target Group์—์„œ Draining ๋œ๋‹ค.

AWS Target Group

Target Group ์ฝ˜์†”์—์„œ๋„ ์œ„์™€ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋•Œ, ์‚ฌ์šฉ์ž๊ฐ€ ALB์˜ ์—”๋“œํฌ์ธํŠธ๋ฅผ ์ ‘์†ํ•˜๋Š” ๊ฒฝ์šฐ ์œ„์™€ ๊ฐ™์ด 503 ์—๋Ÿฌ๋ฅผ return ๋ฐ›๋Š”๋‹ค.

๋ณธ ํฌ์ŠคํŒ…์—์„œ๋Š” ASG ์‚ญ์ œ๋ฅผ ์›ํ•˜์ง€๋งŒ ์‚ฌ์šฉ์ž๊ฐ€ ์—ฌ์ „ํžˆ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ๋ชฉํ‘œ์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด Target Group์— ๊ธฐ์กด EC2๋ฅผ ํƒ€๊ฒŸ์œผ๋กœ ๋“ฑ๋กํ•œ๋‹ค.

๐Ÿ’ก  ๊ธฐ์กด ์„œ๋น„์Šค๋ฅผ ์ค‘๋‹จ ์‹œ๊ฐ„ ์—†์ด ๊ฐ€์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•œ ์ธ์Šคํ„ด์Šค์”ฉ ASG์—์„œ Detach ํ•˜๊ณ  Drain ๋œ ์ธ์Šคํ„ด์Šค๋ฅผ Target Group์— ๋“ฑ๋กํ•˜๋ฉด ๋œ๋‹ค.

 

5. Auto Scaling Group ์‚ญ์ œ

ASG ์ฝ˜์†”์—์„œ ๋ชจ๋‘ Detach ์™„๋ฃŒ๋˜์–ด Desired capacity๊ฐ€ 0์ด ๋์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Delete ๋ฒ„ํŠผ์„ ์ด์šฉํ•ด ASG๋ฅผ ์‚ญ์ œํ•œ๋‹ค.

⇒ ์„ฑ๊ณต~~!