๋ฐ˜์‘ํ˜•
JPA (Java Persistence API)

์ž๋ฐ” ์ง„์˜์—์„œ ๋งŒ๋“  ORM ๊ธฐ์ˆ  ํ‘œ์ค€

์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์ž๊ฐ€ SQL ์— ์˜์กดํ•˜๋Š” ๊ฐœ๋ฐœ์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.
๊ฐœ๋ฐœ์ž ์ž…์žฅ์—์„œ ์ฟผ๋ฆฌ๋ฌธ์„ ๋‹ค๋ฃจ์ง€ ์•Š๊ณ  ๊ฐ์ฒด์ง€ํ–ฅ ์ค‘์‹ฌ์œผ๋กœ ๊ฐœ๋ฐœ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋˜์–ด์žˆ๊ธฐ์—, ์ƒ์‚ฐ์„ฑ ๋ฐ ์œ ์ง€๋ณด์ˆ˜์— ํšจ์œจ์ 
๊ฐ์ฒด์™€ ๊ด€๊ณ„ํ˜• DB์˜ ์ฐจ์ด๋ฅผ ์ค‘๊ฐ„์—์„œ ํ•ด๊ฒฐํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ต์ฒดํ•˜๋”๋ผ๋„ ์œ ์ง€๋ณด์ˆ˜ ์˜ํ–ฅ๋„๊ฐ€ ํฌ์ง€ ์•Š์Œ.
    → mysql,, oracle ๋ฐ”๊ฟ” ์‚ฌ์šฉํ•˜๋”๋ผ๋„ ์ฟผ๋ฆฌ ๋ณ€๊ฒฝ์—†์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ

 

JPA ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ

โ€ฃ ์—”ํ‹ฐํ‹ฐ ์™€ ํ…Œ์ด๋ธ”์„ ๋งคํ•‘ํ•˜๋Š” ์„ค๊ณ„ ๋ถ€๋ถ„
โ€ฃ ๋งคํ•‘ํ•œ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์‹ค์ œ ์‚ฌ์šฉํ•˜๋Š” ๋ถ€๋ถ„.

โœข ์—”ํ‹ฐํ‹ฐ ? 
์ •๋ณด๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋‹จ์œ„์ด๊ธฐ๋„ํ•˜๋ฉฐ
JPA ์—์„œ๋Š” ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์˜์†ํ™” ํ•ด์•ผํ•  ์ž๋ฐ” ๊ฐ์ฒด (๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”๋กœ ํ‘œํ˜„)๋ฅผ ๋‚˜ํƒ€๋ƒ„.

 

 

์˜์†์„ฑ ๊ด€๋ฆฌ

ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ƒ์„ฑ์ด ๋˜์—ˆ์ง€๋งŒ, ๋ณ„๊ฐœ๋กœ ์œ ์ง€๋˜๋Š” ์ƒํƒœ์˜ ํŠน์ง•์ค‘ ํ•˜๋‚˜.
์ด๋ฅผ ๋ณ„๋„์˜ ๊ธฐ์–ต์žฅ์น˜์— ๋ณด์กด ๋ฐ ๊ด€๋ฆฌํ•˜๋Š”๊ฒƒ.

https://www.youtube.com/watch?v=PMNSeD25Qko&list=PL9mhQYIlKEhfpMVndI23RwWTL9-VL-B7U&index=6

์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ €๋Š” ํŠธ๋žœ์žญ์…˜์ด ์‹คํ–‰๋ ๋•Œ ์ปค๋„ฅ์…˜์„ ์–ป์Œ

์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ € ํŒฉํ† ๋ฆฌ
EntityManagerFactory emf = Persistence.createEntityManagerFactory("test");

โ€ฃ JPA ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒํ•จ.
โ€ฃ JPA ๋™์ž‘ ์œ„ํ•ด ๊ธฐ๋ฐ˜ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  ์ปค๋„ฅ์…˜ํ’€์„ ์ƒ์„ฑํ•จ → ๋น„์šฉ์ด ํฌ๋‹ค.
โ€ฃ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋”ฑ ํ•œ๋ฒˆ ์ƒ์„ฑ ํ›„ ๊ณต์œ ํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.

 

์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ €
EntityManager em = emf.createEntityManager();

โ€ฃ JPA ๊ธฐ๋Šฅ์„ ์ œ๊ณต. ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ CRUD๊ฐ€ ๊ฐ€๋Šฅํ•จ.
โ€ฃ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•จ. (๊ด€๋ฆฌ์ž)
โ€ฃ ํŠธ๋žœ์žญ์…˜์„ ์ปค๋ฐ‹ํ•˜๊ธฐ ์ง์ „๊นŒ์ง€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š๊ณ  ๋‚ด๋ถ€ ์ฟผ๋ฆฌ ์ €์žฅ์†Œ(์“ฐ๊ธฐ์ง€์—ฐ SQL ์ €์žฅ์†Œ)์— ์ฟผ๋ฆฌ๋ฅผ ๋ชจ์•„๋‘๋„๋ก ํ•จ.
    → ํŠธ๋žœ์žญ์…˜ ์ปค๋ฐ‹์‹œ ๋ชจ์•„๋‘” ์ฟผ๋ฆฌ๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ณด๋ƒ„=ํ”Œ๋Ÿฌ์‹œ (์“ฐ๊ธฐ์ง€์—ฐ)
    → ํŠธ๋žœ์žญ์…˜ ์ปค๋ฐ‹๊นŒ์ง€ ๋˜์–ด์•ผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ณ€๊ฒฝ๋‚ด์šฉ ๋ฐ˜์˜์ด ๋จ
โ€ฃ ๋‚ด๋ถ€์— ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์œ ์ง€ํ•˜๋ฉด์„œ (์ปค๋„ฅ์…˜ ์œ ์ง€) ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ํ†ต์‹ ํ•จ.
โ€ฃ ๊ฐœ๋ฐœ์ž ์ž…์žฅ์—์„  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์Œ.
โ€ฃ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ปค๋„ฅ์…˜๊ณผ ๋ฐ€์ ‘ํ•œ ๊ด€๊ณ„๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ์Šค๋ ˆ๋“œ๊ฐ„์— ๊ณต์œ ํ•˜๊ฑฐ๋‚˜ ์žฌ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋จ. (๋™์‹œ์„ฑ ๋ฌธ์ œ)
โ€ฃ ์ƒ์„ฑ ๋น„์šฉ์ด ํฌ์ง„ ์•Š์Œ.
โ€ฃ ์—”ํ‹ฐํ‹ฐ๋งค๋‹ˆ์ €๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋งˆ๋‹ค ์‹ค์ œ๋กœ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์™€ ์ƒํ˜ธ ์ž‘์šฉ์„ ํ•จ.

 

์˜์†์„ฑ ์ปจํ…์ŠคํŠธ (persistence context)

https://www.youtube.com/watch?v=PMNSeD25Qko&list=PL9mhQYIlKEhfpMVndI23RwWTL9-VL-B7U&index=6

โ€ฃ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜๊ตฌ ์ €์žฅํ•˜๋Š” ํ™˜๊ฒฝ 
โ€ฃ ์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ €๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅ

โ€ฃ ์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ €๋กœ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์กฐํšŒํ•˜๋ฉด ์—”ํ‹ฐํ‹ฐ๋งค๋‹ˆ์ €๋Š” ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์—”ํ‹ฐํ‹ฐ๋ฅผ ๋ณด๊ด€ํ•˜๊ณ  ๊ด€๋ฆฌ (์—”ํ‹ฐํ‹ฐ ๋งค๋‹ˆ์ €์˜ ์ˆ˜๋ช…์ฃผ๊ธฐ ๊ด€๋ฆฌ)
โ€ฃ 1์ฐจ์บ์‹œ, ๋™์ผ์„ฑ๋ณด์žฅ(identity), ์“ฐ๊ธฐ์ง€์—ฐ, ๋ณ€๊ฒฝ๊ฐ์ง€(Dirty Checking), ์ง€์—ฐ๋กœ๋”ฉ(Lazy Loading) ๋จ

โœข 1์ฐจ ์บ์‹œ ? 
์˜์†์„ฑ ์ปจํ…์ŠคํŠธ ๋‚ด ์บ์‹œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ. 
์˜์†์ƒํƒœ์˜ ์—”ํ‹ฐํ‹ฐ๋Š” ๋ชจ๋‘ ์ด๊ณณ์— ์ €์žฅ๋จ.
Map ํ˜•ํƒœ์ด๊ณ  [key: @Id๋กœ ๋งคํ•‘ํ•œ ์‹๋ณ„์ž, value: ์—”ํ‹ฐํ‹ฐ ์ธ์Šคํ„ด์Šค] ์ด๋‹ค

 

์—”ํ‹ฐํ‹ฐ ์ƒ๋ช…์ฃผ๊ธฐ

https://www.youtube.com/watch?v=PMNSeD25Qko&list=PL9mhQYIlKEhfpMVndI23RwWTL9-VL-B7U&index=6

โ€ฃ ๋น„์˜์† (new/transient): ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์™€ ์ „ํ˜€ ๊ด€๊ณ„๊ฐ€ ์—†๋Š” ์ƒํƒœ
    → ์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅํ•˜์ง€ ์•Š์€ ์ƒํƒœ.
    → ๊ฐ์ฒด๋งŒ ์ƒ์„ฑํ•œ ์ƒํƒœ 
โ€ฃ ์˜์† (managed): ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅ๋œ ์ƒํƒœ (์˜์†์ƒํƒœ)
โ€ฃ ์ค€์˜์† (detached): ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅ ๋˜์—ˆ๋‹ค๊ฐ€ ๋ถ„๋ฆฌ๋œ ์ƒํƒœ 
   → ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.
   → 1์ฐจ ์บ์‹œ์—์„œ ์‚ฌ๋ผ์ง..
   → ์ง€์—ฐ๋กœ๋”ฉ(LAZY LOADING) ํ•  ์ˆ˜ ์—†๋‹ค.
   → ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.
   → ์‹๋ณ„์ž๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  ๊ฑฐ์˜ ๋น„์˜์† ์ƒํƒœ์ž„.
   → ๋‹ค์‹œ ์˜์† ์ƒํƒœ๋กœ ๋งŒ๋“œ๋ ค๋ฉด merge() ํ•˜๋ฉด ๋จ. (์ค€์˜์† ์ƒํƒœ์˜ ์—”ํ‹ฐํ‹ฐ๋ฅผ ๋ฐ›์•„ ๋‹ค์‹œ ์˜์† ์ƒํƒœ๋กœ ๋งŒ๋“ฌ)
โ€ฃ ์‚ญ์ œ (removed): ์‚ญ์ œ 

 

์—”ํ‹ฐํ‹ฐ ์ €์žฅ (insert)

์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์— ์ €์žฅํ•œ ์ƒํƒœ, ์•„์ง ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—๋Š” ์ €์žฅํ•˜์ง€ ์•Š์€ ์ƒํƒœ.

 

๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์— ์ €์žฅ

โ€ฃ ์“ฐ๊ธฐ์ง€์—ฐ(transactional write-behind)
    → ํŠธ๋žœ์žญ์…˜ ์ปค๋ฐ‹ ์ง์ „๊นŒ์ง€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š๊ณ ,
        ๋‚ด๋ถ€ ์ฟผ๋ฆฌ ์ €์žฅ์†Œ์— INSERT ์ฟผ๋ฆฌ๋ฅผ ๋ชจ์•„๋‘๊ณ  ์ปค๋ฐ‹์‹œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ณด๋‚ด๋Š” ์ƒํƒœ (๋ณด๋‚ด๋Š” ์ž‘์—…=flush)

 

์—”ํ‹ฐํ‹ฐ ์กฐํšŒ (read)

1์ฐจ ์บ์‹œ์—์„œ ์กฐํšŒํ•œ ์ƒํƒœ

โ€ฃ ๋™์ผ์„ฑ์ด ๋ณด์žฅ๋œ๋‹ค!

 

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์กฐํšŒํ•œ ์ƒํƒœ

 

๋ณ€๊ฒฝ ๊ฐ์ง€ (dirty checking) - ์ˆ˜์ •

โ€ฃ ์—”ํ‹ฐํ‹ฐ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ž๋™์œผ๋กœ ๋ฐ˜์˜ํ•˜๋Š” ๊ธฐ๋Šฅ
โ€ฃ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์กฐํšŒํ•˜์—ฌ ๋ณ€๊ฒฝ๋ถ€๋ถ„ ํŒŒ์•… ํ›„ ์—…๋ฐ์ดํŠธ
โ€ฃ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์˜์† ์ƒํƒœ์˜ ์—”ํ‹ฐํ‹ฐ์—๋งŒ ์ ์šฉ
โ˜ž ๋ณ€๊ฒฝ ๊ฐ์ง€ ๊ด€๋ จ ์ƒํ™ฉ (๋งํฌ)

๋ณ€๊ฒฝ๊ฐ์ง€ ์ฒ˜๋ฆฌ์ƒํƒœ 

 

ํ”Œ๋Ÿฌ์‹œ (flush)

โ€ฃ ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋™๊ธฐํ™”ํ•˜๋Š” ์ž‘์—…. 
    → ์ง์ ‘ ํ˜ธ์ถœ: em.flush() ์ง์ ‘ ํ˜ธ์ถœ
    → ํŠธ๋žœ์žญ์…˜ ์ปค๋ฐ‹ ์‹œ ํ”Œ๋Ÿฌ์‹œ ์ž๋™ ํ˜ธ์ถœ: ๊ธฐ๋ณธ์„ค์ •..
    → JPQL ์ฟผ๋ฆฌ ์‹คํ–‰์‹œ ํ”Œ๋Ÿฌ์‹œ ์ž๋™ ํ˜ธ์ถœ

 

 


์ฐธ๊ณ 

- ์ฑ…: http://www.kyobobook.co.kr/product/detailViewKor.laf?mallGb=KOR&ejkGb=KOR&barcode=9788960777330 

 

์ž๋ฐ” ORM ํ‘œ์ค€ JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ - ๊ต๋ณด๋ฌธ๊ณ 

์Šคํ”„๋ง ๋ฐ์ดํ„ฐ ์˜ˆ์ œ ํ”„๋กœ์ ํŠธ๋กœ ๋ฐฐ์šฐ๋Š” ์ „์ž์ •๋ถ€ ํ‘œ์ค€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ”„๋ ˆ์ž„ | โ˜… ์ด ์ฑ…์—์„œ ๋‹ค๋ฃจ๋Š” ๋‚ด์šฉ โ˜…โ–  JPA ๊ธฐ์ดˆ ์ด๋ก ๊ณผ ํ•ต์‹ฌ ์›๋ฆฌโ–  JPA๋กœ ๋„๋ฉ”์ธ ๋ชจ๋ธ์„ ์„ค๊ณ„ํ•˜๋Š” ๊ณผ์ •์„ ์˜ˆ์ œ ์ค‘์‹ฌ์œผ๋กœ

www.kyobobook.co.kr

- ๋งํฌ: https://ko.wikipedia.org/wiki/%EC%A7%80%EC%86%8D%EC%84%B1

- ๋งํฌ: https://www.baeldung.com/jpa-entities

 

์ง€์†์„ฑ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

 

ko.wikipedia.org

- ๋งํฌ: https://cupping.tistory.com/2

 

Programming language png Logo (transparent)

Jpa logo.png MariaDB logo.png ECMA6 logo.png python logo.png elasticSearch logo.png gradle logo.png node.js logo.png

cupping.tistory.com

- ๋งํฌ: https://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/jpa_overview_emfactory_perscontext.html

 

3.  Persistence Context

Example 7.1.  Behavior of Transaction Persistence Context The following code illustrates the behavior of entites under an EntityManager using a transaction persistence context. EntityManager em; // injected ... // outside a transaction: // each operation

openjpa.apache.org

- ๋งํฌ: https://www.baeldung.com/jpa-hibernate-persistence-context

- ๊ฐ•์˜: https://www.youtube.com/playlist?list=PL9mhQYIlKEhfpMVndI23RwWTL9-VL-B7U 

 

ํ† ํฌON 41์ฐจ. JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ๊ธฐ ๋‹ค์ง€๊ธฐ | T์•„์นด๋ฐ๋ฏธ

T์•„์นด๋ฐ๋ฏธ ์˜จ๋ผ์ธ ๊ฐ•์˜- [ํ† ํฌON์„ธ๋ฏธ๋‚˜] JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ๊ธฐ ๋‹ค์ง€๊ธฐ (์ด8๊ฐ•) https://tacademy.skplanet.com/live/player/onlineLectureDetail.action?seq=149 [๊ณผ์ • ์†Œ๊ฐœ] ๋งˆํ” ํ•œ๋ฒˆ์งธ ์„ธ๋ฏธ๋‚˜ ์ฃผ์ œ๋Š” ‘JPA(Java...

www.youtube.com

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค
(k8s = kubernetes)

 

์„ค๋ช…

์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‰ฝ๊ณ  ๋น ๋ฅด๊ฒŒ ๋ฐฐํฌ/ํ™•์žฅํ•˜๊ณ  ๊ด€๋ฆฌ๋ฅผ ์ž๋™ํ™”ํ•ด์ฃผ๋Š” ์˜คํ”ˆ์†Œ์Šค ํ”Œ๋žซํผ
 ์‰ฝ๊ฒŒ๋งํ•ด, ๋‹ค์ˆ˜์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉ
 ๊ตฌ๊ธ€์—์„œ ๋งŒ๋“ค์—ˆ๊ณ  borg ๊ธฐ๋ฐ˜
์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜(container orchestration)์˜ ํ‘œ์ค€ 
  ↑click-!

โ€ป ์ปจํ…Œ์ด๋„ˆ
• ํ•˜๋‚˜์˜ ์šด์˜์ฒด์ œ(OS) ์ปค๋„ ์—์„œ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์— ์˜ํ–ฅ๋ฐ›์ง€ ์•Š๊ณ  ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค ์ƒํƒœ
• ์šด์˜์ฒด์ œ ํ™˜๊ฒฝ์— ๊ด€๊ณ„ ์—†์ด ๋…๋ฆฝ์ ์ธ ํ™˜๊ฒฝ์—์„œ ์ผ๊ด€๋œ ๊ฒฐ๊ณผ ๋ณด์žฅ
• ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐ„ ์šด์˜์ฒด์ œ(OS)์„ ๊ณต์œ 
• ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—๋Š” ์ž์ฒด ํŒŒ์ผ์‹œ์Šคํ…œ, CPU์ ์œ ์œจ, ๋ฉ”๋ชจ๋ฆฌ, ํ”„๋กœ์„ธ์Šค ๊ณต๊ฐ„ ๋“ฑ์ด ์กด์žฌ.
• ํด๋ผ์šฐ๋“œ or OS ๋ฐฐํฌ๋ณธ์— ๋ชจ๋‘ ์ด์‹ ๊ฐ€๋Šฅ.

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ?

๋ถ„์‚ฐ์‹œ์Šคํ…œ์„ ํƒ„๋ ฅ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ. (๋ฐฐํฌ ๊ด€๋ฆฌ๋“ฑ์„ ์‹œ์Šคํ…œ์ด ์•Œ์•„์„œ ์ฒ˜๋ฆฌํ•ด์คŒ์œผ๋กœ์จ ์•ˆ์ •์„ฑ์— ๊ธฐ์—ฌํ•จ)

 

 

Desired State (์›ํ•˜๋Š” ์ƒํƒœ)

https://subicura.com/2019/05/19/kubernetes-basic-1.html

์ƒํƒœ ์ฒดํฌ(Observe) ์ค‘ ํ˜„์žฌ์ƒํƒœ(Current State)์—์„œ ์ฐจ์ด์ (Diff)์ด ๋ฐœ๊ฒฌ์‹œ ์กฐ์น˜(Act)๋ฅผ ์ทจํ•˜์—ฌ ์›ํ•˜๋Š” ์ƒํƒœ๋กœ ๋งŒ๋“ฌ
๋น„๊ตํ•˜๊ณ  ๋น„๊ตํ•˜๊ณ  ๋น„๊ตํ•˜์—ฌ ๋‹ค๋ฅด๋ฉด ๊ทธ์— ๋งž๊ฒŒ ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•จ
API ๊ฐ€ ํ˜„์žฌ์ƒํƒœ๋ฅผ ๊ฐ–๊ณ  ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ๋ณด์กดํ•˜๊ธฐ ์œ„ํ•ด etcd๊ฐ€ ํ•„์š” (ํ•œ๋ชธ์œผ๋กœ ์›€์ง์ž„)

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ปดํฌ๋„ŒํŠธ

 ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ๋ฐฐํฌํ•˜์˜€์„๋•Œ ์ƒ์„ฑ

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•„ํ‚คํ…์ฒ˜

https://kubernetes.io/ko/docs/concepts/overview/components/

โ ๋งˆ์Šคํ„ฐ๋…ธ๋“œ์™€ ์›Œ์ปค๋…ธ๋“œ๋กœ ๊ตฌ์„ฑ โ 
    โ€ฃ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์—๋Š” kubectl, API ์„œ๋ฒ„, etcd, ์ปจํŠธ๋กค๋Ÿฌ ๋งค๋‹ˆ์ €, ์Šค์ผ€์ค„๋Ÿฌ ๋“ฑ์ด ์กด์žฌ. (์„ ์–ธ์  ์‹œ์Šคํ…œ)
    โ€ฃ์›Œ์ปค๋…ธ๋“œ์—๋Š” kubelet, ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„, Pod, ๋„คํŠธ์›Œํฌํ”Œ๋Ÿฌ๊ทธ์ธ, CoreDNS ๊ฐ€ ์กด์žฌํ•จ. (์›Œ์ปค๋…ธ๋“œ๋Š” ์›Œ์ปคํ”Œ๋กœ ๊ตฌ์กฐ)

โ– Kubernetes cluster
    โ€ฃ ์ปจํ…Œ์ด๋„ˆํ™”๋œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š” ๋…ธ๋“œ๋ผ๊ณ  ํ•˜๋Š” (์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์œ„ํ•จ) ์˜ ์›Œ์ปค ๋จธ์‹ ์˜ ์ง‘ํ•ฉ

โ– Control Plane
    โ€ฃ ๋Š์ž„์—†์ด ์ƒํƒœ๋ฅผ ์ฒดํฌํ•˜๊ณ  ์›ํ•˜๋Š” ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•จ (์ƒˆ๋กœ์ƒ๊ธด Pod์„ ๊ณ„์† ์ฒดํฌํ•จ)
    โ€ฃ etcd, API ์„œ๋ฒ„, Scheduler, ์ปจํŠธ๋กค๋Ÿฌ๋งค๋‹ˆ์ €, ํด๋ผ์šฐ๋“œ ์ปจํŠธ๋กค๋Ÿฌ ๋งค๋‹ˆ์ € ๋“ฑ์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑ → ์ด๋ฅผ ์‹คํ–‰ํ•ด์ฃผ๋Š” ๊ฒƒ์ด Master
    โ€ฃ ๋งˆ์Šคํ„ฐ๋…ธ๋“œ

โ– Controller
    โ€ฃ ๋Š์ž„์—†์ด ์ƒํƒœ๋ฅผ ์ฒดํฌํ•˜๊ณ  ์›ํ•˜๋Š” ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•จ (์ƒˆ๋กœ์ƒ๊ธด Pod์„ ๊ณ„์† ์ฒดํฌํ•จ, API ์„œ๋ฒ„๋ฅผ ํ†ตํ•ด ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ณต์œ  ์ƒํƒœ ๊ฐ์‹œ)
    โ€ฃ ๋‹จ์ผ ํ”„๋กœ์„ธ์Šค๋กœ ์‹คํ–‰ (๋ณต์žก์„ฑ ๋‚ฎ์ถค)
    โ€ฃ ๋ฌดํ•œ๋ฐ˜๋ณต์œผ๋กœ ๋Œ๋ฉด์„œ ์ฒดํฌ
    โ€ฃ๋…ผ๋ฆฌ์ ์œผ๋กœ ๋‹ค์–‘ํ•œ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌํ•จ (๋ณต์ œ์ปจํŠธ๋กค๋Ÿฌ,, ๋…ธ๋“œ์ปจํŠธ๋กค๋Ÿฌ,, ์—”๋“œํฌ์ธํŠธ ์ปจํŠธ๋กค๋Ÿฌ,, 10๊ฐœ..20๊ฐœ..)


โ– Scheduler
    โ€ฃ Node ํ˜„์žฌ ์ƒํƒœ๋ฅผ ์ฒดํฌํ•จ
    โ€ฃ ์ƒˆ๋กœ ์ƒ์„ฑ๋œ Pod์„ ๊ฐ์ง€ํ•˜๊ณ  ์‹คํ–‰ํ•  ๋…ธ๋“œ๋ฅผ ์„ ํƒํ•จ. (ํ• ๋‹น์š”์ฒญ Pod์„ ํ™•์ธํ•จ)
    โ€ฃ ๋…ธ๋“œ์˜ ํ˜„์žฌ ์ƒํƒœ์™€ Pod์˜ ์š”๊ตฌ์‚ฌํ•ญ์„ ์ฒดํฌํ•จ

โ– API Server
    โ€ฃetcd ์™€ ์œ ์ผํ•˜๊ฒŒ ํ†ต์‹ ํ•˜๋Š” ๋ชจ๋“ˆ **
    โ€ฃ ์ƒํƒœ๋ฅผ ๋ฐ”๊พธ๊ฑฐ๋‚˜ ์กฐํšŒํ•˜๋Š” ๊ธฐ๋Šฅ (์กฐํšŒ ๋ฐ ์š”์ฒญ์€ ๋ฌด์กฐ๊ฑด API Server์„ ํ†ตํ•ด์„œ ํ•จ)
    โ€ฃ REST API ํ˜•ํƒœ๋กœ ์ œ๊ณต
    โ€ฃ ๊ถŒํ•œ์ฒดํฌ, ๊ด€๋ฆฌ์ž ์š”์ฒญ ๋ฟ ์•„๋‹ˆ๋ผ ๋‹ค์–‘ํ•œ ๋‚ด๋ถ€ ๋ชจ๋“ˆ๊ณผ ํ†ต์‹ ํ•จ
    โ€ฃ ์ˆ˜ํ‰์œผ๋กœ ํ™•์žฅ๋˜๋„๋ก ๋””์ž์ธ

โ– etcd
    โ€ฃ ์ƒํƒœ ๋ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ (๋‚ ๋ผ๊ฐ€์ง€์•Š๊ฒŒ,, ๋ณดํ†ต 3๋Œ€๋กœ ๊ด€๋ฆฌ,, ๋ฐฑ์—… ํ•„์ˆ˜)
    โ€ฃ ๋ณต๊ตฌ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•จ
    โ€ฃ ๊ณ ๊ฐ€์šฉ์„ฑ, ์ผ๊ด€์„ฑ
    โ€ฃ Key, Value ํ˜•ํƒœ ๋ฐ TTL(time to live), watch ๊ฐ™์€ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ ์ œ๊ณต

 

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋…ธ๋“œ(Node) ์ปดํฌ๋„ŒํŠธ

โ–ช๏ธŽ ์ปจํ…Œ์ด๋„ˆํ™”๋œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰
โ–ช๏ธŽ ํด๋Ÿฌ์Šคํ„ฐ์— ๋”ฐ๋ผ ๊ฐ€์ƒ or ๋ฌผ๋ฆฌ์ ์ผ ์ˆ˜ ์žˆ๋‹ค.
โ–ช๏ธŽControl Plain ์— ์˜ํ•ด ๊ด€๋ฆฌ๋˜๋ฉฐ, Pod์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์„œ๋น„์Šค๋ฅผ ํฌํ•จํ•จ.
โ–ช๏ธŽ ํ•˜๋‚˜์˜ ํด๋Ÿฌ์Šคํ„ฐ์—๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋…ธ๋“œ๊ฐ€ ์กด์žฌ.

    โ– kubelet
        โ€ฃ Pod ์„ ์‹คํ–‰/์ค‘์ง€ํ•˜๊ณ  ์ƒํƒœ๋ฅผ ์ฒดํฌํ•จ (๊ฐ ๋…ธ๋“œ์—์„œ ์‹คํ–‰, ๋ฏธ์‹คํ–‰ Pod์„ ํ™•์ธํ•˜์—ฌ Pod์„ ์ƒ์„ฑํ•จ)
        โ€ฃ ๋‹ค ์‹คํ–‰๋˜์–ด ์žˆ์–ด์•ผ ํ•จ.
        โ€ฃ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ง์ ‘ ์“ฐ์ง€ ์•Š๊ณ  Pod๋ผ๋Š” ๊ฑธ๋กœ ๊ฐ์‹ธ์„œ ์‚ฌ์šฉํ•จ.

    โ– kube-proxy
        โ€ฃ ๋„คํŠธ์›Œํฌ ํ”„๋ก์‹œ์™€ ๋ถ€ํ•˜ ๋ถ„์‚ฐ ์—ญํ• , iptables or IPVS์„ ์‚ฌ์šฉ (์„ค์ •๋งŒ ๊ด€๋ฆฌ)
 
    โ– ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„
        โ€ฃ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์„ ๋‹ด๋‹นํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด  

 

Kubectl

โ–ช๏ธŽ ๋ช…๋ นํ˜• ์ปค๋งจ๋“œ.. ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•จ

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์˜ค๋ธŒ์ ํŠธ

https://www.youtube.com/watch?v=-gIyfII5eak&t=5s

โ– Pod
    โ€ฃ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ ๊ฐ€์žฅ ์ž‘์€ ์ปดํ“จํŒ… ๋‹จ์œ„
    โ€ฃ ์ „์ฒด ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ๊ณ ์œ ํ•œ IP์„ ํ• ๋‹น (Pod ๋ณ„๋กœ IP ํ• ๋‹น)
    โ€ฃ ํ•˜๋‚˜์˜ Pod ์•ˆ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ ์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

โ– ReplicaSet
    โ€ฃ Pod์„ ๋‹จ๋…์œผ๋กœ ๋งŒ๋“ ์ƒํ™ฉ์—์„œ pod๊ฐ€ ์‚ฌ๋ผ์ง€๋Š”๊ฒฝ์šฐ(์„œ๋ฒ„๊ฐ€์ฃฝ์Œ) ์ž๋™๋ณต๊ตฌ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋ฐ, ์ด๋Ÿฌํ•œ pod์„ ์ž๋™ ๋ณต์ œ ๊ด€๋ฆฌํ•ด์ฃผ๋Š”๊ฒƒ.
    โ€ฃ ์—ฌ๋Ÿฌ๊ฐœ์˜ Pod ์„ ๊ด€๋ฆฌ (๋ช‡๊ฐœ์˜ Pod์„ ๊ด€๋ฆฌํ• ์ง€ ๊ฒฐ์ •)
    โ€ฃ ๋ฌด์ค‘๋‹จ๋ฐฐํฌ ํ•˜๊ณ ์‹ถ์„๋•Œ ์‚ฌ์šฉ
    โ€ฃ ์‹ ๊ทœ Pod์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ๊ธฐ์กด์˜ Pod์„ ์ œ๊ฑฐํ•˜์—ฌ ์›ํ•˜๋Š” ์ˆ˜ (Replicas)์„ ์œ ์ง€


โ– Deployment
    โ€ฃ ๋ฐฐํฌ๋ฒ„์ „ ๊ด€๋ฆฌ (ReplicaSet์„ ์ด์šฉํ•˜์—ฌ ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ํ•จ)
    โ€ฃ ๋‚ด๋ถ€์ ์œผ๋กœ ReplicaSet ์„ ์ด์šฉํ•จ

โ– Workload
    โ€ฃ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ Pod ์‹คํ–‰์ค‘ ์ง‘ํ•ฉ ๋‚˜ํƒ€๋ƒ„

โ– Service
    โ€ฃ ํŒŒ๋“œ ์ง‘ํ•ฉ์—์„œ ์‹คํ–‰์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋„คํŠธ์›Œํฌ ์„œ๋น„์Šค๋กœ ๋…ธ์ถœํ•˜๋Š” ์ถ”์ƒํ™” ๋ฐฉ๋ฒ•.
    โ€ฃ Pod ์„ ์—ฐ๊ฒฐํ•˜๊ณ  ์™ธ๋ถ€์— ๋…ธ์ถœ

โ– Service > ClusterIP
    โ€ฃ Pod์„ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ํ•˜๋Š” ์„œ๋น„์Šค
    โ€ฃ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋ก์‹œ 
    โ€ฃ Pod๋Š” ๋™์ ์ด์ง€๋งŒ, Service๋Š” ๊ณ ์œ  IP์„ ๊ฐ€์ง
    โ€ฃ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด๋ถ€์—์„œ ์„œ๋น„์Šค ์—ฐ๊ฒฐ์€ DNS ์ด์šฉ

โ– Service > NodePort
    โ€ฃ ๋…ธ๋“œ์— ๋…ธ์ถœ๋˜์–ด ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ์„œ๋น„์Šค (๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ ‘๊ทผ ๊ฐ€๋Šฅ ๋“ฑ)
    โ€ฃ ๋ชจ๋“  ๋…ธ๋“œ์— ๋™์ผํ•œ ํฌํŠธ๋กœ ์ƒ์„ฑ

โ– Service > LoadBalancer
    โ€ฃ ํ•˜๋‚˜์˜ IP์ฃผ์†Œ๋ฅผ ์™ธ๋ถ€์— ๋…ธ์ถœ

โ– Ingress
    โ€ฃ URL, path ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ… ์ •์˜ 
    โ€ฃ SSL ๋ณด์•ˆ ์—ฐ๊ฒฐ

    โ€ฃ domain path์— ๋”ฐ๋ผ ๋‚ด๋ถ€ ClusterIp์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋„๋ก ์ฒ˜๋ฆฌ
    โ€ฃ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์˜ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์™ธ๋ถ€ ์ ‘๊ทผ์„ ๊ด€๋ฆฌํ•˜๋Š” API ์˜ค๋ธŒ์ ํŠธ์ด๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ HTTP์„ ๊ด€๋ฆฌํ•จ.

โ– Volume 
    โ€ฃ ๋ฐ์ดํ„ฐ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ์ด๋ฉฐ, Pod์˜ ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅ.

โ– ConfigMap
    โ€ฃ key-value ์Œ์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” API ์˜ค๋ธŒ์ ํŠธ.
    โ€ฃ ์„ค์ • ๊ฐ’์„ Pod ์— ์ „๋‹ฌ
    โ€ฃ ์ปจํ…Œ์ด๋„ˆ ์„ค์ • ์ •๋ณด๋ฅผ ์ €์žฅ ํ•ด ๋†“๋Š” ์ผ์ข…์˜ ์ €์žฅ์†Œ (key / value ํ˜•์‹)
    โ€ฃ ์ปจํ…Œ์ด๋„ˆ์—์„œ ํ•„์š”ํ•œ ํ™˜๊ฒฝ ์„ค์ • ๋‚ด์šฉ์„ ์ปจํ…Œ์ด๋„ˆ์™€ ๋ถ„๋ฆฌํ•ด์„œ ์ œ๊ณต
    โ€ฃ ์„ค์ • ๊ฐ’์ด ๋ณ€๊ฒฝ๋˜์—ˆ์„ ๋•Œ๋งˆ๋‹ค ์ปจํ…Œ์ด๋„ˆ์˜ ์žฌ๋ฐฐํฌ ์—†์ด ์ ์šฉ ๊ฐ€๋Šฅ


 


 

โ€ป ์ฐธ๊ณ 
- ์ธํ”„๋Ÿฐ ๊ฐ•์˜: ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ

 

์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ 1๋„ ๋ชจ๋ฅด๋Š” ์ž…๋ฌธ์ž, ์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ ์ž…๋‹ˆ๋‹ค. ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ๋‚ด์šฉ๊ณผ ํ๋ฆ„์œผ๋กœ ๊ตฌ์„ฑํ–ˆ์–ด์š”., - ๊ฐ•์˜ ์†Œ๊ฐœ | ์ธํ”„๋Ÿฐ...

www.inflearn.com

- ์ฑ…: ์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•์„ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค / ๋„์ปค 

 

์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•์„ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค/๋„์ปค - ๊ต๋ณด๋ฌธ๊ณ 

์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ์„ ์ดํ•ดํ•˜๊ณ  ์ง์ ‘ ๊ตฌ์ถ•ํ•ด ๋ณด์ž! | ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์™€ ๋„์ปค๋ฅผ ํ™œ์šฉํ•œ ์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•!์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ์„ ์ง€์›ํ•˜๋Š” ๋„๊ตฌ๋“ค์„ ์œ ๊ธฐ์ ์œผ๋กœ ์—ฐ๊ฒฐํ•ด ์„ค๋ช…ํ•œ๋‹ค์ฟ ๋ฒ„๋„ค

www.kyobobook.co.kr

- ๋งํฌ: https://kubernetes.io/ko/docs/concepts/overview/what-is-kubernetes/

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์ปจํ…Œ์ด๋„ˆํ™”๋œ ์›Œํฌ๋กœ๋“œ์™€ ์„œ๋น„์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ด์‹ํ•  ์ˆ˜ ์žˆ๊ณ , ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ์˜คํ”ˆ์†Œ์Šค ํ”Œ๋žซํผ์œผ๋กœ, ์„ ์–ธ์  ๊ตฌ์„ฑ๊ณผ ์ž๋™ํ™”๋ฅผ ๋ชจ๋‘ ์ง€์›ํ•œ๋‹ค. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ํฌ๊ณ  ๋น ๋ฅด๊ฒŒ ์„ฑ์žฅํ•˜

kubernetes.io

- ๋งํฌ: https://subicura.com/2019/05/19/kubernetes-basic-1.html

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

 

์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ (container orchestration)

์„ค๋ช…

โ—ฆ ๋ณต์žกํ•œ ์ปจํ…Œ์ด๋„ˆ ํ™˜๊ฒฝ์„ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌ ํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ
โ—ฆ ์„œ๋ฒ„ ๊ด€๋ฆฌ์ž๊ฐ€ ํ•ด์•ผํ•˜๋Š” ์ผ์„ ๋Œ€์‹  ํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ๋Š”๊ฒƒ
โ—ฆ ๋ณต์žกํ•œ ๋‹จ๊ณ„๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์š”์†Œ๋“ค์˜ ์œ ๊ธฐ์ ์ธ ๊ด€๊ณ„๋ฅผ ๋ฏธ๋ฆฌ ์ •์˜ ํ•ด ์†์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์„œ๋น„์Šค
โ—ฆ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ์ด์˜ ํ‘œ์ค€์ด๋ผ๊ณ  ํ•จ.

โ€ป ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜
์„œ๋ฒ„ ๊ตฌ์„ฑ ๊ด€๋ฆฌ ์ž๋™ํ™” = ์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ๊ณผ ์†Œํ”„ํŠธ์›จ์–ด์˜ ์ž๋™ํ™”๋œ ๊ตฌ์„ฑ, ์กฐ์œจ ๊ด€๋ฆฌ
๊ด€๋ จ ๋„๊ตฌ๋กœ Ansible, Puppet, Salt, ํ…Œ๋ผํผ, AWS CloudeFormation..

..์ปจํ…Œ์ด๋„ˆ ๊ด€๋ฆฌ๋ฅผ ์ž๋™ํ™” ํ•œ๋‹ค๋Š” ๊ฒƒ?

 

ํŠน์ง•

โ—ฆ ํด๋Ÿฌ์Šคํ„ฐ ๋‹จ์œ„ ๊ด€๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. (๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์—์„œ ๊ฐ ๋…ธ๋“œ๋ณ„ ๊ด€๋ฆฌ..)
โ—ฆ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ฐ€๋Šฅ
โ—ฆ ๋ฐฐํฌ๊ด€๋ฆฌ ์•Œ์•„์„œ ํ•จ
โ—ฆ ์„œ๋ฒ„ ๋กค๋ฐฑ๋“ฑ์„ ์ค‘์•™์—์„œ ๊ด€๋ฆฌํ•จ
โ—ฆ ์ƒˆ๋กœ ๋“ฑ๋ก๋˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝ๋˜๋Š” ์„œ๋ฒ„ IP๋ฅผ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌํ•ด์คŒ 
โ—ฆ ๋ณผ๋ฅจ ์Šคํ† ๋ฆฌ์ง€ ๋งˆ์šดํŠธ ์„ค์ • ๊ฐ€๋Šฅ

โ€ป ํด๋Ÿฌ์Šคํ„ฐ
์—ฌ๋Ÿฌ๋Œ€์˜ ์„œ๋ฒ„๋“ค์„ ํ•˜๋‚˜์˜ ์‹œ์Šคํ…œ์œผ๋กœ ๋™์ž‘ํ•˜๊ฒŒ ํ•จ์œผ๋กœ์จ, ํด๋ผ์ด์–ธํŠธ๋“ค์—๊ฒŒ ๊ณ ๊ฐ€์šฉ์„ฑ(=์˜ค๋žœ๊ธฐ๊ฐ„๋™์•ˆ ์ •์ƒ์šด์˜ ๊ฐ€๋Šฅ)์„ ์ œ๊ณต

ใƒป ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ = ๋…ธ๋“œ๋จธ์‹  (์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์œ„ํ•จ) ์˜ ์›Œ์ปค ๋จธ์‹ ์˜ ์ง‘ํ•ฉ
→ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์‹คํ–‰์ค‘ ? ํด๋Ÿฌ์Šคํ„ฐ ์‹คํ–‰์ค‘ !

 

 


 

โ€ป ์ฐธ๊ณ 
- inflearn: ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ

 

์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ 1๋„ ๋ชจ๋ฅด๋Š” ์ž…๋ฌธ์ž, ์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ๋‚ด์„œ ์ž…๋‹ˆ๋‹ค. ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ๋‚ด์šฉ๊ณผ ํ๋ฆ„์œผ๋กœ ๊ตฌ์„ฑํ–ˆ์–ด์š”., - ๊ฐ•์˜ ์†Œ๊ฐœ | ์ธํ”„๋Ÿฐ...

www.inflearn.com

- book: ์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•์„ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค / ๋„์ปค 

 

์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•์„ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค/๋„์ปค - ๊ต๋ณด๋ฌธ๊ณ 

์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ์„ ์ดํ•ดํ•˜๊ณ  ์ง์ ‘ ๊ตฌ์ถ•ํ•ด ๋ณด์ž! | ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์™€ ๋„์ปค๋ฅผ ํ™œ์šฉํ•œ ์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ ๊ตฌ์ถ•!์ปจํ…Œ์ด๋„ˆ ์ธํ”„๋ผ ํ™˜๊ฒฝ์„ ์ง€์›ํ•˜๋Š” ๋„๊ตฌ๋“ค์„ ์œ ๊ธฐ์ ์œผ๋กœ ์—ฐ๊ฒฐํ•ด ์„ค๋ช…ํ•œ๋‹ค์ฟ ๋ฒ„๋„ค

www.kyobobook.co.kr

- search: https://ko.wikipedia.org/wiki/%EC%98%A4%EC%BC%80%EC%8A%A4%ED%8A%B8%EB%A0%88%EC%9D%B4%EC%85%98_(%EC%BB%B4%ED%93%A8%ED%8C%85) 

 

์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ (์ปดํ“จํŒ…) - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์‹œ์Šคํ…œ ๊ด€๋ฆฌ์—์„œ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜(ochestration)์€ ์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ๊ณผ ์†Œํ”„ํŠธ์›จ์–ด์˜ ์ž๋™ํ™”๋œ ๊ตฌ์„ฑ, ์กฐ์œจ, ๊ด€๋ฆฌ์ด๋‹ค.[1] ์„œ๋ฒ„ ๊ตฌ์„ฑ๊ณผ ๊ด€๋ฆฌ ์ž๋™ํ™”๋ฅผ ์œ„ํ•œ ์ˆ˜๋งŽ์€ ๋„๊ตฌ๊ฐ€ ์กด์žฌํ•˜๋ฉฐ ์—ฌ๊ธฐ์—๋Š” Ansible, Puppet,

ko.wikipedia.org

https://wooody92.github.io/kubernetes/Kubernetes-%EC%BB%A8%ED%85%8C%EC%9D%B4%EB%84%88-%EC%98%A4%EC%BC%80%EC%8A%A4%ED%8A%B8%EB%A0%88%EC%9D%B4%EC%85%98/

 

Kubernetes - ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜

์†Œ๊ฐœ์™€ ๋ฐฐ๊ฒฝ ๊ทธ๋ฆฌ๊ณ  ํŠน์ง•

wooody92.github.io

https://www.redhat.com/ko/topics/containers/what-is-a-kubernetes-cluster

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ(Kubernetes cluster)์˜ ๊ฐœ๋…, ๊ตฌ์„ฑ ๋ฐ ๊ด€๋ฆฌ

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ž€ ์ปจํ…Œ์ด๋„ˆํ™”๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š” ๋…ธ๋“œ๋ฅผ ๋œปํ•˜๋ฉฐ, ์˜จํ”„๋ ˆ๋ฏธ์Šค, ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํด๋ผ์šฐ๋“œ ๋“ฑ์„ ์œ„ํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

www.redhat.com

https://ko.wikipedia.org/wiki/%EC%BB%B4%ED%93%A8%ED%84%B0_%ED%81%B4%EB%9F%AC%EC%8A%A4%ED%84%B0

 

์ปดํ“จํ„ฐ ํด๋Ÿฌ์Šคํ„ฐ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์ปดํ“จํ„ฐ ํด๋Ÿฌ์Šคํ„ฐ(์˜์–ด: computer cluster)๋Š” ์—ฌ๋Ÿฌ ๋Œ€์˜ ์ปดํ“จํ„ฐ๋“ค์ด ์—ฐ๊ฒฐ๋˜์–ด ํ•˜๋‚˜์˜ ์‹œ์Šคํ…œ์ฒ˜๋Ÿผ ๋™์ž‘ํ•˜๋Š” ์ปดํ“จํ„ฐ๋“ค์˜ ์ง‘ํ•ฉ์„ ๋งํ•œ๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ตฌ์„ฑ ์š”์†Œ๋“ค์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ณ ์†์˜ ๊ทผ๊ฑฐ๋ฆฌ ํ†ต์‹ ๋ง์œผ

ko.wikipedia.org

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
์ƒํ™ฉ

vagrant up ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ master node, worker node ๋“ฑ์„ ์‹คํ–‰ํ•˜๋ ค๊ณ  ํ•˜์˜€๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•จ.
(์ด์ฑ…์œผ๋กœ ํ•™์Šต์ค‘ ์ด์˜€๊ณ .., ๋‚˜๋Š” mac ์œ ์ €์˜€๋œธ..)

๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๋‹ˆ VirtualBox ๋ฒ„์ „์„ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ๋ฅผ ํ•ด์•ผํ•œ๋‹ค๋Š” ๋‚ด์šฉ๋“ฑ๋“ฑ ๋ฐœ๊ฒฌํ•˜๊ธดํ•˜์˜€๋œธ.. 

 

ํ•ด๊ฒฐ

private_network ์ •๋ณด๋ฅผ 192.168.1.10 ์—์„œ 192.168.56.10 ์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ ์šฉํ•˜์—ฌ ๋‹ค์‹œ ์‹คํ–‰ํ•˜์˜€๋”๋‹ˆ ์—๋Ÿฌ ๋ฐœ์ƒ ํ•˜์ง€ ์•Š๊ฒŒ๋จ.

๊ทธ๋ ‡๊ฒŒ ํ•œ ์ด์œ ๋Š” virtualbox ์‚ฌ์ดํŠธ ๊ด€๋ จ ๋ฌธ์„œ ๋‚ด์šฉ์ค‘์ด ์ด๋Ÿฌํ•œ ๋‚ด์šฉ์„ ๋ฐœ๊ฒฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ..,
>> Linux, Mac OS X ๋ฐ Solaris Oracle VM VirtualBox๋Š” 192.168.56.0/21 ๋ฒ”์œ„์˜ IP ์ฃผ์†Œ๋งŒ ํ˜ธ์ŠคํŠธ ์ „์šฉ ์–ด๋Œ‘ํ„ฐ์— ํ• ๋‹นํ•˜๋„๋ก ํ—ˆ์šฉํ•œ๋‹ค๋Š” ๋‚ด์šฉ..

 


 

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
json web token
์„ค๋ช…

JSON ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ† ํฐ ์ž์ฒด์— ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ์›นํ† ํฐ.
claims์„ ์•ˆ์ „ํ•˜๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ํ‘œ์ค€.
HMAC ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‚ฌ์šฉ ํ•˜๊ฑฐ๋‚˜, RSA or ECDSA๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณต๊ฐœ / ๊ฐœ์ธํ‚ค ์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ช…์ด ๊ฐ€๋Šฅํ•จ.
๊ถŒํ•œ ๋ถ€์—ฌ ๋ฐ ์ •๋ณด๊ตํ™˜์‹œ์ ์—์„œ ์‚ฌ์šฉ.

โœณ๏ธŽ claims ?
JWT ์˜ PAYLOAD ๋ถ€๋ถ„์„ ๊ตฌ์„ฑํ•˜๊ณ  ๊ตํ™˜๋˜๋Š” ์ •๋ณด ์ง‘ํ•ฉ.

 

ํ† ํฐ์ƒ๊น€์ƒˆ
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0IiwiYXV0aCI6IlJPTEVfVVNFUiIsImV4cCI6MTY0MDI2NjczOX0.A5bzyF4jkKVmdDzboK8_qsPbDh3qGO3v2lgcSp5K41CxmSgyDZlKxBfcZNiZ754S_IDhFOPO7m18bsBqhZgBMw

์œ„์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ƒ๊ฒผ์œผ๋ฉฐ, https://jwt.io/ ์‚ฌ์ดํŠธ์—์„œ ํ† ํฐ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๊ตฌ์„ฑ๋ฐฉ์‹

HEADER, PAYLOAD, SIGNITURE ์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. 
์ด ์„ธ๋ถ€๋ถ„์€ Base64url ์ธ์ฝ”๋”ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ„๋„๋กœ ์ธ์ฝ”๋”ฉ๋˜๋ฉฐ JWT ์ƒ์„ฑ์„ ์œ„ํ•˜ ์ (.)์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐ๋œ๋‹ค. 

var token = base64UrlEncoding(HEADER) + '.' + base64UrlEncoding(PAYLOAD) + '.' + base64UrlEncoding(SIGNITURE);

↓↓↓↓

var token = 
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0IiwiYXV0aCI6IlJPTEVfVVNFUiIsImV4cCI6MTY0MDI2NjczOX0.A5bzyF4jkKVmdDzboK8_qsPbDh3qGO3v2lgcSp5K41CxmSgyDZlKxBfcZNiZ754S_IDhFOPO7m18bsBqhZgBMw

 

๊ฐ ๊ตฌ์„ฑ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

HEADER signiture ์ •๋ณด๋ฅผ ํ•ด์‹ฑํ•˜๊ธฐ ์œ„ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ •๋ณด๋“ค์ด ๋‹ด๊ฒจ์žˆ๋Š”๊ณณ.
HMAC, SHA256 or RSA ์™€ ๊ฐ™์€ ์„œ๋ช… ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๊ตฌ์„ฑ๋จ.
PAYLOAD ์„œ๋ฒ„, ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ฃผ๊ณ  ๋ฐ›๋Š” ์‹œ์Šคํ…œ์—์„œ ์‹ค์ œ๋กœ ์‚ฌ์šฉ๋  ์ •๋ณด์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ๋‹ด๊ฒจ์žˆ์Œ.
PAYLOAD claims ์€ 3๊ฐ€์ง€ ์œ ํ˜•์ด ์กด์žฌ

- registered claims: ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ ์ƒํ˜ธ ์šด์šฉ์„ ์œ„ํ•ด ๋ฏธ๋ฆฌ ์ •์˜๋œ ํด๋ ˆ์ž„(RFC 7519) ์ง‘ํ•ฉ (iss, exp, sub, aud..)

- public claims: jwt ์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ๋งˆ์Œ๋Œ€๋กœ ์ •์˜. ์ถฉ๋Œ ๋ฐฉ์ง€ ์œ„ํ•ด ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํฌํ•จํ•˜๋Š” URL๋กœ ์ •์˜ ํ•„์š”

- private claims: ์‚ฌ์šฉ์— ๋™์˜ํ•˜๊ณ  ๋“ฑ๋ก๋œ ํด๋ ˆ์ž„์ด๋‚˜ ๊ณต๊ฐœ ํด๋ ˆ์ž„์ด ์•„๋‹Œ ๋‹น์‚ฌ์ž๊ฐ„์˜ ์ •๋ณด๋ฅผ ๊ณต์œ ํ•˜๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ๋œ ๋งž์ถค ํด๋ ˆ์ž„
SIGNITURE ํ† ํฐ์˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ์œ„ํ•œ ๋ฌธ์ž์—ด. ์ด ๋ฌธ์ž์—ด๋กœ ์œ ํšจํ•œ ํ† ํฐ์ธ์ง€ ํ™•์ธํ•จ.
๋ฉ”์„ธ์ง€๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ.

 

 

๋™์ž‘๋ฐฉ์‹

jwt ํ† ํฐ ์ธ์ฆ ๋ฐฉ์‹ ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ ค๋ณธ๊ฒƒ์ด๋‹ค. (oauth2์˜ ํ—ˆ๊ฐ€๋Š” ์ƒ๋žต)

accessToken, refreshToken์ด jwt ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋‹ค.

 

์žฅ์ ๊ณผ ๋‹จ์ 
  • ์žฅ์ 
    ์ค‘์•™์˜ ์ธ์ฆ์„œ๋ฒ„, ๋ฐ์ดํ„ฐ ์Šคํ† ์–ด์— ๋Œ€ํ•œ ์˜์กด์„ฑ์ด ์—†๊ณ , ์‹œ์Šคํ…œ ์ˆ˜ํ‰ํ™•์žฅ์— ์œ ๋ฆฌํ•˜๋‹ค.

  • ๋‹จ์ 
    PAYLOAD ์ •๋ณด๊ฐ€ ๋งŽ์•„์ง€๋ฉด ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉ๋Ÿ‰์ด ์ฆ๊ฐ€ํ•จ.
    ํ† ํฐ์ด ํด๋ผ์ด์–ธํŠธ์— ์ €์žฅ๋˜๊ธฐ์— ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ์˜ ํ† ํฐ์„ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 


์ฐธ์กฐ

https://jwt.io/introduction

 

JWT.IO

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

jwt.io

https://ko.wikipedia.org/wiki/JSON_%EC%9B%B9_%ED%86%A0%ED%81%B0

 

JSON ์›น ํ† ํฐ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

JSON ์›น ํ† ํฐ์ƒํƒœ์ธํ„ฐ๋„ท ํ‘œ์ค€์ตœ์ดˆ ์ถœํŒ์ผ2010๋…„ 12์›” 28์ผ (2010-12-28)๋งˆ์ง€๋ง‰ ๋ฒ„์ „RFC 75192015๋…„ 5์›”์กฐ์งIETF์•ฝ์–ดJWT JSON ์›น ํ† ํฐ(JSON Web Token, JWT, "jot”[1])์€ ์„ ํƒ์  ์„œ๋ช… ๋ฐ ์„ ํƒ์  ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ

ko.wikipedia.org

https://velog.io/@kshired/Express%EC%97%90%EC%84%9C-JWT%EB%A1%9C-%EC%9D%B8%EC%A6%9D%EC%8B%9C%EC%8A%A4%ED%85%9C-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0-Access-Token%EA%B3%BC-Refresh-Token

 

Express์—์„œ JWT๋กœ ์ธ์ฆ์‹œ์Šคํ…œ ๊ตฌํ˜„ํ•˜๊ธฐ ( Access Token๊ณผ Refresh Token )

Express์—์„œ jwt๋ฅผ ์ด์šฉํ•˜์—ฌ access token์œผ๋กœ๋งŒ ์ธ์ฆ์„ ํ•˜๋Š” ๊ธ€์€ ๋งŽ์ด ์žˆ๋Š”๋ฐ, refresh token๊นŒ์ง€ ๊ตฌํ˜„ํ•œ ์ž๋ฃŒ๋Š” ๊ทธ๋ ‡๊ฒŒ ๋งŽ์ง€์•Š์•„ ์ด ๊ธ€์„ ์“ฐ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.์ด ๊ธ€์€ ๊ตฌํ˜„์— ์น˜์ค‘๋˜์–ด ์žˆ์–ด, JWT์˜ ์ž์„ธํ•œ

velog.io

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-jwt/dashboard

 

[๋ฌด๋ฃŒ] Spring Boot JWT Tutorial - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

Spring Boot, Spring Security, JWT๋ฅผ ์ด์šฉํ•œ ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ์ธ์ฆ๊ณผ ์ธ๊ฐ€์— ๋Œ€ํ•œ ๊ธฐ์ดˆ ์ง€์‹์„ ์‰ฝ๊ณ  ๋น ๋ฅด๊ฒŒ ํ•™์Šตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค., [์‚ฌ์ง„] ๋ณธ ๊ฐ•์˜๋Š” Spring Boot, Spring Security๋ฅผ ์ด์šฉํ•ด์„œ JWT ์ธ์ฆ๊ณผ ์ธ๊ฐ€๋ฅผ ์‰ฝ

www.inflearn.com

https://techdocs.akamai.com/api-gateway/docs/json-web-token-jwt-val#jwt-claims

 

JSON web token (JWT) validation

JSON web token is an open standard (RFC 7519) that defines a compact and self-contained method for securely transmitting JSON-encoded information between parties. With <<COMPANY_NICKNAME>>, you can use JWTs to quickly identify and authorize API consumers w

techdocs.akamai.com

 

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SSE (Server Sent Event)  (1) 2023.08.20
Vault  (1) 2023.02.07
ํ—ฅ์‚ฌ๊ณ ๋‚  ์•„ํ‚คํ…์ฒ˜ (Hexagonal Architecture)  (2) 2022.09.25
Rest API  (0) 2021.06.02
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09
๋ฐ˜์‘ํ˜•
ํŠธ๋žœ์žญ์…˜
์„ค๋ช…

๋‘๊ฐœ ์ด์ƒ์˜ ์ฟผ๋ฆฌ๋ฅผ ํ•œ ์ž‘์—…์œผ๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ 
ํŠธ๋žœ์žญ์…˜์œผ๋กœ ๋ฌถ์ธ ์ฟผ๋ฆฌ ์ค‘ ํ•˜๋‚˜๋ผ๋„ ์‹คํŒจํ•˜๋ฉด ์ „์ฒด ์‹คํŒจ๋กœ ๊ฐ„์ฃผ -> ๊ธฐ์กด์ƒํƒœ๋กœ ๋˜๋Œ๋ฆผ (rollback)
ํŠธ๋žœ์žญ์…˜์œผ๋กœ ๋ฌถ์ธ ์ฟผ๋ฆฌ๊ฐ€ ๋ชจ๋‘ ์„ฑ๊ณตํ•  ๊ฒฝ์šฐ -> ์‹ค์ œ๋ฐ˜์˜ (commit)

 

@Transactional
์„ค๋ช…

์Šคํ”„๋ง์—์„œ ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜ 
ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉํ•จ.
์ œ๋Œ€๋กœ๋œ ๋™์ž‘์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” PlatformTransactionManager ๋นˆ ์„ค์ • & @Transactional ์–ด๋…ธํ…Œ์ด์…˜ ํ™œ์„ฑํ™” ์„ค์ • ์ด ํ•„์š”

PlatformTransactionManager
- ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ์— ํ•„์š”ํ•œ API ์ œ๊ณต
- ๊ฐœ๋ฐœ์ž๊ฐ€ API๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํŠธ๋žœ์žญ์…˜ ์กฐ์ž‘์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.
- ๋Œ€ํ‘œ์ ์ธ ๊ตฌํ˜„ ํด๋ž˜์Šค: DataSourceTransactionManager, HibernateTransactionManager, JpaTransactionManager, JtaTransactionManager, WebLogicJtaTransactionManager, WebSphereUowTransactionManager
@Transactional ์–ด๋…ธํ…Œ์ด์…˜ ํ™œ์„ฑํ™” ์„ค์ •
 - @EnableTransactionManagement ์–ด๋…ธํ…Œ์ด์…˜์„ ์ด์šฉํ•˜์—ฌ @Transactional ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”
- ๋“ฑ๋ก๋œ PlatformTransactionManager ๋นˆ์„ ์‚ฌ์šฉํ•ด์„œ ํŠธ๋žœ์žญ์…˜์„ ์ ์šฉํ•œ๋‹ค.

 

@Transactional๊ณผ ํ”„๋ก์‹œ

์Šคํ”„๋ง์€ ํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด๋ถ€์ ์œผ๋กœ AOP์„ ์ด์šฉํ•จ!

 

..

 

 

ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ์ž ์ •์˜

๋กœ์ปฌํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ JDBC API ํ˜ธ์ถœ, ํŠธ๋žœ์žญ์…˜ ์ œ์–ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” DataSourceTransactionManager์„ ์‚ฌ์šฉํ•œ๋‹ค.
๋‹จ์ผ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ ์กฐ์ž‘์„ ํ•˜๋‚˜์˜ ๋…ผ๋ฆฌ์  ๋‹จ์œ„๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉ

๊ธ€๋กœ๋ฒŒํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ(์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ์— ๊ฑธ์ณ์„œ ์ ์šฉ๋˜๋Š” ๊ฒฝ์šฐ: DB๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ด๊ณ , ๊ฐ๊ฐ ์กฐ์ž‘ ์ˆ˜ํ–‰ ๋‹จ์œ„๋ฅผ ํ•˜๋‚˜์˜ ํŠธ๋ž˜์žญ์…˜์œผ๋กœ ๋ฌถ๋Š” ๊ฒฝ์šฐ) JtaTransactionManager ์„ ์‚ฌ์šฉ

 

 

์„ ์–ธ์  ํŠธ๋žœ์žญ์…˜ 
์„ค๋ช…

commit, rollback ๋“ฑ์˜ ์ฒ˜๋ฆฌ๋ฅผ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์— ์„œ์ˆ ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• (@Transactional)

ํ•„์š”์ •๋ณด

value
transactionManager
propagation
isolation
timeout
readOnly
rollbackFor
rollbackForClassName
noRollbackFor
noRollbackForClassName

.....

 

๋ช…์‹œ์  ํŠธ๋žœ์žญ์…˜
์„ค๋ช…

์ปค๋ฐ‹์ด๋‚˜ ๋กค๋ฐฑ๊ณผ ๊ฐ™์€ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ฅผ ์†Œ์Šค์ฝ”๋“œ์— ์ง์ ‘ ๋ช…์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•.
๋ฉ”์„œ๋“œ ๋‹จ์œ„๋ณด๋‹ค ๋” ์ž‘์€ ๋‹จ์œ„๋กœ ํŠธ๋žœ์žญ์…˜์„ ์ œ์–ดํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉ.
PlatformTransactionManager, TransactionTemplate์„ ์‚ฌ์šฉํ•˜๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ• ์ œ๊ณต

....

 

ํŠธ๋žœ์žญ์…˜ ๊ฒฉ๋ฆฌ์ˆ˜์ค€
์„ค๋ช…

๋™์‹œ์— DB์— ์ ‘๊ทผํ•  ๋•Œ ๊ทธ ์ ‘๊ทผ์„ ์–ด๋–ป๊ฒŒ ์ œ์–ดํ• ์ง€์— ๋Œ€ํ•œ ์„ค์ •์„ ๋‹ค๋ฃธ.
DEFAULT, READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE
....

 

 

 

 


์ฐธ๊ณ 

(์ฑ…) ์ดˆ๋ณด ์›น ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ์Šคํ”„๋ง5 ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ž…๋ฌธ
(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
์ž๋ฐ”๋Š” call by value (๊ฐ’์— ์˜ํ•œ ํ˜ธ์ถœ) ๋ฐฉ์‹์ด๋‹ค.

public class CallTest {

    public static void main(String[] args) {
        String test1 = "test1";
        String test2 = "test2";
        CallTest.callByValue(test1, test2); // ๊ฐ’์— ์˜ํ•œ ์ฐธ์กฐ
        
        // CallTest.callByValue ์—์„œ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ „๋‹ฌ ํ›„ ๋ฐ”๊ฟง๋‹ค ํ•˜์—ฌ, test1, test2์— ์˜ํ–ฅ ์•ˆ๋ฏธ์นจ.
        System.out.println("test1:" + test1+", test2:"+test2); 
    }

    public static void callByValue(String test1, String test2) {
        String temp = test1;
        test1 = test2;
        test2  = temp;
        System.out.println("test1:" + test1+", test2:"+test2);
    }
}

/*
// result)
test1:test2, test2:test1
test1:test1, test2:test2
**/

ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์ „๋‹ฌ!
์ „๋‹ฌํ•œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ!
๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๊ฐ’๋“ค์€ ๊ฐ๊ฐ์˜ ๋‹ค๋ฅธ ๋ฉ”๋ชจ๋ฆฌ ์œ„์น˜์— ์ €์žฅ๋จ. 
ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ ๋ณ€๊ฒฝํ•œ ์‚ฌํ•ญ์€ ํ˜ธ์ถœ์ž์˜ ์‹ค์ œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋ฐ˜์˜๋˜์ง€๋Š” ์•Š์Œ.

 

call by reference (์ฃผ์†Œ์— ์˜ํ•œ ํ˜ธ์ถœ)

๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋™์ผํ•œ ์œ„์น˜๋ฅผ ์ฐธ์กฐํ•˜๋ฏ€๋กœ ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ ๋ณ€๊ฒฝํ•œ ์‚ฌํ•ญ์€ ์‹ค์ œ ํ˜ธ์ถœ์ž์˜ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋ฐ˜์˜๋จ.
ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ์ฃผ์†Œ๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ์‚ฌ์šฉ!
์ฐธ์กฐ์— ์˜ํ•œ ํ˜ธ์ถœ (C++ ํฌ์ธํ„ฐ)

/** 
C++ ์–ธ์–ด์—์„œ ๋ณ€์ˆ˜ ์ฃผ์†Œ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ ํ•˜์˜€์„ ๋•Œ
result) 
test1:test2, test2:test1
test1:test2, test2:test1 // ์ฃผ์†Œ ์ฐธ์กฐ์— ์˜ํ•ด ๊ฐ’์ด ๋ณ€๊ฒฝ ๋จ.
*/

 


์ฐธ๊ณ 

https://www.geeksforgeeks.org/difference-between-call-by-value-and-call-by-reference/

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์–ด๋””์„œ ๋งŽ์ด ๋ณธ ๊ทธ๋ฆผ

 

 

filter
์„ค๋ช…

dispatcherServlet ํ˜ธ์ถœ ์ „, ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ์ „์ฒ˜๋ฆฌ ์ž‘์—…(์›ํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ˜•)์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ. (์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋“ฑ๋ก)
filter chain ์„ ํ†ตํ•ด ์—ฐ์‡„์ ์œผ๋กœ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๊ฐ€๋Šฅ.
์ธ์ฆ, ๊ถŒํ•œ, CORS, ์ธ์ฝ”๋”ฉ, XSS ์ž‘์—…์‹œ ์ด์šฉ

 

 

dispatcherServlet
์„ค๋ช…

ํ”„๋ŸฐํŠธ ์ปจํŠธ๋กค๋Ÿฌ์™€ ์—ฐ๋™๋˜๋Š” ์ง„์ž…์  ์—ญํ• ์„ ํ•˜๋ฉฐ, ๊ธฐ๋ณธ์ ์ธ ์ฒ˜๋ฆฌ ํ๋ฆ„์„ ์ œ์–ดํ•˜๋Š” ์‚ฌ๋ นํƒ‘ ์—ญํ• ์„ ํ•œ๋‹ค. 

โœฟ ํ”„๋ก ํŠธ ์ปจํŠธ๋กค๋Ÿฌ?
ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์„ ํ”„๋ŸฐํŠธ ์ปจํŠธ๋กค๋Ÿฌ๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฐ›์•„ ์š”์ฒญ ๋‚ด์šฉ์— ๋”ฐ๋ผ ์ˆ˜ํ–‰ํ•˜๋Š” ํ•ธ๋“ค๋Ÿฌ(Handler)๋ฅผ ์„ ํƒํ•˜๋Š” ์•„ํ‚คํ…์ฒ˜

 

dispatcherServlet๊ณผ ์—ฐ๋™๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค
์ธํ„ฐํŽ˜์ด์Šค๋ช… ์—ญํ• 
HandlerExceptionResolver ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ธํ„ฐํŽ˜์ด์Šค.
LocaleResolver
LocaleContextResolver
ํด๋ผ์ด์–ธํŠธ Locale ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
ThemeResolver ์Šคํ”„๋ง ํ…Œ๋งˆ๋ฅผ ๊ฒฐ์ •ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
FlashMapManager FlashMap์ด๋ผ๋Š” ๊ฐ์ฒด๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
RequestToViewNameTranslator ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ๋ทฐ ์ด๋ฆ„๊ณผ ๋ทฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์ ์šฉ๋˜๋Š” ๋ทฐ ์ด๋ฆ„์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์Šคํ”„๋ง MVC์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋ณธ ๊ตฌํ˜„ ํด๋ž˜์Šค๊ฐ€ ์ ์šฉ๋˜์–ด ์žˆ๋‹ค.
HandlerInterceptor ํ•ธ๋“ค๋Ÿฌ ์‹คํ–‰ ์ „ํ›„์— ํ•˜๋Š” ๊ณตํ†ต ์ฒ˜๋ฆฌ๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์ด ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ตฌํ˜„ํ•˜๊ณ  ์Šคํ”„๋ง MVC์— ๋“ฑ๋กํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
MultipartResolver ๋ฉ€ํ‹ฐํŒŒํŠธ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์Šคํ”„๋ง MVC์—์„œ ๋ช‡ ๊ฐ€์ง€ ๊ตฌํ˜„ ํด๋ž˜์Šค๊ฐ€ ์ œ๊ณต๋˜๊ณ  ์žˆ์ง€๋งŒ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

 

Handler
์„ค๋ช…

ํ”„๋ ˆ์ž„์›Œํฌ ๊ด€์ ์—์„œ ๋ถˆ๋ฆฌ๋Š” Handler๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž‘์„ฑํ•˜๋Š” ํด๋ž˜์Šค์˜ ๊ด€์ ์—์„œ Controller ์ด๋‹ค.

 

 

HandlerMapping
์„ค๋ช…

์š”์ฒญ์— ๋Œ€์‘ํ•  ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์„ ํƒํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. (์ปจํŠธ๋กค๋Ÿฌ๋‚ด์˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ํ•ธ๋“ค๋Ÿฌ๋กœ ์ธ์‹!)
ํด๋ผ์ด์–ธํŠธ(๋ธŒ๋ผ์šฐ์ €)์—์„œ ์š”์ฒญ์ด ์˜ฌ ๊ฒฝ์šฐ RequestMappingHandlerMapping ํด๋ž˜์Šค๋Š”
์š”์ฒญ ๋‚ด์šฉ(์š”์ฒญ ๊ฒฝ๋กœ ํ˜น์€ HTTP ๋ฉ”์„œ๋“œ)๊ณผ ์š”์ฒญ ๋งคํ•‘ ์ •๋ณด๋ฅผ ๋งค์นญํ•ด์„œ ์‹คํ–‰ํ•  ํ•ธ๋“ค๋Ÿฌ๋ฅด ์„ ํƒํ•œ๋‹ค!

@Controller
class TestController {
    @RequestMapping("/hello")
    public String hello() {
        return "/hi";
    }
    // hello ๋ฉ”์†Œ๋“œ๊ฐ€ ํ•ธ๋“ค๋Ÿฌ!
}

 

 

HandlerAdapter
์„ค๋ช…

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

 

 

ViewResolver
์„ค๋ช…

ํ•ธ๋“ค๋Ÿฌ์—์„œ ๋ฐ˜ํ™˜ํ•œ ๋ทฐ ์ด๋ฆ„์„ ๋ณด๊ณ , ์ดํ›„์— ์‚ฌ์šฉํ•  View ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ตฌํ˜„ ํด๋ž˜์Šค๋ฅผ ์„ ํƒํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 


์ฐธ๊ณ 

(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ
(์ฑ…) ์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ ๋ฐฐ์šฐ๋Š” ์ž๋ฐ” ์›น ๊ฐœ๋ฐœ
https://exhibitlove.tistory.com/7

 

[springboot] Filter ์„ค์ •

์ถœ์ฒ˜ : https://linked2ev.github.io/gitlog/2019/09/15/springboot-mvc-13-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-MVC-Filter-%EC%84%A4%EC%A0%95/ Filter๋ž€? ํ•„ํ„ฐ๋ž€? ๊ฑฐ๋ฅธ๋‹ค๋Š” ๋œป์ด๋‹ค. ์„œ๋ธ”๋ฆฟ์˜ Servl..

exhibitlove.tistory.com

https://stargatex.wordpress.com/2015/12/08/spring-mvc-request-lifecycle/

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[WebSocket] ์›น์†Œ์ผ“  (0) 2022.03.29
ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
IOC/DI, DI์‘์šฉ  (0) 2017.11.20
๋ฐ˜์‘ํ˜•
REST (Representational State Transfer)
์„ค๋ช…

์ž์›์„ ํ‘œํ˜„(Representational)์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ด๋‹น ์ž์›์˜ ์ƒํƒœ(State)๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š”(Transfer)๋‹ค.
HTTP URI(Uniform Resource Identifier)์„ ํ†ตํ•ด ์ž์›(Resource)์„ ๋ช…์‹œํ•˜๊ณ , Http Method(GET, POST, PUT, DELETE)์„ ํ†ตํ•ด ์ž์›์— ๋Œ€ํ•œ CRUD Operation์„ ์ ์šฉ

โœฑ URI (Uniform Resource Identifier)
์ธํ„ฐ๋„ท ์ž์›์„ ๋‚˜ํƒ€๋‚ด๋Š” ์œ ์ผํ•œ ์ฃผ์†Œ
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
 - URN: ์ž์›์˜ ์ด๋ฆ„ (์‹๋ณ„์ž)
 - URL: ์ž์›์˜ ์œ„์น˜ 

 

๊ตฌ์„ฑ์š”์†Œ

1. ์ž์› (Resource)
โ€ฃ Http URI (ex. /users/:userId)

2. ํ–‰์œ„ (Method)
โ€ฃ GET, POST, PUT, DELETE,
โ€ฃ HEAD (์š”์ฒญ header ์ •๋ณด๋งŒ ์‘๋‹ต),
โ€ฃ PATCH (PUT๊ณผ ๋‹ค๋ฅด๊ณ , ์ž์›์˜ ์ผ๋ถ€๋งŒ ์ˆ˜์ •ํ•˜๊ณ ์ž ํ• ๋•Œ ์‚ฌ์šฉ),
โ€ฃ OPTION (ํ˜„์žฌ End-point๊ฐ€ ์ œ๊ณต ๊ฐ€๋Šฅํ•œ API method๋ฅผ ์‘๋‹ต)

3. ํ‘œํ˜„ (Representation of Resource)
  Client(๋ธŒ๋ผ์šฐ์ €)๊ฐ€ ์ž์›์˜ ์ƒํƒœ์— ๋Œ€ํ•œ ์กฐ์ž‘์„ ์š”์ฒญ(Request)ํ•˜๋ฉด ์„œ๋ฒ„๋Š” ์ด์— ์ ์ ˆํ•œ ์‘๋‹ต(Response)์„ ๋ณด๋‚ธ๋‹ค.
  JSON, XML, TEXT, RSS ๋“ฑ ์—ฌ๋Ÿฌ ํ˜•ํƒœ๋กœ ํ‘œํ˜„

 

REST API ํŠน์ง•

1. ํด๋ผ์ด์–ธํŠธ/์„œ๋ฒ„
โ€ฃ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋‹จ์ˆœํ™” ์‹œํ‚ค๊ณ  ์ž‘์€๋‹จ์œ„๋กœ ๋ถ„๋ฆฌํ•จ์œผ๋กœ์จ
ํด๋ผ์ด์–ธํŠธ - ์„œ๋ฒ„ ๊ฐ ํŒŒํŠธ๊ฐ€ ๋…๋ฆฝ์ ์œผ๋กœ ๊ฐœ์„ ๋  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค. 


2. ์ƒํƒœ์—†์Œ
โ€ฃ ํด๋ผ์ด์–ธํŠธ์˜ ์ƒํƒœ๊ฐ€ ์„œ๋ฒ„์— ์ €์žฅ๋˜์–ด์„œ๋Š” ์•ˆ๋œ๋‹ค.

3. ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜ (Layered Architecture)
โ€ฃ ํด๋ผ์ด์–ธํŠธ - ์„œ๋ฒ„ ์—ฐ๊ฒฐ ์‚ฌ์ด์˜ ์ค‘๊ฐ„ ์„œ๋ฒ„๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ (ํด๋ผ์ด์–ธํŠธ - ์ค‘๊ฐ„์„œ๋ฒ„ - ์„œ๋ฒ„),
์ค‘๊ฐ„์„œ๋ฒ„(๊ฒŒ์ดํŠธ์›จ์ด, ๋ฐฉํ™”๋ฒฝ, ํ”„๋ก์‹œ etc)๋Š” ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ ํ˜น์€ ๊ณต์œ  ์บ์‹œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•จ์œผ๋กœ์จ
์‹œ์Šคํ…œ ๊ทœ๋ชจ ํ™•์žฅ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ค๋Š”๋ฐ ์œ ์šฉ

4. ์บ์‹œ (Cache)
โ€ฃ ํด๋ผ์ด์–ธํŠธ ์‘๋‹ต์„ ์บ์‹ฑํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ. ์บ์‹ฑํ•จ์œผ๋กœ์„œ ์„œ๋ฒ„์— ๋ถ€ํ•˜ ์ตœ์†Œํ™”

5. ์ฝ”๋“œ ์˜จ ๋””๋งจ๋“œ(Code on demand)
โ€ฃ ์š”์ฒญ์ด ์˜ค๋ฉด ์ฝ”๋“œ๋ฅผ ์ค€๋‹ค๋Š” ์˜๋ฏธ๋กœ ํŠน์ • ์‹œ์ ์— ์„œ๋ฒ„๊ฐ€ ํŠน์ • ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ ๋˜๋Š”
ํ”Œ๋Ÿฌ๊ทธ์ธ์„
ํด๋ผ์ด์–ธํŠธ์— ์ „๋‹ฌํ•ด์„œ ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ๋™์ž‘ํ•˜๋„๋ก ํ•˜๋Š”๊ฒƒ. (์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ, ํ”Œ๋ž˜์‹œ etc)

6. ํ†ตํ•ฉ ์ธํ„ฐํŽ˜์ด์Šค
โ€ฃ ์ผ๊ด€์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ถ„๋ฆฌ ๋˜์–ด์•ผ ํ•จ.

 

REST ์ธํ„ฐํŽ˜์ด์Šค ๊ทœ์น™

1. ๋ฆฌ์†Œ์Šค ์‹๋ณ„
โ€ฃ ์š”์ฒญ ๋‚ด์— ๊ธฐ์ˆ ๋œ ๊ฐœ๋ณ„ ์ž์›์„ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. (URI)

2. ํ‘œํ˜„์„ ํ†ตํ•œ ๋ฆฌ์†Œ์Šค ์ฒ˜๋ฆฌ
โ€ฃ ๋‹ค์–‘ํ•œ ์ฝ˜ํ…์ธ  ์œ ํ˜•์œผ๋กœ ํ‘œํ˜„ ๊ฐ€๋Šฅ (JSON, XML, HTML ..)

3. ์ž๊ธฐ ๋ฌ˜์‚ฌ ๋ฉ”์„ธ์ง€
โ€ฃ Http header ์— ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ์‹ค์ œ ๋ฐ์ดํ„ฐ์™€๋Š” ๊ด€๋ จ ์—†์ง€๋งŒ
๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์„ค๋ช…์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ •๋ณด๋ฅผ ๋‹ด์„ ์ˆ˜ ์žˆ์Œ.

4. ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ์— ๋Œ€ํ•œ ํ•˜์ดํผ๋ฏธ๋””์–ด(HATEOAS, Hypermedia As The Engine Of Application State)
โ€ฃ REST API ๊ฐœ๋ฐœํ•  ๋•Œ์— ๋‹จ์ˆœ ๋ฐ์ดํ„ฐ๋งŒ ์ „๋‹ฌํ•˜์ง€ ์•Š๊ณ , ๋งํฌ ์ •๋ณด๊นŒ์ง€ ํฌํ•จํ•˜์—ฌ ์ „๋‹ฌ (ํ•˜์ดํผ ํ…์ŠคํŠธ ๋งํฌ)
โ€ฃ ๋ฆฌ์†Œ์Šค ์ƒํƒœ๊ฐ€ ์ „์ด๋˜๋Š” ๊ฒฝ์šฐ์— ๋ณ€๊ฒฝ๋˜๋Š” ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๊ณ ์ž ํ•จ.
(๋“ฑ๋ก ์š”์ฒญ ํ›„, ๋ณ€๊ฒฝ ๋œ ์ •๋ณด๋ฅผ ์ข€ ๋” ์ž์„ธํžˆ ์•Œ๊ณ ์ž ํ• ๋•Œ ํ•˜์ดํผ ๋งํฌ๋„ ๊ฐ™์ด ์ œ๊ณต)
    

 

REST API 
์„ค๋ช…

REST ์•„ํ‚คํ…์ฒ˜์˜ ์ œ์•ฝ ์กฐ๊ฑด์„ ์ค€์ˆ˜ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธํ„ฐํŽ˜์ด์Šค

 

RESTful์˜ ๋ชฉ์ 

API ์ด์šฉ์ž๊ฐ€ ํ•ด๋‹น API ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์–ป๊ณ , ํŠน์ • ๊ธฐ๋Šฅ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ

 

๋ฆฌ์†Œ์Šค ์›ํ˜•

๋„ํ๋จผํŠธ (document)
โ€ฃ ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋‚˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ ˆ์ฝ”๋“œ์™€ ์œ ์‚ฌํ•œ ๊ฐœ๋…

์ปฌ๋ ‰์…˜ (collection)
โ€ฃ ์„œ๋ฒ„์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ฆฌ์†Œ์Šค 

์Šคํ† ์–ด (store)
โ€ฃ ํด๋ผ์ด์–ธํŠธ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๋ฆฌ์†Œ์Šค ์ €์žฅ์†Œ
โ€ฃ API ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฆฌ์†Œ์Šค๋ฅผ ๋“ฑ๋ก/์ˆ˜์ •/์‚ญ์ œ์— ๊ด€์—ฌ

์ปจํŠธ๋กค๋Ÿฌ (controller)
โ€ฃ ์ ˆ์ฐจ์ ์ธ ๊ฐœ๋…์„ ๋ชจ๋ธํ™” ํ•œ ๊ฒƒ

 

โœฐ REST API ๋””์ž์ธ์„ ์œ„ํ•œ ๊ทœ์น™

์ถ”์ƒ์ ์ธ ๊ฒƒ ๋ณด๋‹จ, ๊ตฌ์ฒด์ ์ธ ๊ฒƒ์ด ์ข‹๋‹ค.
ex) /animals -> /pigs

๋™์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. (๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉ)
method ๋ฅผ ๋™์‚ฌ ๋Œ€์šฉ์œผ๋กœ ์‚ฌ์šฉ.

๋‹จ์ˆ˜๋ณด๋‹จ, ๋ณต์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•œ๋‹ค.
ex) /thing  ->  /things or /things/{id}

์Šฌ๋ž˜์‹œ(/) ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ„์ธต๊ด€๊ณ„๋ฅผ ํ‘œ์‹œํ•ด์•ผ ํ•œ๋‹ค.
๋ฆฌ์†Œ์Šค๊ฐ„ ์—ฐ๊ด€๊ด€๊ณ„๋Š” /๋ฆฌ์†Œ์Šค๋ช…/๋ฆฌ์†Œ์ŠคID/๊ด€๊ณ„๊ฐ€ ์žˆ๋Š” ๋‹ค๋ฅธ ๋ฆฌ์†Œ์Šค๋ช… ์œผ๋กœ ํ‘œํ˜„ํ•œ๋‹ค.

ex) GET /users/{userid}/devices (์†Œ์œ ์ž๊ฐ€ ๊ฐ€์ง€๊ณ ์žˆ๋Š” ๋””๋ฐ”์ด์Šค ๋ชฉ๋ก?)

URL ๋งˆ์ง€๋ง‰์— ์Šฌ๋ž˜์‹œ(/) ์„ ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.
์Šฌ๋ž˜์‹œ๋ฅผ ํฌํ•จํ•œ๋‹ค๋ฉด, ์Šฌ๋ž˜์‹œ ๋‹ค์Œ์— ์‹๋ณ„์ž๊ฐ€ ์™€์•ผํ•˜๋Š”๋ฐ ์˜ค์ง€ ์•Š์Œ์œผ๋กœ ํ˜ผ๋™์„ ์ค„ ์—ฌ์ง€๊ฐ€ ์žˆ์Œ.

URI์˜ ๊ฐ€๋…์„ฑ์„ ๋†’ํžˆ๋ ค๋ฉด ํ•˜์ดํ”ˆ(-)์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

URI์— ๋ฐ‘์ค„(_)์„ ์‚ฌ์šฉํ•ด์„  ์•ˆ๋œ๋‹ค.
๋ณด๊ธฐ๊ฐ€ ์–ด๋ ค์›€. ๊ฐ€๋…์„ฑ

URI ๊ฒฝ๋กœ์—๋Š” ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

ํŒŒ์ผ ํ™•์žฅ์ž๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

 


์ฐธ๊ณ 

https://www.redhat.com/ko/topics/api/what-is-a-rest-api

(์ฑ…) ์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ ๋ฐฐ์šฐ๋Š” ์ž๋ฐ” ์›น ๊ฐœ๋ฐœ

 

REST API(RESTful API, ๋ ˆ์ŠคํŠธํ’€ API)๋ž€ - ์„œ๋ฒ„, ๊ตฌํ˜„, ์‚ฌ์šฉ๋ฒ•

REST API(RESTful API)๋ž€ REST ์•„ํ‚คํ…์ฒ˜์˜ ์ œ์•ฝ ์กฐ๊ฑด์„ ์ค€์ˆ˜ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋œปํ•ฉ๋‹ˆ๋‹ค. api ์„œ๋ฒ„, rest api ๊ตฌํ˜„ ๋ฐ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

www.redhat.com

https://nsinc.tistory.com/192

 

URL vs URI vs URN

์ธํ„ฐ๋„ท์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋งŽ์ด ๋งŒ๋‚˜๊ฒŒ ๋˜๋Š” URI, URL, URN์˜ ๊ฐœ๋…์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. URI, URL, URN์€ ๊ธฐ์ˆ ์ ์ธ ๊ตฌ๋ถ„์ด ์•„๋‹Œ ๊ฐœ๋…์ ์ธ ์ฐจ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค. URI vs URL vs URN ?

nsinc.tistory.com

https://spoqa.github.io/2013/06/11/more-restful-interface.html

 

RESTful API๋ฅผ ์„ค๊ณ„ํ•˜๊ธฐ ์œ„ํ•œ ๋””์ž์ธ ํŒ

RESTful api๋ฅผ ์„ค๊ณ„ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐœ๋…๋“ค์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์•Œ์•„๋ณด๊ณ  ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ผ๋งŒํ•œ HTTPํ—ค๋”์™€ ์ƒํƒœ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

spoqa.github.io

https://dzone.com/articles/7-rules-for-rest-api-uri-design-1

 

7 Rules for REST API URI Design - DZone Integration

URIs, or Uniform Resource Identifiers, should be designed to be readable and clearly communicate the API resource model. These rules will help you succeed.

dzone.com

https://gmlwjd9405.github.io/2018/09/21/rest-and-restful.html

 

[Network] REST๋ž€? REST API๋ž€? RESTful์ด๋ž€? - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

https://www.slideshare.net/nexusz99/rest-api-48600643

 

REST API ๋””์ž์ธ ๊ฐœ์š”

REST API๊ฐ€ ๋ฌด์—‡์ด๊ณ  ๊ทธ๊ฒƒ์„ ์–ด๋–ป๊ฒŒ ๋””์ž์ธํ•ด์•ผํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ๋‚˜๋ฆ„๋Œ€๋กœ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

www.slideshare.net

https://zsgg.tistory.com/entry/REST-API-%EB%94%94%EC%9E%90%EC%9D%B8-%EA%B7%9C%EC%B9%99

 

REST API ๋””์ž์ธ ๊ทœ์น™

์—ฌ์ „ํžˆ ์šฐ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์งˆ๋ฌธ๋“ค์— ๋Œ€ํ•œ ๋‹ต์„ ์ฐพ์•„์•ผ ํ•œ๋‹ค. URI ๊ฒฝ๋กœpath ์„ธ๊ทธ๋จผํŠธ๋Š” ์–ธ์ œ ๋ณต์ˆ˜๋กœ ์จ์•ผ ํ•˜๋Š”๊ฐ€? ๋ฆฌ์†Œ์Šค์˜ ์ƒํƒœ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ ค๋ฉด, ์–ด๋–ค ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”๊ฐ€? CRUD12๊ฐ€ ์•„๋‹Œ

zsgg.tistory.com

https://sanghaklee.tistory.com/57

 

RESTful API ์„ค๊ณ„ ๊ฐ€์ด๋“œ

1. RESTful API ์„ค๊ณ„ ๊ฐ€์ด๋“œ ๋ณธ ๋ฌธ์„œ๋Š” REST API๋ฅผ ์ข€ ๋” RESTful ํ•˜๊ฒŒ ์„ค๊ณ„ํ•˜๋„๋ก ๊ฐ€์ด๋“œํ•  ๋ชฉ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์กŒ๋‹ค. ๋”ฐ๋ผ์„œ, ๊ธฐ๋ณธ์ ์ธ REST API ๊ฐœ๋… ์„ค๋ช…์€ ์•„๋ž˜์˜ ๋งํฌ๋กœ ๋Œ€์‹ ํ•œ๋‹ค. REST API ์ œ๋Œ€๋กœ ์•Œ๊ณ  ์‚ฌ์šฉ

sanghaklee.tistory.com

https://meetup.toast.com/posts/92

 

REST API ์ œ๋Œ€๋กœ ์•Œ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ : NHN Cloud Meetup

REST API ์ œ๋Œ€๋กœ ์•Œ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ

meetup.toast.com

 

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SSE (Server Sent Event)  (1) 2023.08.20
Vault  (1) 2023.02.07
ํ—ฅ์‚ฌ๊ณ ๋‚  ์•„ํ‚คํ…์ฒ˜ (Hexagonal Architecture)  (2) 2022.09.25
JWT (JSON WEB TOKEN)  (0) 2021.12.22
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09
๋ฐ˜์‘ํ˜•
DI
์„ค๋ช…

์˜์กด์„ฑ ์ฃผ์ž…์ด๋ผ๊ณ ๋„ ํ•˜๋ฉฐ, IoC (Inversion of Control) ๋ผ๊ณ  ํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜.
์–ด๋–ค ํด๋ž˜์Šค๊ฐ€ ํ•„์š”๋กœ ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์™ธ๋ถ€์—์„œ ์ƒ์„ฑํ•œ ํ›„, ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๊ณผ์ •

DI ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๊ฐ ์ปดํฌ๋„ŒํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ†ตํ•ฉ ๊ด€๋ฆฌํ•˜๋ฉด์„œ ์ปดํฌ๋„ŒํŠธ๊ฐ„ ์˜์กด์„ฑ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

โœณ๏ธŽ ๋นˆ (@bean)
spring DI container์— ์˜ํ•ด ๊ด€๋ฆฌ๋˜๋Š” ๊ฐ์ฒด 
ApplicationContext.getBean(XXX.class) ์œผ๋กœ ์–ป์–ด์ง€๋Š” ๊ฐ์ฒด๋ฅผ ์˜๋ฏธ


โœณ๏ธŽ ์ปดํฌ๋„ŒํŠธ (@Component)
์‚ฌ์šฉ์ž๊ฐ€ ๋งŒ๋“  bean ์„ ์ž๋™์œผ๋กœ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ ๊ฒƒ


โœณ๏ธŽ IoC ์ปจํ…Œ์ด๋„ˆ (Inversion of Control)
์˜์กด์„ฑ ์ฃผ์ž…์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋ฐ˜์ด๊ณ  ์ธ์Šคํ„ด์Šค ๊ตฌ์„ฑ ๋ฐ ๋นˆ ์กฐ๋ฆฝ์„ ๋‹ด๋‹นํ•œ๋‹ค.
๋นˆ ํŒฉํ† ๋ฆฌ(Bean Factory)๋ผ๊ณ ๋„ ํ•จ.
Bean Factory์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ApplicationContext๋ผ๊ณ  ๋ถ€๋ฆ„. (Bean Factory์˜ ํ™•์žฅ)


โœณ๏ธŽ Bean Factory
Bean ์„ ๋“ฑ๋ก/์ƒ์„ฑ/์กฐํ™”/๋ฐ˜ํ™˜ ๊ด€๋ฆฌํ•จ.


โœณ๏ธŽ ApplicationContext
spring bean์„ ๋ณด์œ ํ•˜๊ณ ์žˆ๋Š”๊ณณ
Bean Factory ์™€ ๊ธฐ๋Šฅ ๊ฐ™๊ณ , Spring์˜ ๋ถ€๊ฐ€ ์„œ๋น„์Šค๋ฅผ ์ถ”๊ฐ€๋กœ ์ œ๊ณต


์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๋Š” ์‹ฑ๊ธ€ํ„ด(singleton) ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋ฉฐ, ์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๋Š” ํ”„๋กœํ† ํƒ€์ž…(prototype) ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. ์ด๋Ÿฌํ•œ ์ธ์Šคํ„ด์Šค ์Šค์ฝ”ํ”„(scope) ๊ด€๋ฆฌ๋ฅผ DI ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋Œ€์‹  ํ•ด์ค€๋‹ค.

 

DI ๋ฐฉ๋ฒ• 3๊ฐ€์ง€

1. ์„ค์ •์ž ๊ธฐ๋ฐ˜ (setter-based)
  setter method ์— @Autowired ์„ ์ ์šฉ

@RestController
public class AController {
    private A a;

    @Autowired
    public void setA(A a) {
	    this.a = a;
    }
}


2. ์ƒ์„ฑ์ž ๊ธฐ๋ฐ˜ (contructor-based)
  ์ƒ์„ฑ์ž ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์˜์กด์„ฑ์„ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ์‹

@RestController
public class AController {
    private final A a;
    
    public AController(A a){
        this.a = a;
    }
}

 

3. ํ•„๋“œ๊ธฐ๋ฐ˜ (field-based)
  ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ํ•„๋“œ์— @Autowired ์„ ์ ์šฉ 

@RestController
public class AController {
    
    @Autowired
    private A a;
}

 

โœณ๏ธŽ @Autowired
๋นˆ์„ ์ž๋™์œผ๋กœ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ์‹

 

ํ•„๋“œ ๊ธฐ๋ฐ˜ ๋ฐฉ์‹์€ ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค. (์ƒ์„ฑ์ž ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ๊ถŒ์žฅ)
์ถ”์ฒœํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ์ˆœํ™˜์ฐธ์กฐ ๋•Œ๋ฌธ! 

โœณ๏ธŽ ์ˆœํ™˜์ฐธ์กฐ
์„œ๋กœ ๋‹ค๋ฅธ ํด๋ž˜์Šค๊ฐ€ ์„œ๋กœ๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ, ๋”ฐ๋ผ์„œ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์–ด๋–ค ๋นˆ์„ ๋จผ์ € ์ƒ์„ฑํ•ด์•ผํ• ์ง€ ํŒ๋‹จ์„ ํ•˜์ง€ ๋ชปํ•ด์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ!

์ƒ์„ฑ์ž ๋ฐฉ์‹์„ ์ถ”์ฒœํ•˜๋Š” ์ด์œ ๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ์— ์šฉ์˜ํ•˜๋ฉฐ, ์‹คํ–‰ ์ค‘ ๊ฐ์ฒด๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  

 

DI ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์šฉ์˜ ์žฅ์ 
์žฅ์ 

  ์ธ์Šคํ„ด์Šค ์Šค์ฝ”ํ”„ ์ œ์–ด
  ์ธ์Šคํ„ด์Šค ์ƒ๋ช…์ฃผ๊ธฐ ์ œ์–ด
  AOP ๋ฐฉ์‹์œผ๋กœ ๊ณตํ†ต๊ธฐ๋Šฅ ์ ์šฉ ๊ฐ€๋Šฅ
  ์˜์กดํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถฐ ๋‹จ์œ„ํ…Œ์ŠคํŠธ ์‰ฝ๊ฒŒ ๊ฐ€๋Šฅ

 

 

๋นˆ ์„ค์ • ๋ฐฉ๋ฒ•
์„ค์ • ๋ฐฉ๋ฒ• 3๊ฐ€์ง€

1. ์ž๋ฐ” ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐฉ์‹ (Java-based configuration)
  - ์ž๋ฐ” ํด๋ž˜์Šค์— @Configuration, ๋ฉ”์†Œ๋“œ์— @Bean ์„ ์‚ฌ์šฉํ•ด ๋นˆ์„ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

2. XML ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐ˜์‹ (XML-based configuration)
  - XML ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• (<bean>, <constructor-arg>, <property>)

3. ์• ๋„ˆํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐฉ์‹ (Annotation-based configuration)
  - @Component ๊ฐ™์€ ๋งˆ์ปค ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ€์—ฌ๋œ ํด๋ž˜์Šค๋ฅผ ํƒ์ƒ‰ํ•ด์„œ(Component Scan) IoC์ปจํ…Œ์ด๋„ˆ์— ๋นˆ์„ ์ž๋™์œผ๋กœ ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•.

 

 

์ปดํฌ๋„ŒํŠธ ์Šค์บ” (Component Scan)
์„ค๋ช…

ํด๋ž˜์Šค ๋กœ๋”(Class Loader)๋ฅผ ์Šค์บ”ํ•˜๋ฉด์„œ ํŠน์ • ํด๋ž˜์Šค๋ฅผ ์ฐพ์€ ๋‹ค์Œ, DI ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•

 

์ข…๋ฅ˜

@Component, @Controller, @Service, @Repository, @Configuration, @RestController, @ControllerAdvice, @ManagedBean, @Named ..

 

 


์ฐธ๊ณ 

(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ
http://blog.naver.com/PostView.nhn?blogId=gngh0101&logNo=221179100057&parentCategoryNo=&categoryNo=32&viewDate=&isShowPopularPosts=false&from=postView
https://dog-developers.tistory.com/12
https://ict-nroo.tistory.com/120
https://www.baeldung.com/spring-component-annotation
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-basics

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
IOC/DI, DI์‘์šฉ  (0) 2017.11.20
spring ์‹œ์ž‘, maven ์„ค์น˜  (0) 2017.11.12

+ Recent posts