SlideShare a Scribd company logo
1 of 19
Download to read offline
YAML Tips & Tricks for K8s
Neependra Khare, CloudYuga
@neependra
About Me - Neependra Khare
●
●
●
●
●
●
Agenda
● YAML Basics
● K8s & YAML
● K8s API Reference
● YAML Tips for K8s
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.
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]
Why are we stuck with YAML?
Watch Joe Beda’s talk : I am Sorry about The YAML.
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
K8s API Reference
API Group
Core API Group
Other API Groups
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
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:
……
……
Tip #1 Combine Multiple YAML files into One
apiVersion: apps/v1
kind: Deployment
metadata:
name: rsvp
spec:
replicas: 1
...
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:
…..
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",|...
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
apiVersion: v1
kind: Pod
metadata:
name: mypod
labels:
app: nginx
spec:
containers:
- name: nginx-demo
image: nginx:alpine
env:
- name: VERSION
value: “10.3”
- name: NORWAY
value: “NO”
ports:
- containerPort: 80
Tip#3 - Use YAML Reference
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
selector:
matchLabels: &labelsToMatch
app: nginx
env: dev
template:
metadata:
labels: *labelsToMatch
spec:
containers:
- name: nginx
image: nginx:1.9.1
ports:
- containerPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
selector:
matchLabels:
app: nginx
env: dev
template:
metadata:
labels:
app: nginx
env: dev
spec:
containers:
- name: nginx
image: nginx:1.9.1
ports:
- containerPort: 80
Tip#4 - Use YAML Linters, IDE Plugins
● Online
○ http://www.yamllint.com
● Offline
○ Yamllint CLI
■ https://github.com/adrienverge/yamllint
○ yq
■ https://github.com/mikefarah/yq
● IDE Plugins
○ VSCode
■ https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml
○ IntelliJ
■ https://www.jetbrains.com/help/idea/code-style-yaml.html
Thanks
@neependra
References
● https://tanzu.vmware.com/developer/blog/the-hate-for-yaml-the-hammer
-or-the-nail/
● https://www.mirantis.com/blog/introduction-to-yaml-creating-a-kubernete
s-deployment/

More Related Content

What's hot

Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
Docker, Inc.
 

What's hot (20)

Docker Containers Deep Dive
Docker Containers Deep DiveDocker Containers Deep Dive
Docker Containers Deep Dive
 
OpenShift-Technical-Overview.pdf
OpenShift-Technical-Overview.pdfOpenShift-Technical-Overview.pdf
OpenShift-Technical-Overview.pdf
 
Kubernetes Deployment Tutorial | Kubernetes Tutorial For Beginners | Kubernet...
Kubernetes Deployment Tutorial | Kubernetes Tutorial For Beginners | Kubernet...Kubernetes Deployment Tutorial | Kubernetes Tutorial For Beginners | Kubernet...
Kubernetes Deployment Tutorial | Kubernetes Tutorial For Beginners | Kubernet...
 
Introduction to Nexus Repository Manager.pdf
Introduction to Nexus Repository Manager.pdfIntroduction to Nexus Repository Manager.pdf
Introduction to Nexus Repository Manager.pdf
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
 
Gitops: the kubernetes way
Gitops: the kubernetes wayGitops: the kubernetes way
Gitops: the kubernetes way
 
OpenShift 4 installation
OpenShift 4 installationOpenShift 4 installation
OpenShift 4 installation
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Ansible
AnsibleAnsible
Ansible
 
Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker 101 - Nov 2016
Docker 101 - Nov 2016
 
Containers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red HatContainers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red Hat
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017
 
Introduction to container based virtualization with docker
Introduction to container based virtualization with dockerIntroduction to container based virtualization with docker
Introduction to container based virtualization with docker
 
OpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaSOpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaS
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker intro
Docker introDocker intro
Docker intro
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
 

Similar to YAML Tips For Kubernetes by Neependra Khare

Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
DoKC
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
Lucas Jellema
 

Similar to YAML Tips For Kubernetes by Neependra Khare (20)

K8s Pod Scheduling - Deep Dive. By Tsahi Duek.
K8s Pod Scheduling - Deep Dive. By Tsahi Duek.K8s Pod Scheduling - Deep Dive. By Tsahi Duek.
K8s Pod Scheduling - Deep Dive. By Tsahi Duek.
 
Optimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on KubernetesOptimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on Kubernetes
 
New Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 betaNew Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 beta
 
Beam on Kubernetes (ApacheCon NA 2019)
Beam on Kubernetes  (ApacheCon NA 2019)Beam on Kubernetes  (ApacheCon NA 2019)
Beam on Kubernetes (ApacheCon NA 2019)
 
Rook - cloud-native storage
Rook - cloud-native storageRook - cloud-native storage
Rook - cloud-native storage
 
Interop2018 contrail ContrailEnterpriseMulticloud
Interop2018 contrail ContrailEnterpriseMulticloudInterop2018 contrail ContrailEnterpriseMulticloud
Interop2018 contrail ContrailEnterpriseMulticloud
 
Opa gatekeeper
Opa gatekeeperOpa gatekeeper
Opa gatekeeper
 
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark OperatorApache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
 
Optimizing Application Performance on Kubernetes
Optimizing Application Performance on KubernetesOptimizing Application Performance on Kubernetes
Optimizing Application Performance on Kubernetes
 
CI/CD Across Multiple Environments
CI/CD Across Multiple EnvironmentsCI/CD Across Multiple Environments
CI/CD Across Multiple Environments
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
 
Deploying on Kubernetes - An intro
Deploying on Kubernetes - An introDeploying on Kubernetes - An intro
Deploying on Kubernetes - An intro
 
Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
 
Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
 
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
 
Docker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker eeDocker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker ee
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
 
Scaling docker with kubernetes
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetes
 
Ansiblefest 2018 Network automation journey at roblox
Ansiblefest 2018 Network automation journey at robloxAnsiblefest 2018 Network automation journey at roblox
Ansiblefest 2018 Network automation journey at roblox
 
An Introduction to Project riff, a FaaS Built on Top of Knative - Eric Bottard
An Introduction to Project riff, a FaaS Built on Top of Knative - Eric BottardAn Introduction to Project riff, a FaaS Built on Top of Knative - Eric Bottard
An Introduction to Project riff, a FaaS Built on Top of Knative - Eric Bottard
 

More from CodeOps Technologies LLP

More from CodeOps Technologies LLP (20)

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetup
 
Understanding azure batch service
Understanding azure batch serviceUnderstanding azure batch service
Understanding azure batch service
 
DEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNINGDEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNING
 
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONSSERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
 
Jet brains space intro presentation
Jet brains space intro presentationJet brains space intro presentation
Jet brains space intro presentation
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps Foundation
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
 
Improve customer engagement and productivity with conversational ai
Improve customer engagement and productivity with conversational aiImprove customer engagement and productivity with conversational ai
Improve customer engagement and productivity with conversational ai
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

YAML Tips For Kubernetes by Neependra Khare

  • 1. YAML Tips & Tricks for K8s Neependra Khare, CloudYuga @neependra
  • 2. About Me - Neependra Khare ● ● ● ● ● ●
  • 3. Agenda ● YAML Basics ● K8s & YAML ● K8s API Reference ● YAML Tips for K8s
  • 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
  • 9. API Group Core API Group Other API Groups
  • 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",|...
  • 15. 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 apiVersion: v1 kind: Pod metadata: name: mypod labels: app: nginx spec: containers: - name: nginx-demo image: nginx:alpine env: - name: VERSION value: “10.3” - name: NORWAY value: “NO” ports: - containerPort: 80
  • 16. Tip#3 - Use YAML Reference apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 3 selector: matchLabels: &labelsToMatch app: nginx env: dev template: metadata: labels: *labelsToMatch spec: containers: - name: nginx image: nginx:1.9.1 ports: - containerPort: 80 apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 3 selector: matchLabels: app: nginx env: dev template: metadata: labels: app: nginx env: dev spec: containers: - name: nginx image: nginx:1.9.1 ports: - containerPort: 80
  • 17. Tip#4 - Use YAML Linters, IDE Plugins ● Online ○ http://www.yamllint.com ● Offline ○ Yamllint CLI ■ https://github.com/adrienverge/yamllint ○ yq ■ https://github.com/mikefarah/yq ● IDE Plugins ○ VSCode ■ https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml ○ IntelliJ ■ https://www.jetbrains.com/help/idea/code-style-yaml.html