当前位置:网站首页>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边栏推荐
- 多线程的相关知识
- Programming learning records - Lesson 6 [functions]
- Binary tree - search tree
- 英语基础知识:非谓语使用规则上篇
- C language -- string operation function and memory operation function
- Random points in non overlapping rectangle (force deduction daily question)
- PLL of IP core
- 线程安全问题详解
- Sexy prime number (acwing daily question)
- 基于Apache下ab工具进行网站压力性能测试
猜你喜欢

Communication mechanism cases

shell脚本循环

Detailed explanation of thread safety problems

单元集成(接⼝)测试

Navigation related messages

Database commands

Li Kou daily question leetcode 513. find the value in the lower left corner of the tree

互联网简单协议概括

Index and transaction of database (emphasis)

Briefly remember the top ten orders
随机推荐
数据库的约束以及设计
Path to file
英语基础知识:非谓语使用规则上篇
C language - file operation
软件测试用里篇
多线程常见锁的策略
shell脚本循环
Navigation related messages
Shell programming specifications and variables
Function call of shell script
Remote sensing image recognition training strategy
Shell语句判断练习题
远程访问及控制
Unity hub login no response
Array and subscript index
shell之if条件语句
正则表达式
Launch file of ROS operation management
iptables防火墙及SNAT和DNAT
Related knowledge of internal classes