๐Ÿ“‚ IaC

[IaC] IaC(Infra as a Code)

dhyuck 2021. 10. 31. 23:43
๋ฐ˜์‘ํ˜•

Infrastructure as Code (IaC)

  • Infrastructure as Code (IaC)๋ž€ ์ˆ˜๋™ ํ”„๋กœ์„ธ์Šค(manual processes) ๋Œ€์‹ ์— ์ฝ”๋“œ๋กœ ์ธํ”„๋ผ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ํ”„๋กœ๋น„์ €๋‹(provisioning)ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

  • IaC๋Š” Configuration files(์„ค์ • ํŒŒ์ผ)์„ ์ˆ˜์ •ํ•˜๊ณ  ๋ฐฐํฌํ•จ์œผ๋กœ์จ ์ธํ”„๋ผ๋ฅผ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์„ค์ •ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์–ธ์ œ๋‚˜ ๊ฐ™์€ ํ™˜๊ฒฝ์„ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


IaC์˜ ํŠน์ง•

  • ๋น„์šฉ ์ ˆ๊ฐ : ์ธํ”„๋ผ๋ฅผ ํ”„๋กœ๋น„์ €๋‹ํ•˜๋Š” ๊ฒƒ์€ ์‹œ๊ฐ„๊ณผ ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ์ˆ˜๋™ ํ”„๋กœ์„ธ์Šค์˜€์œผ๋‚˜ IaC๋ฅผ ํ†ตํ•ด ์‹œ๊ฐ„๊ณผ ๋น„์šฉ์„ ์ ˆ์•ฝ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋น ๋ฅธ ์‹คํ–‰ : ์„ค์ • ํŒŒ์ผ์„ ํ†ตํ•ด ๋™์ผํ•œ ์ธํ”„๋ผ๋ฅผ ํšŸ์ˆ˜์— ์ƒ๊ด€ ์—†์ด ๋น ๋ฅด๊ณ  ํšจ์œจ์ ์œผ๋กœ ๊ตฌ์ถ• ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์—๋Ÿฌ ๊ฐ์†Œ : ์ธํ”„๋ผ๋ฅผ ์ˆ˜๋™์œผ๋กœ ๊ตฌ์„ฑํ•˜๋ฉฐ ๋ฐœ์ƒํ•˜๋Š” ํœด๋จผ์—๋Ÿฌ๋ฅผ ๊ฐ์†Œ์‹œํ‚ฌ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์žฌ์‚ฌ์šฉ์„ฑ ํ–ฅ์ƒ : ์ฝ”๋“œ๋กœ ์ธํ”„๋ผ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ๋–„๋ฌธ์— ์ฝ”๋“œ๋ฅผ ์žฌ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋ฒ„์ „ ๊ด€๋ฆฌ : IaC๋Š” ์„ค์ •ํŒŒ์ผ์„ ์ฝ”๋“œ์ฒ˜๋Ÿผ ๊ด€๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„์ „ ๊ด€๋ฆฌ(Version control)๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

  • ์ธํ”„๋ผ ์ผ๊ด€์„ฑ(consistency) ํ–ฅ์ƒ : ๋™์ผํ•œ ์„ค์ •ํŒŒ์ผ์˜ ๋™์ผํ•œ ๋ฒ„์ „์€ ๋™์ผํ•œ ์ธํ”„๋ผ๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.


Mutable Infrastructure์™€ Immutable Infrastructure

  • Mutable infrastructure๋Š” ์›๋ž˜ ํ”„๋กœ๋น„์ €๋‹(originally provisioned) ๋œ ์ดํ›„๋กœ ์ˆ˜์ •๋˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ”„๋ผ ์ŠคํŠธ๋Ÿญ์ณ์ž…๋‹ˆ๋‹ค.

    ์ด๋Š” ์ธํ”„๋ผ ์ŠคํŠธ๋Ÿญ์ณ์— ์œ ์—ฐ์„ฑ์„ ์ œ๊ณตํ• ์ˆ˜๋Š” ์žˆ์ง€๋งŒ IaC์˜ ํฐ ์ด์ ์ธ ์ธํ”„๋ผ ์ผ๊ด€์„ฑ๊ณผ ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ํ†ตํ•ด ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ด์ ์„ ์•ฝํ™”์‹œํ‚ต๋‹ˆ๋‹ค.

    ๊ฐ™์€ ๋ฒ„์ „์œผ๋กœ ๋ฐฐํฌ๋œ ์ธํ”„๋ผ๋ผ๋„ ์กฐ๊ธˆ์˜ ์ˆ˜์ •์ด ๊ฐ€ํ•ด์ง€๋ฉด ๋‹ค๋ฅธ ์ธํ”„๋ผ๊ฐ€ ๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋Œ€๋ถ€๋ถ„์˜ IaC๋Š” Immutable Infrastructure๋กœ ๊ตฌํ˜„๋ฉ๋‹ˆ๋‹ค.

  • Immutable Infrastructure๋Š” ์›๋ž˜ ํ”„๋กœ๋น„์ €๋‹(originally provisioned)๋œ ์ดํ›„๋กœ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋Š” ์ธํ”„๋ผ ์ŠคํŠธ๋Ÿญ์ณ์ž…๋‹ˆ๋‹ค.

    ๋งŒ์•ฝ์— Immutable Infrastructure๋ฅผ ๋ณ€๊ฒฝํ•ด์•ผ ํ•œ๋‹ค๋ฉด ์ƒˆ๋กœ์šด ์ธํ”„๋ผ(new infrastructure)๋กœ ๊ต์ฒดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ์ƒˆ๋กœ์šด ์ธํ”„๋ผ๋Š” ๋น ๋ฅด๊ฒŒ ๊ฐ€๋™ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— immutable infrastructure๋Š” ํ›จ์”ฌ ๋” ์‹คํ˜„๊ฐ€๋Šฅํ•˜๊ณ  ํ˜„์‹ค์  (much more feasible and practical)์ž…๋‹ˆ๋‹ค.

    Immutable Infrastructure๋Š” ์ธํ”„๋ผ๋ฅผ ๋ฒ„์ „์œผ๋กœ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. ์ด๋Š” ์ธํ”„๋ผ๋ฅผ ์ž์‹ ์žˆ๊ฒŒ ๋กค๋ฐฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.


Declarative approach(์„ ์–ธํ˜• ์ ‘๊ทผ) IaC์™€ Imperative approach(๋ช…๋ นํ˜• ์ ‘๊ทผ) IaC

  • Declarative approach IaC์€ ํ•„์š”ํ•œ ๋ฆฌ์†Œ์Šค์™€ ์›ํ•˜๋Š” ์‹œ์Šคํ…œ์˜ ์ƒํƒœ๋ฅผ ์ •์˜(defines the desired state of the system)ํ•˜๋ฉด IaC tool์ด ์ด๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • Impreative approach IaC๋Š” ์›ํ•˜๋Š” ์‹œ์Šคํ…œ์˜ ์ƒํƒœ๋ฅผ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ช…๋ น๋“ค์„ ์ •์˜(defines the specific commands needed to achieve the desired configuration)ํ•˜๋ฉด IaC tool์ด ์ด๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ์ด๋Š” ์˜ฌ๋ฐ”๋ฅธ ์ˆœ์„œ(correct order)๋กœ ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Declarative IaC์— ๋น„ํ•ด ๋งŽ์€ ์ „๋ฌธ์„ฑ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

  • IaC tool์€ ์ข…์ข… 2๊ฐ€์ง€ ์ ‘๊ทผ ๋ฐฉ์‹ ๋ชจ๋‘์—์„œ ์ž‘๋™ ๋  ์ˆ˜ ์žˆ์œผ๋‚˜, 1๊ฐ€์ง€ ๋ฐฉ์‹๋งŒ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ Declarative approach Iac๊ฐ€ ์„ ํ˜ธ๋ฉ๋‹ˆ๋‹ค.


Configuration orchestration ์™€ Configuration management

  • Configuration orchestration์€ ์„œ๋ฒ„ ์ธ์Šคํ„ด์Šค์™€ ๊ธฐํƒ€ ์ธํ”„๋ผ๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ  ์ž๋™ํ™” ํ•˜๋„๋ก ์„ค๊ณ„ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ข…๋ฅ˜๋กœ๋Š” Terraform, AWS Cloud Formation ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • Configuration management๋Š” ๊ธฐ์กด ์„œ๋ฒ„์— ์ธ์Šคํ„ด์Šค์— ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์„ค์น˜ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ข…๋ฅ˜๋กœ๋Š” Ansible, Puppet, Chef ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•