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.
Join the DZone community and get the full member experience.Join For Free
Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.
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:
- configuration files,
- log files,
- interprocess messaging,
- cross-language data sharing,
- object persistence, and
- 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
replicas– Tells Kubernetes how many Pods to create during a deployment. Modifying this field is an easy way to scale a containerized application
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.
spec.strategy.rollingUpdate.maxUnavailable– It is the maximum number of pods that can be unavailable during the update.
spec.strategy.rollingUpdate.maxSurge– It is the maximum number of pods that can be scheduled above the desired number of pods.
spec.strategy.rollingUpdate.maxSurgecan also be defined as a percentage of all Pods.
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.
spec.revisionHistoryLimit– It is an optional integer attribute you can use to tell Kuberneres explicitly how many old
ReplicaSetsto retain at any given time.
spec.template.metadata.labels– It is to add labels to a deployment specification.
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.
Opinions expressed by DZone contributors are their own.