[Spring] YAML ์ด๋ž€? (Feat. JSON, XML)

๋ฅ˜๋„นยท2024๋…„ 3์›” 5์ผ
1

Spring

๋ชฉ๋ก ๋ณด๊ธฐ
21/50

๐Ÿ“ YAML ์ด๋ž€?

  • ๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ์–ธ์–ด
  • ์„ค์ •ํŒŒ์ผ(๊ตฌ์„ฑํŒŒ์ผ) ์ž‘์„ฑ์— ์ž์ฃผ ์‚ฌ์šฉ
  • ์‰ฝ๊ฒŒ ์ฝ๊ณ  ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋จ

๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ๋ž€?

  • ๊ฐ์ฒด๋ฅผ ๋„คํŠธ์›Œํฌ ํ†ต์‹ ์— ์‚ฌ์šฉํ•˜๊ธฐ ์ ํ•ฉํ•œ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ.
  • ์ฝ๊ณ  ์ž‘์„ฑํ•˜๊ธฐ ์‰ฌ์šด ํ…์ŠคํŠธ ํ˜•์‹๊ณผ ์ปดํ“จํ„ฐ๊ฐ€ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์ด์ง„ํ˜•์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ
  • ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ๋ฐ์ดํ„ฐ ํ˜•์‹
    • CSV
    • JSON
    • XML
    • YAML (๋ฐ์ดํ„ฐ ์ง๋ ฌํ™”๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ธด ํ•˜์ง€๋งŒ, ์ฃผ๋กœ ์„ค์ •ํŒŒ์ผ ์ž‘์„ฑ์„ ์œ„ํ•ด์„œ ๊ฐœ๋ฐœ๋จ)




๐Ÿ“Œ XML, JSON, YAML๋กœ ๋ฐ์ดํ„ฐ ํ‘œํ˜„ํ•˜๊ธฐ

1. XML๋กœ ์„ค์ •์ •๋ณด ํ‘œํ˜„ํ•˜๊ธฐ

  • ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ ํ‘œํ˜„
  • key : ํƒœ๊ทธ์ด๋ฆ„ / value : ํƒœ๊ทธ์˜ ์ปจํ…์ธ (๊ฐ’)
  • ํƒœ๊ทธ ์•ˆ์— ํƒœ๊ทธ๋ฅผ ํฌํ•จ์‹œ์ผœ์„œ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋ƒ„
<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <apiVersion>v1</apiVersion>
    <kind>Pod</kind>
    <metadata>
        <name>hello-pod</name>
        <labels>
            <app>hello</app>
        </labels>
    </metadata>
    <spec>
        <containers>
            <name>hello-container</name>
            <image>sample/hello</image>
        </containers>
    </spec>
</root>

2. JSON์œผ๋กœ ์„ค์ •์ •๋ณด ํ‘œํ˜„ํ•˜๊ธฐ

  • XML์— ๋น„ํ•ด ๋‹จ์ˆœ
  • JSON์€ ๊ฐ์ฒด ํ‘œํ˜„๋ฒ•๊ณผ ๋ฐฐ์—ด ํ‘œํ˜„๋ฒ•์„ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์—
    key-value ์Œ์˜ ๋ฐ์ดํ„ฐ๋Š” ๊ฐ์ฒด ํ‘œํ˜„๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•˜๊ณ ,
    value, value, value ๊ฐ’์˜ ๋ชฉ๋ก์€ ๋ฐฐ์—ด ํ‘œํ˜„๋ฒ•์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Œ
  • XML
{
      "apiVersion": "v1",
      "kind": "Pod",
      "metadata": {
              "name": "hello-pod",
              "labels": [
                          {"app": "hello"},
                ]
      },
      "spec": {
              "containers": [
                          {
                              "name": "hello-container",
                              "image": "sample/hello"
                          }
                ]
      }
}

3. YAML๋กœ ์„ค์ •์ •๋ณด ํ‘œํ˜„ํ•˜๊ธฐ

  • XML์ด๋‚˜ JSON์— ๋น„ํ•ด์„œ ๋” ๋‹จ์ˆœํ•˜๊ณ , ๊ฐ€๋…์„ฑ์ด ๋†’์Œ
  • 2์นธ ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ์ด์šฉํ•ด์„œ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ํ‘œํ˜„ tab ์‚ฌ์šฉ ๋ถˆ๊ฐ€
  • "-"๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐฐ์—ด์ž„์„ ๋‚˜ํƒ€๋ƒ„
  • ์ฝœ๋ก  ๋’ค์—๋Š” ๋ฐ˜๋“œ์‹œ ๊ณต๋ฐฑ ํ•˜๋‚˜๊ฐ€ ์žˆ์–ด์•ผ ํ•จ
apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  labels:
    app: hello
spec:
  containers:
  - name: hello-container
    image: sample/hello




๐Ÿ’ก ์ฐธ๊ณ 

  • resources๋Š” ์ž๋™์œผ๋กœ ์ธ์‹ํ•ด์„œ webapp ๋ฐ‘์— resources ํด๋”๋ฅผ ๋งŒ๋“ค๋ฉด ๋”ฐ๋กœ ์„ค์ •ํ•˜์ง€ ์•Š์•„๋„ ๋˜์ง€๋งŒ,
    resources ํด๋”๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋”ฐ๋กœ ์„ค์ •์„ ํ•ด์ค˜์•ผ ํ•จ

profile
ํ•™์Šต์šฉ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ๊ฐ„๋‹จ ๊ฐœ๋ฐœ์ž ์‚ฌ์ „

0๊ฐœ์˜ ๋Œ“๊ธ€