YAML and Its Usage in Kubernetes

DZone 's Guide to

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.

· Cloud Zone ·
Free Resource

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
   name: nginx-deployment
   revisionHistoryLimit: 5
   minReadySeconds: 10
         app: nginx
         deployer: distelli
      type: RollingUpdate
         maxUnavailable: 1
         maxSurge: 1
   replicas: 3
            app: nginx
            deployer: distelli
            - 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.

code snippet ,data language ,data serialization ,kubernetes ,yaml

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}