美文网首页
2020-07-27 资源编排(YAML)

2020-07-27 资源编排(YAML)

作者: 阿丧小威 | 来源:发表于2020-07-27 22:44 被阅读0次

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文件创建资源对象

图片.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下的所有字段

相关文章

网友评论

      本文标题:2020-07-27 资源编排(YAML)

      本文链接:https://www.haomeiwen.com/subject/loutrktx.html