当前位置:网站首页>How to write yaml file in a standard way
How to write yaml file in a standard way
2022-07-27 06:33:00 【Little candy man】
1、Yaml grammar
1.1 Use white space and indentation to represent hierarchy ( It's kind of similar Python), Curly braces and square brackets can be omitted .
1.2 have access to # Write notes , Compared with JSON It's a big improvement .
1.3 object ( Dictionaries ) The format and JSON Basically the same , but Key You don't need to use double quotes , Use {a,b,c}.
1.4 Array ( list ) It's using - List form at the beginning , Use [a,b,c].
1.5 Representing the object : And representing an array - There must be a space after it . have access to --- Separate multiple in one file YAML object .
2、Ymal Illustrate with examples
2.1 Array example
# YAML Array ( list )
OS:
- linux
- macOS
- Windows
--------------------------
#josn Array
{
"OS": ["linux", "macOS", "Windows"]
}2.2 YAML object ( Dictionaries )
# YAML object ( Dictionaries )
Kubernetes:
master: 1
worker: 3
----------------------
#json object
{
"Kubernetes": {
"master": 1,
"worker": 3
}
}2.3 Yaml Array Object combination example
# Yaml Array Object combination
Kubernetes:
master:
- apiserver: running
- etcd: running
node:
- kubelet: running
- kube-proxy: down
- container-runtime: [docker, containerd, cri-o]3、Yaml Format specification
apiVersion: v1 #API Version number , Because different versions are different , So we need to distinguish versions .
kind: Pod # The type of resource object , Yes pod,Node,Job,Service
metadata: # Meta information , Mark the object , Easy to manage
name: ngx-pod #pod give a name
labels: # to pod tagging , Easy to find
env: demo
owner: feifei
spec: #POD Information about the content container
containers: # Containers
- image: nginx:alpine # Run container image
name: ngx # Container name
ports: # Port number
- containerPort: 80 # Declare container port number 3.1 yaml File creation and deletion
kubectl apply -f ngx-pod.yml
kubectl delete -f ngx-pod.yml4、 To write yaml skill
4.1 First skill first Official documents
4.2 The second technique uses Kubectl api-resources command , Displays the corresponding API Version and type , for example pods The version is v1 runtimeclasses The version is node.k8s.io/v1
[email protected]:~$ kubectl api-resources
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
events ev v1 true Event
limitranges limits v1 true LimitRange
namespaces ns v1 false Namespace
nodes no v1 false Node
persistentvolumeclaims pvc v1 true PersistentVolumeClaim
persistentvolumes pv v1 false PersistentVolume
pods po v1 true Pod
podtemplates v1 true PodTemplate
replicationcontrollers rc v1 true ReplicationController
resourcequotas quota v1 true ResourceQuota
secrets v1 true Secret
serviceaccounts sa v1 true ServiceAccount
services svc v1 true Service
runtimeclasses node.k8s.io/v1 false Runtime
4.3 The third skill is to use commands kubectl explain, It's quite so Kubernetes-api Help document , Will make a detailed description of the target object . Particular attention . Dot notation , for example kuebectl explain pod.spec.volumes, A point represents a target object , The more points , The deeper the hierarchy .
[email protected]:~$ kubectl explain pod.spec.volumes.vsphereVolume
KIND: Pod
VERSION: v1
RESOURCE: vsphereVolume <Object>
DESCRIPTION:
VsphereVolume represents a vSphere volume attached and mounted on kubelets
host machine
Represents a vSphere volume resource.
FIELDS:
fsType <string>
Filesystem type to mount. Must be a filesystem type supported by the host
operating system. Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be
"ext4" if unspecified.
storagePolicyID <string>
Storage Policy Based Management (SPBM) profile ID associated with the
StoragePolicyName.
storagePolicyName <string>
Storage Policy Based Management (SPBM) profile name.
volumePath <string> -required-
Path that identifies vSphere volume vmdk
4.4 The fourth technique , Give Way kubectl Directly generate a template for us , Namely kubectl Two special parameters of --dry-run=client and -o yaml, The former is empty , The latter is generation yaml Format , Combined use will make kubectl There will be no actual creation action , And only generate yaml file .
# Generate pod Of yaml Sample template , Can be in kubectl run Add these two parameters later
--dry-run=client -o yaml Then redirect to a directory , It can't be under the root directory
kubectl run ngx --image=nginx:alpine --dry-run=client -o yaml > /tmp/pod.yaml
kubectl run ngx --image=nginx:alpine --dry-run=client -o yaml >/tmp/pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: ngx
name: ngx
spec:
containers:
- image: nginx:alpine
name: ngx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
4.5 And then on the generated yaml File for editing , Make sure to generate , Or delete
4.6 Can also be kubectl Two parameters of alias Define it , Generating variables
export do="--dry-run=client -o yaml"
kubectl run ngx --image=nginx:alpine $do边栏推荐
猜你喜欢

多线程的知识补充

Ulcl function --5gc

Learning the operation environment needs to be equipped during software testing

Brief introduction to unity window interface

数据库在终端的增删改查

Detailed explanation of thread safety problems

Knowledge supplement of multithreading

Wireshark graphical interface capture

Reading and writing of file content - data flow

Database commands
随机推荐
线程安全问题详解
英语基础知识: 并列结构
KVM命令集管理虚拟机
Unable to start program, access denied?
Markdown文档常用字体及颜色设置
Progress in remote sensing image recognition 2022/5/5
源码编译安装LNMP和DISCUZ论坛
jmeter简介
Wireshark function introduction
Introduction to JMeter
Unityshader Gaussian blur
多线程CAS、synchronized锁原理 、JUC以及死锁
Programming learning record -- recursively solving the tower of Hanoi problem
二叉树——搜索树
Using markdowm
Launch file of ROS operation management
Header and source files in ROS
Strategies for common locks in multithreading
PXE高效批量网络装机
ROS node name duplicate