Kubernetes----资源清单定义DaemonSet.yaml

一、DaemonSet.yaml字段解释

在有限的节点上只运行一个副本,不需要指定replicas

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata: >
spec: >
  minReadySeconds: > #设置pod准备就绪的最小秒数
  revisionHistoryLimit: > #设置保留的历史版本个数,默认是10
  selector: > #pod标签选择器,匹配pod标签,默认使用pods的标签
    matchLabels: [string]string> 
      key1: value1
      key2: value2
    matchExpressions: <[]Object>
      operator: > -required- #设定标签键与一组值的关系,In, NotIn, Exists and DoesNotExist
      key: > -required-
      values: <[]string>
  template: > -required- 
    metadata:
      labels: 
        key1: value1
        key2: value2
    spec:
      containers: <[]Object> #容器配置
      - name: > -required- #容器名、DNS_LABEL
        image: > #镜像
        imagePullPolicy: > #镜像拉取策略,Always、Never、IfNotPresent
        ports: <[]Object>
        - name: #定义端口名
          containerPort: #容器暴露的端口
          protocol: TCP #或UDP
        volumeMounts: <[]Object>
        - name: > -required- #设置卷名称
          mountPath: > -required- #设置需要挂载容器内的路径
          readOnly: > #设置是否只读
        livenessProbe: > #就绪探测
          exec: 
            command: <[]string>
          httpGet:
            port: > -required-
            path: >
            host: >
            httpHeaders: <[]Object>
              name: > -required-
              value: > -required-
            scheme: > 
          initialDelaySeconds: > #设置多少秒后开始探测
          failureThreshold: > #设置连续探测多少次失败后,标记为失败,默认三次
          successThreshold: > #设置失败后探测的最小连续成功次数,默认为1
          timeoutSeconds: > #设置探测超时的秒数,默认1s
          periodSeconds: > #设置执行探测的频率(以秒为单位),默认1s
          tcpSocket: > #TCPSocket指定涉及TCP端口的操作
            port: > -required- #容器暴露的端口
            host: > #默认pod的IP
        readinessProbe: > #同livenessProbe
        resources: > #资源配置
          requests: [string]string> #最小资源配置
            memory: "1024Mi"
            cpu: "500m" #500m代表0.5CPU
          limits: [string]string> #最大资源配置
            memory:
            cpu:         
      volumes: <[]Object> #数据卷配置
      - name: > -required- #设置卷名称,与volumeMounts名称对应
        hostPath: > #设置挂载宿主机路径
          path: > -required- 
          type: > #类型:DirectoryOrCreate、Directory、FileOrCreate、File、Socket、CharDevice、BlockDevice
      - name: nfs
        nfs: > #设置NFS服务器
          server: > -required- #设置NFS服务器地址
          path: > -required- #设置NFS服务器路径
          readOnly: > #设置是否只读
      - name: configmap
        configMap: 
          name: > #configmap名称
          defaultMode: > #权限设置0~0777,默认0664
          optional: > #指定是否必须定义configmap或其keys
          items: <[]Object>
          - key: > -required-
            path: > -required-
            mode: >
      restartPolicy: > #重启策略,Always、OnFailure、Never
  templateGeneration: >
  updateStrategy: > #更新策略
    rollingUpdate: >
      maxUnavailable: >
    type: > #类型:滚动更新、在删除时更新
status: >

DaemonSet示例

监控组件node-exporter部署示例

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: node-exporter-ds
  namespace: gpe
  labels:
    name: node-exporter-ds
spec:
  minReadySeconds: 10
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: node
      type: host
  template:
    metadata:
      name: node-exporter
      namespace: gpe
      labels:
        app: node
        type: host
    spec:
      containers:
      - name: node-exporter
        image: prom/node-exporter:v0.18.0
        imagePullPolicy: Always
        ports:
        - name: http
          containerPort: 9100
        volumeMounts: #挂载卷路径
        - name: proc
          mountPath: /host/proc
          readOnly: true
        - name: sys
          mountPath: /host/sys
          readOnly: true
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        livenessProbe:
          httpGet:
            port: 9100
            path: /metrics
          initialDelaySeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            port: 9100
            path: /metrics
          initialDelaySeconds: 5
          failureThreshold: 3
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
      restartPolicy: Always #重启策略
      hostNetwork: true
      volumes:
      - name: proc
        hostPath:
          path: /proc
          type: Directory
      - name: sys
        hostPath:
          path: /sys
          type: Directory
      - name: rootfs
        hostPath:
          path: /
          type: Directory

你可能感兴趣的:(Kubernetes)