๐Ÿค” ์ ์šฉ ์ด์œ 

AutoScaling, LoadBalancer

EB๋ฅผ ์‚ฌ์šฉํ•ด๋ณธ ์ ์€ ์—†์œผ๋‚˜ ์‚ฌ์šฉ์œจ์ด ์ฆ๊ฐ€ํ•˜๋ฉด scale out ํ–ˆ๋‹ค๊ฐ€, ๋‹ค์‹œ ์ค„์–ด๋“ค๋ฉด scale in ์„ ํ•  ์ˆ˜ ์žˆ๋Š” AutoScaling Group๊ณผ ์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋ฅผ ๋‚˜๋ˆ„์–ด ์ฃผ๋Š” LoadBalancer๋ฅผ ๊ฐ„ํŽธํ•˜๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ ์ด ์žฅ์ ์œผ๋กœ ๋Š๊ปด์กŒ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์—ฌ๋Ÿฌ ์žฅ์ ์€ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ์ „์—๋Š” ์™€๋‹ฟ์ง€ ์•Š์•„์„œ โ€˜์‚ฌ์šฉํ•ด๋ณด๊ณ  ๋Š๊ปด๋ณด์žโ€™ ํ•ด์„œ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.


โš™๏ธ ์„ค์ • ๋ฐฉ๋ฒ•

1. IAM ์—ญํ•  ์ถ”๊ฐ€

Elastic beanstalk(์ดํ•˜ EB) ์˜ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ ์—ญํ• ์— ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

1.1 ์„œ๋น„์Šค ์—ญํ• 

EB๋ฅผ ์„œ๋น„์Šค๋กœ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ๋‹ด๋‹นํ•  IAM ์—ญํ• ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค. Elastic Beanstalk ์„œ๋น„์Šค ์—ญํ•  ๊ด€๋ฆฌ

์„ค์ •ํ•˜์ง€ ์•Š์„ ์‹œ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค..

Configuration validation exception: Invalid option specification (Namespace: โ€˜aws:elasticbeanstalk:managedactionsโ€™, OptionName: โ€˜ManagedActionsEnabledโ€™): You canโ€™t enable managed platform updates when your environment uses the service-linked role โ€˜AWSServiceRoleForElasticBeanstalkโ€™. Select a service role that has the โ€˜AWSElasticBeanstalkManagedUpdatesCustomerRolePolicyโ€™ managed policy.


1.2 EC2 ์ธ์Šคํ„ด์Šค ํ”„๋กœํŒŒ์ผ

EB ํ™˜๊ฒฝ ๊ตฌ์„ฑ์ด ์™„๋ฃŒ๋˜๋ฉด EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด IAM ์—ญํ• ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. Elastic Beanstalk ์ธ์Šคํ„ด์Šค ํ”„๋กœํŒŒ์ผ ๊ด€๋ฆฌ


2. ํ™˜๊ฒฝ ๊ตฌ์„ฑ

Elastic Beanstalk ํ™˜๊ฒฝ ๊ตฌ์„ฑ


ํ™˜๊ฒฝ ํ‹ฐ์–ด: ์›น ์„œ๋ฒ„ ํ™˜๊ฒฝ ์„ ํƒ ์‹œ Http ์š”์ฒญ์„ ์ฒ˜๋ฆฌ ํ•ฉ๋‹ˆ๋‹ค.
ํ™˜๊ฒฝ ์ •๋ณด - ํ™˜๊ฒฝ ์ด๋ฆ„: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„ + [-env] ํ˜•์‹์œผ๋กœ ์ž๋™ ์™„์„ฑ๋ฉ๋‹ˆ๋‹ค.
ํ™˜๊ฒฝ ์ •๋ณด - ๋„๋ฉ”์ธ: ์ž‘์„ฑํ•˜์ง€ ์•Š์„ ์‹œ ๋žœ๋ค๊ฐ’์œผ๋กœ ์ž๋™ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.



์‚ฌ์ „ ์„ค์ •: AutoScaling, LoadBalancer๋ฅผ ์‚ฌ์šฉํ•  ์˜ˆ์ •์ด๋ผ๋ฉด ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค. ์•„๋‹ˆ๋ฉด ๋‹จ์ผ ์ธ์Šคํ„ด์Šค๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๊ธฐ๊นŒ์ง€ ์„ค์ •ํ•˜๊ณ  ๊ฒ€ํ†  ๋‹จ๊ณ„๋กœ ๊ฑด๋„ˆ๋›ฐ๋ฉด ์ž ์‹œ ๋’ค EB ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ๋œ ๋„๋ฉ”์ธ์„ ํด๋ฆญํ•˜๋ฉด ํ™”๋ฉด์ด ์•„๋ž˜์ฒ˜๋Ÿผ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.


3. ๋ฐฐํฌ

๋„์ปค ํ—ˆ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค. docker-compose.yml ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

version: "3"
  api:
    image: tester/jpa-rest:0.0.1-dev
    restart: always
    ports:
      - "80:9090"
    container_name: jpa-rest-api
    environment:
      TZ: Asia/Seoul
      SPRING_PROFILES_ACTIVE: prod

EB ํ™˜๊ฒฝ ํƒญ์—์„œ ์—…๋กœ๋“œ ๋ฐ ๋ฐฐํฌ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

์ •์ƒ ๋ฐฐํฌ๊ฐ€ ๋œ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


4. ๋ฐฐํฌ ์˜ต์…˜

๋ฐฐํฌ ์˜ต์…˜์€ 4๊ฐ€์ง€ ์ •๋„๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. Rolling ์ด ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” ๊ธฐ๋ณธ ์„ค์ •์ธ Rolling ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•˜์—ฌ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์šดํƒ€์ž„์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด์„œ๋„ ๋ฐฐํฌ์‹œ๊ฐ„์ด ๋น„๊ต์  ๋นจ๋ผ์„œ ์†Œ๊ทœ๋ชจ ์„œ๋น„์Šค์—์„œ ์ ํ•ฉํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

1. All at once

๋ชจ๋“  ์ธ์Šคํ„ด์Šค์— ๋™์‹œ์— ์ƒˆ ๋ฒ„์ „ ๋ฐฐํฌ ๋‹จ์ˆœํ•˜๊ณ  ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐฐํฌ ๋ฐฉ์‹

๋‹จ์ : ์„œ๋น„์Šค๊ฐ€ ์ค‘๋‹จ๋˜๋Š” ๋‹ค์šดํƒ€์ž„์ด ์กด์žฌํ•œ๋‹ค.

2. Rolling

๋ฐฐ์น˜ ๋‹จ์œ„๋กœ ์ƒˆ ๋ฒ„์ „ ๋ฐฐํฌ (๋‹จ์ผ ์ธ์Šคํ„ด์Šค ๋ถˆ๊ฐ€) ์˜ˆ๋ฅผ ๋“ค์–ด, 4๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. 2๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋จผ์ € ๋ฐฐํฌํ•˜๊ณ , ๋ฐฐํฌ๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ๋‚˜๋จธ์ง€ ์ธ์Šคํ„ด์Šค๋„ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

๋‹จ์ : ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐฐํฌ๊ฐ€ ๋˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ˆ„๊ตฐ๊ฐ€๋Š” ์—…๋ฐ์ดํŠธ ์ „ ๋ฒ„์ „์„ ๋ˆ„๊ตฌ๋Š” ์—…๋ฐ์ดํŠธ ํ›„ ๋ฒ„์ „์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3. Rolling with additional batch

๋ฐฐ์น˜ ๋‹จ์œ„๋กœ ์ƒˆ ๋ฒ„์ „ ๋ฐฐํฌ, +1 ์ถ”๊ฐ€ ๋ฐฐ์น˜ (๋‹จ์ผ ์ธ์Šคํ„ด์Šค ๋ถˆ๊ฐ€) ์˜ˆ๋ฅผ ๋“ค์–ด, 4๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. ๋ฐฐํฌ ์‹œ 2๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์ดํ›„ ๋ฐฐ์น˜ ๋‹จ์œ„๋กœ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค. 6๊ฐœ์ค‘ 4๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ฐฐํฌ ์™„๋ฃŒ๋˜๋ฉด 2๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋Š” ์ข…๋ฃŒ ํ•ฉ๋‹ˆ๋‹ค.

4. Immutable

์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค ๊ทธ๋ฃน์— ๋ฐฐํฌ AutoScaling Group์„ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด ๋ฐฐํฌํ•œ๋‹ค. ์ƒˆ๋กœ ์ƒ๊ธด ๊ทธ๋ฃน์€ ๊ธฐ์กด์˜ ๊ทธ๋ฃน๊ณผ ๊ฐ™์€ DNS ๋ฅผ ๋ฐ”๋ผ๋ณธ๋‹ค. (Blue green ๊ณผ ๋น„์Šทํ•˜๋‹ค)


5. AutoScaling

EB ์˜ AutoScaling ๋ฐฉ๋ฒ•์€ ๋‘ ๊ฐ€์ง€๋กœ ๋‚˜๋‰ฉ๋‹ˆ๋‹ค.

1. Triggers based scaling

ํŠน์ • ๋ฉ”ํŠธ๋ฆญ์˜ ์ž„๊ณ„๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์Šค์ผ€์ผ๋ง์„ ํ•œ๋‹ค.

2. Time-based scaling

ํŠน์ • ์‹œ๊ฐ„์„ ๊ธฐ์ค€์œผ๋กœ ์Šค์ผ€์ผ๋ง์„ ํ•œ๋‹ค. (ex. ์˜ค์ „ 8์‹œ์— ๋Œ€๊ทœ๋ชจ ์—…๋ฐ์ดํŠธ๊ฐ€ ์‹ค์‹œ ๋œ๋‹ค.)

์„ค์ •ํ•˜๊ธฐ

์ €๋Š” CPU ์‚ฌ์šฉ๋ฅ ์„ ๋ฉ”ํŠธ๋ฆญ์œผ๋กœ ํ•˜์—ฌ 60% ์ด์ƒ์ผ ์‹œ ์Šค์ผ€์ผ์—…์„ ํ•˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.


์ธ์Šคํ„ด์Šค๊ฐ€ 2~4๊ฐœ ๊ฐ€ ์œ ์ง€๋˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.


์ธ์Šคํ„ด์Šค๊ฐ€ 2๊ฐœ ์‹คํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ“„ ๋งˆ์น˜๋ฉฐ..

1. ์ดˆ๊ธฐ ์„ค์ •์ด ๋น ๋ฅด๊ณ  ๊ฐ„๋‹จํ•˜๋‹ค.

EC2 ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ, ํƒ„๋ ฅ์  IP ์„ค์ •, ๋„์ปค ์„ค์น˜ ๋“ฑ ๋‹น์—ฐํžˆ ์ˆ˜ํ–‰๋˜์–ด์•ผ ๋˜๋Š” ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋ ค์šด ์ผ์€ ์•„๋‹ˆ์ง€๋งŒ, EB ๊ฐ€ ๋ฐ˜๋ณต๋œ ์ž‘์—…์„ ์ค„์—ฌ์ฃผ๋ฏ€๋กœ ํŽธ๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.

2. AutoScaling ์„ค์ •์ด ํŽธํ•˜๋‹ค.

AutoScaling ์„ค์ •์ด ๊ฐ„๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ˆˆ์— ๋ณด์ด๋Š”๋ฐ๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์„ค์ •ํ•˜๊ณ , ์ž„๊ณ„๊ฐ’๊ณผ ์ธ์Šคํ„ด์Šค ์ˆ˜๋งŒ ์ •ํ•˜๋ฉด ์ ์šฉ์ด ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค.


์ฐธ๊ณ  ์ž๋ฃŒ

AWS Elastic Beanstalk ํ™œ์šฉํ•˜์—ฌ ์ˆ˜ ๋ถ„๋งŒ์— ์ฝ”๋“œ ๋ฐฐํฌํ•˜๊ธฐ - ์ตœ์›๊ทผ ์†”๋ฃจ์…˜์ฆˆ ์•„ํ‚คํ…ํŠธ(AWS)
๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๋ฐฉ์‹(Rolling / BlueGreen / Canary)
[AWS] Spring Boot ํ”„๋กœ์ ํŠธ Elastic beanstalk์— ์ˆ˜๋™ ๋ฐฐํฌํ•˜๊ธฐ