1. YAML文件格式說明
YAML是一種簡潔的非標記語言。
語法格式:
- 縮進表示層級關系
- 不支持制表符“tab”縮進,使用空格縮進
- 通常開頭縮進2 個空格
- 字符后縮進1 個空格,如冒號、逗號等
- “---” 表示YAML格式,一個文件的開始
- “#”注釋
示例:
[root@k8s-master1 ~]# kubectl get deploy -o yaml
apiVersion: v1
items:
- apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2020-07-26T13:15:28Z"
generation: 1
labels:
app: web
name: web
namespace: default
resourceVersion: "14633"
selfLink: /apis/apps/v1/namespaces/default/deployments/web
uid: c85e6a81-e83f-4afd-a427-15b44d44c0cc
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: web
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2020-07-26T13:48:32Z"
lastUpdateTime: "2020-07-26T13:48:32Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2020-07-26T13:48:32Z"
lastUpdateTime: "2020-07-26T13:48:32Z"
message: ReplicaSet "web-d86c95cc9" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
---省略若干---
2. YAML文件創(chuàng)建資源對象

圖片.png

圖片.png
3. 資源字段太多,記不住怎么辦
- 用create命令生成
kubectl create deployment nginx --image=nginx:1.14 -o yaml --dry-run> my-deploy.yaml
--- -o yaml,提交成yaml文件;--dry-run,嘗試運行,不會在k8s上運行 - 用get命令導出
kubectl get my-deploy/nginx-o=yaml --export > my-deploy.yaml - Pod容器的字段拼寫忘記了
kubectl explain pods.spec.containers
---獲取pods下的spec下的containers下的所有字段