2020-07-27 資源編排(YAML)

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下的所有字段
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容