当前位置:网站首页>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边栏推荐
- Reading and writing of file content - data flow
- ROS node name duplicate
- 多线程CAS、synchronized锁原理 、JUC以及死锁
- Introduction to Wireshark graphical interface
- ROS distributed communication
- iptables防火墙及SNAT和DNAT
- rsync远程同步
- The concept of interface testing and the use of postman tools
- Network troubleshooting: Ping and tracert commands
- bug分类及缺陷和csv文件测试
猜你喜欢
随机推荐
Binary tree - search tree
PLL of IP core
Multi coordinate transformation
Addition, deletion, modification and query of the database at the terminal
Sexy prime number (acwing daily question)
多线程CAS、synchronized锁原理 、JUC以及死锁
Brief introduction to unity window interface
Knowledge supplement of multithreading
Unity practical tips (updating)
Index and transaction of database (emphasis)
Summary of Internet simple protocol
软件测试基础概念篇
Array and subscript index
Shell script if nested for loop script
Shell script loop
5g's past and present life -- a brief introduction to the development of mobile communication
Li Kou daily question leetcode 513. find the value in the lower left corner of the tree
Advanced ROS communication mechanism
FTP服务器的搭建
Unable to start program, access denied?









