YAML Configuration
A YAML file is used to represent the data that want to configure or settings on the applications to make easy and readible. The case configuration data here is a quick comparison of sample data in three different formats.
The one on the left is the XML where we display the list of servers and the information is the same as the data
represented in Json format in the middle and finally in YAML format on the right.
Example of YAML Usage
YAML is a structure that represents data from a created configuration. For example, configure a server with details:
- name: Server1
- owner: Ihsan
- created: 12122024
- status: active
then implement it into a YAML file like this
servers:
- name: Server1
owner: Ihsan
created: 12122024
status: active
We can see that the -
sign indicates an array that has the fields name
, owner
, created
and status
.
Meanwhile, if we convert it to JSON from the YAML file it will look like this.
{
"servers":[
{
"name": "Server1",
"owner": "Ihsan",
"created": 12122024,
"status": "active"
}
]
}
Then if we want to just add an array of values from a key
then we can add it, for example, like this.
servers:
- name: Server1
owner: Ihsan
created: 12122024
status: active
labels:
- backend
- services
- apps
and if we convert it into a JSON file it will be like below.
{
"servers":[
{
"name": "Server1",
"owner": "Ihsan",
"created": 12122024,
"status": "active",
"labels": [
"backend",
"services",
"apps"
]
}
]
}
Learning about the YAML file format is very easy, it just takes a lot of practice to create this configuration using YAML files.
Things to pay attention to about YAML files
- The indentation of each line determines the parent child object.
- If we create an
array
of values from Yaml then it will be read sequentially if we change the order then the execution order will also change. - If we want to make a comment, we can use the
#
sign at the beginning of the line.
Why do we study YAML Files
In this Kubernetes configuration, many files are created using YAML format, so we need to memorize and understand how the mechanism and creation of file formats use YAML. So that later when we create a Kubernetes service
configuration we will not have difficulty digesting and understanding the configuration or structure of the YAML file that we have created.