DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Resource Management in Kubernetes
  • Implementing EKS Multi-Tenancy Using Capsule (Part 4)
  • Automate Application Load Balancers With AWS Load Balancer Controller and Ingress
  • Don’t Let Kubernetes Developers Suffer From Solved Problems

Trending

  • Java’s Next Act: Native Speed for a Cloud-Native World
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. YAML and Its Usage in Kubernetes

YAML and Its Usage in Kubernetes

If you've used Kubernetes before, chances are you have come into contact with YAML files. Find out more about what they do here.

By 
Raghavendra Deshpande user avatar
Raghavendra Deshpande
·
Updated Jul. 24, 22 · Code Snippet
Likes (3)
Comment
Save
Tweet
Share
5.5K Views

Join the DZone community and get the full member experience.

Join For Free

YAML is a human-friendly data serialization standard for all programming language.

Purpose of YAML

There are hundreds of different languages for programming, but only a handful of languages for storing and transferring data. YAML is a human-friendly data serialization standard for all programming language. Even though its potential is virtually boundless, YAML was specifically created to work well for common use cases such as:

  1. configuration files,
  2. log files,
  3. interprocess messaging,
  4. cross-language data sharing,
  5. object persistence, and
  6. complex data structures

YAML Usage in Kubernetes

The Kubernetes resources are created through a declarative way making use of YAML files. Kubernetes resources such as pods, services, and deployments are created using the YAML files.

This example helps explain the creation of the deployment resource using the YAML:

Note: This example contains both basic and advanced specifications.

apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
   name: nginx-deployment
spec:
   revisionHistoryLimit: 5
   minReadySeconds: 10
   selector:
      matchLabels:
         app: nginx
         deployer: distelli
   strategy:
      type: RollingUpdate
      rollingUpdate:
         maxUnavailable: 1
         maxSurge: 1
   replicas: 3
   template:
      metadata:
         labels:
            app: nginx
            deployer: distelli
      spec:
         containers:
            - name: nginx
              image: nginx: 1.7.9

Explanation of Various Fields

  1.  replicas– Tells Kubernetes how many Pods to create during a deployment. Modifying this field is an easy way to scale a containerized application
  2.  spec.strategy.type – The Rolling Update strategy allows Kubernetes to update a service without facilitating an outage by proceeding to update Pods one at a time.
  3.  spec.strategy.rollingUpdate.maxUnavailable – It is the maximum number of pods that can be unavailable during the update.
  4.  spec.strategy.rollingUpdate.maxSurge – It is the maximum number of pods that can be scheduled above the desired number of pods.
  5.  spec.strategy.rollingUpdate.maxUnavailable and spec.strategy.rollingUpdate.maxSurge  can also be defined as a percentage of all Pods.
  6.  spec.minReadySeconds – It is an optional Integer that describes the minimum number of seconds for which a new pod should be ready without any of its containers crashing, for it to be considered available.
  7.  spec.revisionHistoryLimit – It is an optional integer attribute you can use to tell Kuberneres explicitly how many old ReplicaSets to retain at any given time.
  8.  spec.template.metadata.labels – It is to add labels to a deployment specification.
  9.  spec.selector – It is an optional object that tells the Kubernetes deployment controller to only target pods that match the specified labels. Thus, to only target pods with the labels “app” and “deployer” we can make the following modification to our deployment yaml.

So with the above information, any developer, from beginner to intermediate, would be able to write a yaml file for creation of various Kubernetes resources.


Uses of YAML File

YAML files are commonly used for configurations, application manifest files, and many other places. In addition, these files are also often used for defining Kubernetes resources.

YAML files are saved with the extension .yml or .yaml.

Kubernetes Resources

Kubernetes resources are objects that can be created, modified, and deleted through the Kubernetes API. Several different types of resources can be defined, including:

  • Config Maps – Used to store configuration information that can be used by applications or tools
  • Secrets – Used to store sensitive information like passwords or certificates
  • Persistent Volumes – Describes storage that can be used by applications running in Kubernetes
  • Deployments – Defines how an application should be deployed to Kubernetes
  • Services – Describes how a set of pods can be exposed to the outside world

YAML files are commonly used to define these resources, representing a human-readable way.


Resources that YAML Fields Describe

API version: Kubernetes periodically releases updates which are indicated in the API version field

Kind: The kind field specifies what kind of object it is

Metadata: The metadata includes information that identifies the object like labels, names, and UID

Spec: The spec indicates the configuration or state of the object, and it varies with each object


Writing YAML Files

They are relatively simple to write.

It does not use square brackets or braces. Instead, it uses indentations to define the relations, similar to Python.

So, each child item of a parent is defined by two spaces.

For indicating items in a list, use dashes.

Users can choose between mapping, scalar schemes, and sequences when formatting YAML file data.


How YAML Files are Used

YAML files are used in various applications for configuration, storing, and transferring data.

YAML files have a consistent structure that is easy to read and understand. Their readability makes them ideal for use in configuration files, application manifests, and other places where data needs to be represented in a human-readable way.

YAML files are often used in place of JSON files, as they offer some advantages over JSON. For example, YAML files can support comments, which is not possible with JSON.

Additionally, YAML files can be easily hand-edited, which is useful when working with Kubernetes resources.

YAML and JSON are supersets. So, any legal JSON file can also be represented as a valid YAML document.


Advantages of YAML over JSON

There are a few advantages of using YAML over JSON.

  • YAML supports comments, which is not possible with JSON.
  • YAML files can be easily hand-edited, which can be helpful when working with Kubernetes resources.
  • YAML files tend to be more human-readable than JSON files.


Uses of YAML in Kubernetes

In Kubernetes, a YAML file serves several purposes. First, it helps to define the application service layout.

It also specifies the type of container image that should be used.

Additionally, it contains data about how many replicas to deploy.

Developers use YAML files in Kubernetes to indicate whether or not a load balancer should run behind a service.

It also stores information about the authorizations that connect to the container registry. YAML files offer an information model that is more complete when compared to other languages.


Advantages of YAML for Kubernetes

  1. Convenient: When writing Kubernetes configurations with YAML, you don't have to specify the parameters in the command line.
  2. Easier to maintain: You can track changes by adding YAML files to source control
  3. Adaptable: YAML files give greater flexibility when creating more complex structures
  4. YAML files offer easy portability between programming languages. Also, the native data structures match agile languages.

Structure of YAML Files

  1. Key-Value Pair: This is the basic YAML file entry, which consists of a key followed by a colon and a space then the value.
  2. Arrays/Lists: The lists have the name of the list followed by its items.
  3. Dictionary/Map: This file type includes more complex information.

History of YAML

YAML was created in 2001 by a team of developers. It was designed to be a human-friendly way of representing data.

"YAML" is an acronym for "YAML Ain't Markup Language." Its pronunciation rhymes with "camel." At first, it meant "Yet Another Markup Language," but it eventually changed. It's named this because YAML is not intended to be used as a markup language like HTML or XML.

Instead of writing documents, its purpose is to store data.

When to Use YAML

There are many times when the YAML language is the preferred language.

Here are some examples:

  • If you want to store data in a human-readable format.
  • If you need a format that is easy to hand-edit.
  • When you need a language that supports comments.
YAML Kubernetes

Opinions expressed by DZone contributors are their own.

Related

  • Resource Management in Kubernetes
  • Implementing EKS Multi-Tenancy Using Capsule (Part 4)
  • Automate Application Load Balancers With AWS Load Balancer Controller and Ingress
  • Don’t Let Kubernetes Developers Suffer From Solved Problems

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!