4. Yet Another Markup Language
● YAML Spec
○ https://yaml.org/spec/1.2/spec.html#id2
777534
● YAML Maps
---
apiVersion: v1
kind: Pod
● YAML List
spec:
containers:
- name: myc1
image: nginx:alpine
- name: myc2
image: redis
● Indentation is done with one or more
spaces, as long it is maintained
● Should not use Tabs
--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
5. Some Issues With YAML
● Define the YAML
country_codes:
united_states: us
ireland: ie
norway: no
● Load the YAML in Ruby
require 'yaml'
doc = <<-ENDYAML
country_codes:
united_states: us
ireland: ie
norway: no
ENDYAML
puts YAML.load(doc)
● Output
{"country_codes"=>{"united_states"=>"us",
"ireland"=>"ie", "norway"=>false}}
YAML Reference
● Define
name: &speaker Neependra
presentation:
name: AKD
speaker: *speaker
● Reference Later
name: "Neependra"
presentation:
name: "AKD"
speaker: "Neependra"
● What would happen with this?
a: &a ["a", "a", "a"]
b: &b [*a,*a,*a]
c: &c [*b, *b, *b]
6. Why are we stuck with YAML?
Watch Joe Beda’s talk : I am Sorry about The YAML.
7. Why YAML over JSON ?
● YAML is superset of JSON
● More readable
● Takes less space
● Allows comments
apiVersion: v1
kind: Pod
metadata:
name: mypod #name of the Pod
labels:
app: nginx
spec:
containers:
- name: nginx-demo
image: nginx:alpine
ports:
- containerPort: 80
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "mypod",
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "nginx-demo",
"image": "nginx:alpine",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
Configuration in YAML Configuration in JSON
10. Object Model
● Use YAML or JSON file to define
object
● We define the desired using
spec field
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: default
spec:
containers:
- name: myc
image: nginx:alpine
11. Object Model
● Use YAML or JSON file to define
object
● We define the desired using
spec field
● status field is managed my
Kubernetes, which describes the
current state of the object
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: default
spec:
containers:
- name: myc
image: nginx:alpine
status:
……
……
12. Tip #1 Combine Multiple YAML files into One
apiVersion: apps/v1
kind: Deployment
metadata:
name: rsvp
spec:
replicas: 1
...
13. Tip #1 Combine Multiple YAML files into One
apiVersion: apps/v1
kind: Deployment
metadata:
name: rsvp
spec:
replicas: 1
...
---
apiVersion: v1
kind: Service
metadata:
name: rsvp
…
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
…..
14. Tip#2 Use Quotes
apiVersion: v1
kind: Pod
metadata:
name: mypod
labels:
app: nginx
spec:
containers:
- name: nginx-demo
image: nginx:alpine
env:
- name: INDIA
value: IN
- name: NORWAY
value: NO
ports:
- containerPort: 80
root@master:~# k apply -f pod.yaml
Error from server (BadRequest): error when creating
"pod.yaml": Pod in version "v1" cannot be handled as
a Pod: v1.Pod.Spec: v1.PodSpec.Containers:
[]v1.Container: v1.Container.Env: []v1.EnvVar:
v1.EnvVar.Value: ReadString: expects " or n, but found
f, error found in #10 byte of
...|,"value":false}],"im|..., bigger context
...|":"INDIA","value":"IN"},{"name":"NORWAY","value":fa
lse}],"image":"nginx:alpine","name":
"nginx-demo",|...