01. ECS Service Auto Scaling

ECS ์„œ๋น„์Šค ์˜คํ† ์Šค์ผ€์ผ๋ง์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž.

  • ECS Task ์ˆ˜๋ฅผ ์ˆ˜๋™์œผ๋กœ ๋Š˜๋ฆด์ˆ˜๋„์žˆ์ง€๋งŒ, ์ž๋™์œผ๋กœ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜ ์ค„์ผ์ˆ˜๋„ ์žˆ๋‹ค.
  • AWS ์˜ Auto Scaling ์ด๋ผ๋Š” ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด 3๊ฐ€์ง€ ์ง€ํ‘œ์— ๋Œ€ํ•ด ํ™•์žฅ์ด ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.
    • ํ‰๊ท  CPU ์‚ฌ์šฉ๋ฅ 
    • ํ‰๊ท  ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋ฅ  (RAM)
    • ALB ๊ด€๋ จ ์ง€ํ‘œ์ธ ํƒ€๊ฒŸ๋‹น ์š”์ฒญ ์ˆ˜ (request count)
  • Target Tracking: ํŠน์ • ํƒ€๊ฒŸ์„ ์ถ”์ ํ•˜๋Š” ๋Œ€์ƒ์ถ”์  ์Šค์ผ€์ผ๋ง
  • Step Scaling: ํŠน์ • CloudWatch ์•Œ๋žŒ์— ๋”ฐ๋ผ ์Šค์ผ€์ผ๋ง
  • Scheduled Scaling: ๋ฏธ๋ฆฌ ECS ์„œ๋น„์Šค ํ™•์žฅ์„ ์„ค์ •ํ•˜๋Š” ์˜ˆ์•ฝ ์Šค์ผ€์ผ๋ง

  • ECS Service Auto Scaling (Task Level) != EC2 Auto Scaling (EC2 Instance Level)
    • ECS ์˜คํ†  ์Šค์ผ€์ผ๋ง๊ณผ EC2 ์˜คํ†  ์Šค์ผ€์ผ๋ง์€ ์„œ๋กœ ๋‹ค๋ฅด๋‹ค. (์‹œ์ž‘์œ ํ˜•์ด EC2 ์ธ์Šคํ„ด์Šค์ผ๋•Œ) LaunchType
      • Task(Process) ๋ ˆ๋ฒจ์ด๋ƒ, EC2 ์ธ์Šคํ„ด์Šค ๋ ˆ๋ฒจ์ด๋ƒ์˜ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.
  • Fargate ์‹œ์ž‘์œ ํ˜•์˜ Auto Scaling ์ด ๋”์šฑ ์„ธํŒ…ํ•˜๊ธฐ๊ฐ€ ์‰ฝ๋‹ค. (์„œ๋ฒ„๋ฆฌ์Šค ์ด๊ธฐ ๋•Œ๋ฌธ)
    • ์‹œํ—˜์—์„œ๋„ Fargate ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•œ๋‹ค.




02. EC2 LaunchType - Auto Scaling EC2 Instances

EC2 ์‹œ์ž‘์œ ํ˜•์—์„œ๋Š” ๋ฐฑ์—”๋“œ์˜ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์–ด๋–ป๊ฒŒ ์ž๋™์œผ๋กœ ํ™•์žฅํ•˜๋Š”๊ฐ€

์Šค์ผ€์ผ๋ง์—๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”๋ฐ, ๊ทธ ์ค‘ ํ•˜๋‚˜๊ฐ€ ์˜คํ†  ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน(ASG) ์ด๋‹ค.

  • Auto Scaling Group Scaling
    • CPU ์‚ฌ์šฉ๋Ÿ‰์— ๋”ฐ๋ผ ASG ๊ทธ๋ฃน์„ ์Šค์ผ€์ผ๋ง ํ•œ๋‹ค.
    • CPU ์‚ฌ์šฉ๋ฅ ์ด ๊ธ‰๋“ฑํ•  ๋•Œ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ECS Cluster Capacity Provider (๋” ์ตœ์‹ ๊ธฐ๋Šฅ)
    • ECS ํด๋Ÿฌ์Šคํ„ฐ ์šฉ๋Ÿ‰ ๊ณต๊ธ‰์ž๋ฅผ ์‚ฌ์šฉํ•˜์ž. ์•„์ฃผ ๋˜‘๋˜‘ํ•œ ์„œ๋น„์Šค์ด๋‹ค.
    • ์ƒˆ Task ๋ฅผ ์‹คํ–‰ํ•  ์šฉ๋Ÿ‰์ด ๋ถ€์กฑํ•˜๋ฉด ์ž๋™์œผ๋กœ ASG๋ฅผ ํ™•์žฅํ•œ๋‹ค.
    • Capacity Provider ๋Š” ASG ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ๋œ๋‹ค.
    • RAM or CPU ๊ฐ€ ๋ชจ์ž๋ž„ ๋•Œ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

ASG ์™€ ECS Cluster Provider ์ค‘์— LaunchType์ด EC2 ์ธ ๊ฒฝ์šฐ์—๋Š” EC2 ECS Cluster Provider ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ๊ถŒ์žฅํ•œ๋‹ค.




03. CPU Usage Example

์œ„์— ๋ฐฐ์šด ์„œ๋น„์Šค ์˜ˆ์‹œ๋ฅผ ์‚ดํŽด๋ณด์ž

image-20221124010602894

  • ์„œ๋น„์Šค A ์— Task ๊ฐ€ 2๊ฐœ ์‹คํ–‰์ค‘์ด์—ˆ์œผ๋ฉฐ, CPU ์‚ฌ์šฉ๋Ÿ‰์€ ์ดˆ๋ก์ƒ‰ ์ƒํƒœ์ด๋‹ค.
  • ์ด ์„œ๋น„์Šค๋Š” AWS Application Auto Scaling ์œผ๋กœ ์ž๋™ํ™•์žฅ๋œ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ๋งŽ์•„์ ธ์„œ CPU ์‚ฌ์šฉ๋Ÿ‰์ด ๊ธ‰์ฆํ•˜๋ฉด ECS Service Level ์—์„œ CPU ์‚ฌ์šฉ๋Ÿ‰์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋Š” CloudWatch ์ง€ํ‘œ๊ฐ€ CloudWatch Alarm์„ Trigger ํ•œ๋‹ค.
  • ์ด ์•Œ๋žŒ์ด Auto Scaling์„ ๋˜ Tigger ํ•˜๋ฉด ECS ์„œ๋น„์Šค์˜ ํฌ๋ง์šฉ๋Ÿ‰์ด ์ฆ๊ฐ€ํ•˜๊ณ , ์ƒˆ Task ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

  • ๋˜ํ•œ, LaunchType์ด EC2 ๋ผ๋ฉด, (fargate๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด) EC2 ์šฉ๋Ÿ‰ ๊ณต๊ธ‰์ž๊ฐ€ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด ECS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ํ™•์žฅํ•˜๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค.

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ