k8s定义yaml文件常用的一些字段

spec:
  replicas: 6  # 定义副本数量
  strategy:
    rollingUpdate: # 滚动更新通过参数 maxSurge 和 maxUnavailable 来控制副本替换的数量
      maxSurge: 35%
      maxUnavailable: 35% 
  template:
    spec:
      containers:
        livenessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy # 定义存活健康检查(exec方式)
        readinessProbe: # 定义就绪健康检查(httpGet方式)
          httpGet:
            scheme: HTTP
            path: /healthy
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
        volumeMounts: # 使用empty_dir作为存储(pod不在,volume也在)
        - mountPath: /consumer_dir
          name: shared-volume
        - mountPath: /etc/ssl/certs  # 使用host-path作为存储
          name: ca-certs
          readOnly: true
        - mountPath: /test-ebs # 使用外部的storage provider作为存储
          name: ebs-volume
        - name: foo # 通过volume的方式来使用secret
          mountPath: "/etc/foo"
          readOnly: true
        - name: foo # 通过volume的方式来使用configmap
          mountPath: /etc/foo
          readOnly: true
        env: # 通过env的方式来使用secret
          - name: SECRET_USERNAME
            valueFrom:
              secretKeyRef:
                name: my-secret
                key: username
          - name: SECRET_PASSWORD
            valueFrom:
              secretKeyRef:
                name: my-secret
                key: password
          - name: CONFIG_1 # 通过env的方式来使用configmap
            valueFrom:
              configMapKeyRef:
                name: my-configmap1
                key: config1
          - name: CONFIG_2
            valueFrom:
              configMapKeyRef:
                name: my-configmap1
                key: config2
      volumes:
      - name: shared-volume
        emptyDir: {}
      - hostPath:  # 使用host-path作为存储
          path: /etc/ssl/certs
          type: DirectoryOrCreate
        name: ca-certs
      - name: ebs-volume # 使用外部的storage provider作为存储
        awsElasticBlockStore:
          volumeID: <volume-id>
          fsType: ext4
      - name: wwwroot # 定义使用pvc来做存储
        persistentVolumeClaim:
          claimName: my-pvc
      - name: foo # 通过volume的方式来使用secret
        secret:
          secretName: mysecret
        items: # 自定义存放数据的文件名
        - key: username
          path: my-group/my-username
        - key: password
          path: my-group/my-password
      - name: foo # 通过volume的方式来使用configmap
        configMap:
          name: my-configmap
          items:
            - key: logging.conf
              path: myapp/logging.conf
      nodeSelector:
        disktype: ssd  # 定义节点标签选择器
posted @ 2020-12-15 17:29  Richardo-M-Lu  阅读(451)  评论(0编辑  收藏  举报