一、kubernetes集群YAML文件详解:yaml文件说明

|NO.Z.00012|——————————|CloudNative|—_文件创建

二、快速书写yaml文件

|NO.Z.00012|——————————|CloudNative|—_文件创建_02


三、方式一:yaml文件创建

### --- 第一种方式:create命令生成yaml文件

[root@k8s-master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run # -o yaml把操作用yaml格式生成出, -yaml-dry-run尝试运行,但不正运行
W0222 14:58:10.603590 34484 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
### --- 模板文件生成,可以作为模板
~~~ 输出生成my1.yaml文件

[root@k8s-master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run >my1.yaml
W0222 14:59:57.039704 34808 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
### --- 可以通过实际的环境中来配置自己的部署环境

[root@k8s-master ~]# cat my1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}

四、方式二:yaml文件创建

### --- 第二种方式:get命令导出yaml文件;针对于目前已经部署好的环境
~~~ ginx -o=yaml:nginx相关的格式通过yaml格式导出 --export:放到一个文件中

[root@k8s-master ~]# kubectl get deploy nginx -o=yaml --export > my2.yaml
Flag --export has been deprecated, This flag is deprecated and will be removed in future.
[root@k8s-master ~]# ll
total 8
-rw-r--r-- 1 root root 376 Feb 22 14:59 my1.yaml
-rw-r--r-- 1 root root 3026 Feb 22 15:04 my2.yaml
[root@k8s-master ~]# cat my2.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: null
generation: 1
labels:
app: nginx
managedFields:
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels:
.: {}
f:app: {}
f:spec:
f:progressDeadlineSeconds: {}
f:replicas: {}
f:revisionHistoryLimit: {}
f:selector:
f:matchLabels:
.: {}
f:app: {}
f:strategy:
f:rollingUpdate:
.: {}
f:maxSurge: {}
f:maxUnavailable: {}
f:type: {}
f:template:
f:metadata:
f:labels:
.: {}
f:app: {}
f:spec:
f:containers:
k:{"name":"nginx"}:
.: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:dnsPolicy: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: kubectl
operation: Update
time: "2021-02-19T09:04:17Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:deployment.kubernetes.io/revision: {}
f:status:
f:availableReplicas: {}
f:conditions:
.: {}
k:{"type":"Available"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
k:{"type":"Progressing"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
f:observedGeneration: {}
f:readyReplicas: {}
f:replicas: {}
f:updatedReplicas: {}
manager: kube-controller-manager
operation: Update
time: "2021-02-22T06:25:12Z"
name: nginx
selfLink: /apis/apps/v1/namespaces/default/deployments/nginx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
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: {}

五、kubectl命令行工具

|NO.Z.00012|——————————|CloudNative|—_flink_03













Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart

                                                                                                                                                   ——W.S.Landor