๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“”๊ฐ•์˜ ์ •๋ฆฌ ๋…ธํŠธ

[Spring Cloud๋กœ ๊ฐœ๋ฐœํ•˜๋Š” ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค] Section 0: MicroService์™€ Spring Cloud ์†Œ๊ฐœ

๋ชฉ์ฐจ

์†Œํ”„ํŠธ์›จ์–ด ์•„ํ‚คํ…์ฒ˜

1990 ~ 2000 : Robust, Distributed

2010 ~ : Resilient / Anti-Fagile, Cloud Native

 

  • Antifrgile ํŠน์ง•
    • Auto scaling
    • Microservices
    • Chaos engineering - ๋ถˆํ™•์‹คํ•œ ์ƒํ™ฉ์—์„œ๋„ ์•ˆ์ •์ ์ธ ์„œ๋น„์Šค
    • Continuos deployment - ์ง€์†์ ์ธ ํ†ตํ•ฉ๊ณผ ๋ฐฐํฌ (ํ…Œ์ŠคํŠธ, ๋ชจ๋‹ˆํ„ฐ๋ง,ํ”ผ๋“œ๋ฐฑ) => Continous Delivery

Cloud Native Architecture

  • ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ์•„ํ‚คํ…์ฒ˜
    • ์‹œ์Šคํ…œ์˜ ์ˆ˜ํ‰์  ํ™•์žฅ์— ์œ ์—ฐ
    • ํ™•์žฅ๋œ ์„œ๋ฒ„๋กœ ์‹œ์Šคํ…œ ๋ถ€ํ•˜๋ถ„์‚ฐ, ๊ฐ€์šฉ์„ฑ ๋ณด์žฅ (Scale up, Scale out)
    • ์‹œ์Šคํ…œ ๋˜๋Š”, ์„œ๋น„์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‹จ์œ„์˜ ํŒจํ‚ค์ง€ (์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ํŒจํ‚ค์ง€)
    • ํด๋ผ์šฐ๋“œ ๊ตฌ์ถ•๋œ ๊ฐ€์ƒ์„œ๋ฒ„์™€ ๋ฆฌ์†Œ์Šค๋“ค์€ ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌํ˜„์žฌ ์‹œ์Šคํ…œ์˜ ์ƒํ™ฉ ๋ฐ ๋ฆฌ์†Œ๋ฅด๋ฅผ ํ™•์ธ ๊ฐ€๋Šฅ
  • ํƒ„๋ ฅ์  ์•„ํ‚คํ…์ฒ˜
    • CI/CD ์ž๋™ํ™” ์ ์šฉ (๋น„์ฆˆ๋‹ˆ์Šค ํ™˜๊ฒฝ ๋ณ€ํ™”์— ๋Œ€์‘ ์‹œ๊ฐ„ ๋‹จ์ถ•)
    • ๋ถ„ํ•  ๋œ ์„œ๋น„์Šค ๊ตฌ์กฐ (๋„๋ฉ”์ธ์˜ ํŠน์ง•์— ๋”ฐ๋ผ ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค๋ฅผ ๊ฐœ๋ฐœ)
    • ๋ฌด์ƒํƒœ ํ†ต์‹  ํ”„๋กœํ† ์ฝœ
    • ์„œ๋น„์Šค์˜ ์ถ”๊ฐ€์™€ ์‚ญ์ œ ์ž๋™์œผ๋กœ ๊ฐ์ง€
  • ์žฅ์•  ๊ฒฉ๋ฆฌ (Fault isolation)
    • ํŠน์ • ์„œ๋น„์Šค์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ด๋„ ๋‹ค๋ฅธ ์„œ๋น„์Šค์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์Œ.

 

CI/CD

  • ์ง€์†์ ์ธ ํ†ตํ•ฉ
    • ํ†ตํ•ฉ ์„œ๋ฒ„, ์†Œ์Šค ๊ด€๋ฆฌ, ๋นŒ๋“œ ๋„๊ตฌ, ํ…Œ์ŠคํŠธ ๋„๊ตฌ
    • jenkins, Travis CI
  • ์ง€์†์ ์ธ ๋ฐฐํฌ
    • Continous Delivery (์‹คํ–‰ํŒŒ์ผ ์ˆ˜๋™๋ฐฐํฌ) 
    • Continous Deployment (์‹คํ–‰ํ™˜๊ฒฝ ์„ธํŒ… ์™„๋ฃŒ ํ›„ ์ž๋™ ๋ฐฐํฌ)
  • ์นด๋‚˜๋ฆฌ ๋ฐฐํฌ์™€ ๋ธ”๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ (๋น„์œจ์„ ๋‚˜๋ˆ ์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ํ•จ)

DevOps

๊ณ ๊ฐ์˜ ์š”๊ตฌ์‚ฌํ•ญ์€ ๊ณ„์†ํ•ด์„œ ๋ณ€ํ™”ํ•˜๋ฏ€๋กœ ๊ทธ ๋ณ€ํ™”์— ๋งž์ถฐ ์ž์ฃผ ๊ณ„ํšํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•˜๊ณ  ํ”ผ๋“œ๋ฐฑ๋ฐ›๊ณ  ๊ฐœ๋ฐœํ•˜์—ฌ ๋ฐฐํฌํ•˜๋Š”์ „์ฒด ๊ฐœ๋ฐœ์ผ์ •์ด ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ณ„์†ํ•ด์„œ ๊ฐœ๋ฐœํ•ด๋‚˜๊ฐ€๋Š” ๊ฒƒ์ด๋‹ค.

Container ๊ฐ€์ƒํ™”

์ปจํ…Œ์ด๋„ˆ๋ž€ ํ˜ธ์ŠคํŠธ OS์œ„์— ์ปจํ…Œ์ด๋„ˆ ์—”์ง„์„ ์„ค์น˜ํ•˜๊ณ  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ž‘๋™์— ํ•„์š”ํ•œ ๋ฐ”์ด๋„ˆ๋ฆฌ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ์„ ํ•˜๋‚˜๋กœ ๋ชจ์•„ ๊ฐ์ž๊ฐ€ ๋ณ„๋„์˜ ์„œ๋ฒ„์ธ ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋Š” ํ™˜๊ฒฝ์„ ๋งํ•œ๋‹ค.

12 factors

ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ง€์ผœ์•ผํ•˜๋Š” 12๊ฐ€์ง€ ๊ทœ์น™ [์ฝ์–ด๋ณผ๊ฒƒ]

https://medium.com/dtevangelist/12-factors-%EB%9E%80-b39c7ef1ed30

 

12-Factors ๋ž€

์ตœ๊ทผ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ Cloud ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜์—ฌ ์„œ๋น„์Šค ํ˜•ํƒœ๋กœ ์ œ๊ณตํ•˜๋Š” SaaS(Software As A Service)๊ฐ€ ๋ณดํŽธํ™”๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ €ํฌ ํŒ€์—์„œ๋„ ์ž‘๋…„๋ถ€ํ„ฐ ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์„ Cloud๋กœ ์ „ํ™˜ํ•˜๊ธฐ ์œ„ํ•œ ์ปจ์„คํŒ…์„ ์ค€๋น„ํ•˜

medium.com

 

Monolith vs. MSA

  • Monolith
    • ๋ชจ๋“  ์—…๋ฌด ๋กœ์ง์ด ํ•˜๋‚˜์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ˜•ํƒœ๋กœ ํŒจํ‚ค์ง€ ๋˜์–ด ์„œ๋น„์Šค
    • ์‚ฌ์šฉํ•˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ํ•œ๊ณณ์— ๋ชจ์—ฌ ์ฐธ์กฐ๋˜์–ด ์„œ๋น„์Šค๋˜๋Š” ํ˜•ํƒœ
      => ์ž‘์€ ๋ณ€ํ™”์—๋„ ์ „์ฒด ์‹œ์Šคํ…œ์ด ๋นŒ๋“œ๋˜๊ณ  ๋ฐฐํฌ๋˜์•ผ ํ•œ๋‹ค.
      => ํ•˜๋‚˜์˜ ๊ธฐ๋Šฅ ์˜ค๋ฅ˜์—๋„ ์ „์ฒด ์‹œ์Šคํ…œ์ด ๋‹ค์šด๋œ๋‹ค.
  • Microservice
    • ๊ธฐ๋Šฅ ๋‹จ์œ„์˜ ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค ๊ตฌ์ถ•
      • ์„œ๋กœ ๋…๋ฆฝ์ ์ธ ์–ธ์–ด์™€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ (๊ฐ๊ฐ์˜ ์„œ๋น„์Šค์˜ ํŠน์„ฑ์— ๋งž๊ฒŒ ์„ ํƒํ•ด์„œ ์‚ฌ์šฉ)
    • ์„œ๋น„์Šค ๋‹จ์œ„์˜ ์ž๋™ํ™”๋œ ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ
    • API๋ฅผ ํ†ตํ•œ ์„œ๋น„์Šค๊ฐ„ ํ†ต์‹ 

๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ๋„์ž… ์ „์— ํ™•์ธํ•ด์•ผํ•  ์กฐ๊ฑด

  • Microservice ํŒ€ ๊ตฌ์กฐ
    • Two Pizza team (8 ~ 10)
    • API ํ˜‘์˜๊ฐ€ ์›ํ• ํ•˜๊ฒŒ ๊ฐ€๋Šฅํ•œ ํŒ€
    • ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค๊ฐ€ ๋…๋ฆฝ์ ์œผ๋กœ ๊ฐœ๋ฐœ, ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•œ ํŒ€

SOA vs. MSA

SOA - ์žฌ์‚ฌ์šฉ์„ ํ†ตํ•œ ๋น„์šฉ์ ˆ๊ฐ

  • ๊ณตํ†ต๋œ ์„œ๋น„์Šค๋ฅผ ๋ชจ์•„ ๊ณตํ†ต ์„œ๋น„์Šค ํ˜•์‹์œผ๋กœ ์ œ๊ณต

 

MSA - ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ”์–ด ๋ณ€ํ™”์— ๋Šฅ๋™์ ์œผ๋กœ ๋Œ€์‘

  • ๊ฐ ๋…๋ฆฝ๋œ ์„œ๋น„์Šค๊ฐ€ ๋…ธ์ถœ๋œ REST API๋ฅผ ์ œ๊ณต
    • REST ์„ฑ์ˆ™๋„ ๋ชจ๋ธ 
    • level1 - uri์— ์ ์ ˆํ•œ ์ž์›์„ ๋…ธ์ถœ
    • level2 - level1 + HTTP Methods, [GET, POST, PUT, DELETE..]
    • level3 - level2 + HATEOAS, ๋ฐ์ดํ„ฐ์™€ ๊ฐ€๋Šฅํ•œ ์•ก์…˜ ๋ฉ”ํ„ฐ์ •๋ณด๋ฅผ ํ•จ๊ป˜ ๋„˜๊ฒจ์คŒ

- MSA Component -

Service Mesh - API Gateway -> Service Router [Service Discovery] -> Load Balancing -> ๊ฐ ์ธ์Šคํ„ด์Šค ์„œ๋น„์Šค์— ์š”์ฒญ 

 

CI/CD ์ž๋™ํ™”

Backing Service (DB ๋“ฑ)

Telemetry (Monitoring, Diagnostics)

 

MSA ๊ธฐ๋ฐ˜ ๊ธฐ์ˆ 

Spring Cloud

  • Spring Cloud Config Server
    • ํ™˜๊ฒฝ์„ค์ • ์ •๋ณด (Gateway์ •๋ณด, ์„œ๋ฒ„์˜ IP์ •๋ณด ๋“ฑ)
    • ๋นŒ๋“œ์—†์ด ์™ธ๋ถ€์ €์žฅ์†Œ์—์„œ ํ™˜๊ฒฝ์„ค์ • ์ •๋ณด ๋ฐ”๊ฟ”์„œ ์‚ฌ์šฉํ•˜๋„๋ก ํ•จ 
  • Location Transparency
    • Naming Server (Eureka)
  • Load Distribution (Load Balancing)
    • ์„œ๋ฒ„์˜ ์š”์ฒญ ๋ถ„์‚ฐ ๋ฐ Gateway ๊ธฐ๋Šฅ 
    • Ribbon (client side)
    • Spring Cloud Gateway
  • Easier Rest Client
    • ์„œ๋กœ๊ฐ„ ์›ํ• ํ•œ ํ†ต์‹ ์„ ์œ„ํ•ด
  • Visibility and monitoring
  • Fault Tolerance