What is YAML
Last updated
Last updated
Understanding YAML
YAML, which stands for YAML Ain't Markup Language, is a human-readable data serialization standard. It is commonly used for configuration files and data exchange between languages with different data structures. Its straightforward structure, utilizing indents and simple syntax, makes it accessible for defining hierarchical data.
YAML files typically use the .yaml or .yml extension. They support data structures such as objects (hashes/maps), arrays, and scalars (strings, integers, and floats), making them versatile for various applications. A key principle in YAML is its emphasis on being easy to read and write for machines and humans.
Key Features: Indentation-based structure: Uses spaces for nesting, which visually groups data.
Scalar styles: Support block (used |
for maintaining line breaks) and flow (used >
for folding line breaks).
Comments: Begins with, allowing for explanation or exclusion of elements.
Support for complex data types: Allows for representing objects, arrays, and primitives.
Use Cases:
Configuration files: Widely utilized in software projects for setting up applications or services.
Data exchange: Facilitates data sharing between programming languages with minimal parsing overhead.
In summary, YAML's human-friendly design makes it an excellent choice for software development configuration and data representation tasks.
apiVersion:- Specific to the version of the Kubernetes API being used. it defines the schema of the object that you're creating or modifying.
kind:- Specifics the type of Kubernetes resource being defined. Common values include 'Pod', 'Deployment', 'Service', 'PersistenVloumeClaim' etc.
metadata:- Contains metadata about the resource, such as the name, namespace, labels, and annotations.
Name:- The <name> field specifies the unique name of the Kubernetes object. It serves as an identifier and must be unique within its namespace.
Namespace:- The namespace field(optional) refers to the Kubernetes namespace where the object will be created. Namespaces are used to organize and isolate resources within a cluster. if omitted, the default namespace is used.
Labels:- Labels are key-value pairs that allow you to arbitrary metadata to Kubernetes objects. They are used for selecting and grouping objects based on specific criteria labels are not meant for identifying objects but rather for categorization.
Annotations: -Annotations are also key-value pairs, similar to labels. However, they serve a different purpose. Annotations, allow you to attach additional non-identifying metadata to objects Unlike labels, annotations can include more complex data and characters not allowed by labels, they are often used for recording information related to configuration release, details, debugging, and more.
Spec:- Defines the desired state of the resources. This section varies depending on the kind of resource being defined.
For a Pod- it includes the containers to run, volumes to mount, and other pod-level configurations.
For a Deployment- it includes the desired number of replicas, the template for creating pods, and deployment-specific settings.
For a Service- it includes the type of service ( ClusterIP, NodePort, LoadBalancer ), the selector to route traffic to pods, and other service-specific configurations.
status:- This section is not included in the YAML files that you create manually. it is automatically generated by Kubernetes and provides information about the current status of the resource.