kubernetes学习-DaemonSet(六)

一、配置文件

apiVersion: apps/v1
kind: DaemonSet 
metadata:
  name: fluentd
spec:
  selector:
    matchLabels:
      app: logging
  template:
    metadata:
      labels:
        app: logging
        id: fluentd
      name: fluentd
    spec:
      containers:
      - name: fluentd-es
        image: agilestacks/fluentd-elasticsearch:v1.3.0
        imagePullPolicy: IfNotPresent
        env:
         - name: FLUENTD_ARGS
           value: -qq
        volumeMounts:
         - name: containers
           mountPath: /var/lib/docker/containers
         - name: varlog
           mountPath: /varlog
      volumes:
         - hostPath:
             path: /var/lib/docker/containers
           name: containers
         - hostPath:
             path: /var/log
           name: varlog


# 通过这种方式创建的daemonset,会在每个非master节点都创建pod

# 添加标签
[root@k8s-master daemonset]# kubectl label no k8s-node1 type=microservices
node/k8s-node1 labeled

查看标签,会发现k8s-node1多出一个标签

# 查看当前的部署情况
[root@k8s-master daemonset]# kubectl get po  -o wide
NAME            READY   STATUS    RESTARTS      AGE    IP               NODE        NOMINATED NODE   READINESS GATES
dns-test        1/1     Running   1 (23h ago)   2d2h   10.244.169.161   k8s-node2   <none>           <none>
fluentd-c8gpx   1/1     Running   0             23h    10.244.36.98     k8s-node1   <none>           <none>
fluentd-nps8w   1/1     Running   0             23h    10.244.169.163   k8s-node2   <none>           <none>

# 在 k8s-node1 和 k8s-node2 都有部署

二、指定节点

DaemonSet 会忽略 Node 的 unschedulable 状态,有两种方式来指定 Pod 只运行在指定的 Node 节点上:
nodeSelector:只调度到匹配指定 label 的 Node 上
nodeAffinity:功能更丰富的 Node 选择器,比如支持集合操作
podAffinity:调度到满足条件的 Pod 所在的 Node 上
先为 Node 打上标签
kubectl label nodes k8s-node1 svc_type=microsvc

然后再 daemonset 配置中设置 nodeSelector
spec:
  template:
    spec:
      nodeSelector:
        svc_type: microsvc


# 重新编辑配置文件
[root@k8s-master daemonset]# kubectl edit ds fluentd
apiVersion: apps/v1
kind: DaemonSet
metadata:
  annotations:
    deprecated.daemonset.template.generation: "1"
  creationTimestamp: "2025-01-06T17:13:22Z"
  generation: 1
  name: fluentd
  namespace: default
  resourceVersion: "301917"
  uid: 75f82c83-c526-4bba-8ce9-983343b1d30d
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: logging
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: logging
        id: fluentd
      name: fluentd
    spec:
      nodeSelector:
        type: microservices
      containers:
      - env:
        - name: FLUENTD_ARGS
          value: -qq
        image: agilestacks/fluentd-elasticsearch:v1.3.0
        imagePullPolicy: IfNo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值