前情提要
在 Java 常用的 framework spring boot 中 (Spring MVC 沒有 它還是用一大狗票 Xml…),常可以看到 .properties 與 .yml 檔案做設定,連現在使用的 hugo 也可以使用 yaml 與 toml 設定,並不是唯一,但如果今天要去配置 K8S 的話, yaml 就不得不學了
Yaml
Basic
接著就是有點像 JSON 的 key-value 表示
階層關西的話 => 換行加縮排
以下等於 spring.datasource.username = root
1
2
3
| spring:
datasource:
username: root
|
常見陣列 => 換行 縮排並在開頭加上 “-” 並空一格
內容可用來包 複雜物件
1
2
3
| args:
- "parameter1"
- "parameter2"
|
但陣列好像也可以這樣 (簡單模式)
1
2
| items: [ 1, 2, 3, 4, 5 ]
args: [ "parameter1", "parameter2" ]
|
以下範例 參考 CloudBee YAML Tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| ---
doe: "a deer, a female deer"
ray: "a drop of golden sun"
pi: 3.14159
xmas: true
french-hens: 3
calling-birds:
- huey
- dewey
- louie
- fred
xmas-fifth-day:
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
location: "a pear tree"
turtle-doves: two
|
相等於 JSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| {
"doe": "a deer, a female deer",
"ray": "a drop of golden sun",
"pi": 3.14159,
"xmas": true,
"french-hens": 3,
"calling-birds": [
"huey",
"dewey",
"louie",
"fred"
],
"xmas-fifth-day": {
"calling-birds": "four",
"french-hens": 3,
"golden-rings": 5,
"partridges": {
"count": 1,
"location": "a pear tree"
},
"turtle-doves": "two"
}
}
|