一、DaemonSet.yaml字段解释

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

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

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
Logo

开源、云原生的融合云平台

更多推荐