背景

创建时间:2025-10-24 最近修改时间:2025-10-24

#1. 背景

在腾讯云的 TKE 超级容器节点方案中,虽然租户可以看到超级容器节点,但该节点实际并不存在,仅仅是一个虚拟的 Node,实际是 Serverless 的技术架构。 因此 DeepFlow Agent 无法直接用正常的 DaemonSet 方式进行部署,需要特殊的配置。

#2. 部署方案

在 Serverless 环境中,需要部署2类DeepFlow Agent:

  • 1 个 Deployment 类型的 DeepFlow Agent——该 Pod 用于 Watch K8s资源
  • 1 个 DaemonSet 类型的 DeepFlow Agent——该 Pod 表面是一个 DaemonSet 的 Pod,实际是以 Sidecar 形式注入在业务 Pod 中,因此注册时会使用业务 Pod 的 IP、MAC 进行注册,并采集业务 Pod 的数据。 因此在部署时,需要分别 apply 2 个部署模板:Deployment、DaemonSet;具体配置文件见下文。

#3. 部署模版

#3.1 DaemonSet 的yaml文件样例

  • 注意事项:
    • 将该参数修改为“true”

      调整参数一

      调整参数一

    • 增加 args、command 配置

      调整参数二

      调整参数二

    • 增加:CTRL_NETWORK_INTERFACE

      调整参数三

      调整参数三

    • 修改 filedPatch 为 status.hostIP

      调整参数四

      调整参数四

#3.1.1 样例 Yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  annotations:
    deprecated.daemonset.template.generation: "9"
  creationTimestamp: "2025-08-31T05:45:36Z"
  generation: 9
  labels:
    app: deepflow
    component: deepflow-agent
  managedFields:
  - apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:currentNumberScheduled: {}
        f:desiredNumberScheduled: {}
        f:numberReady: {}
        f:numberUnavailable: {}
        f:observedGeneration: {}
    manager: kube-controller-manager
    operation: Update
    subresource: status
    time: "2025-08-31T09:02:38Z"
  - apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:deprecated.daemonset.template.generation: {}
        f:labels:
          .: {}
          f:app: {}
          f:component: {}
      f:spec:
        f:revisionHistoryLimit: {}
        f:selector: {}
        f:template:
          f:metadata:
            f:annotations:
              .: {}
              f:container.apparmor.security.beta.kubernetes.io/deepflow-agent: {}
              f:eks.tke.cloud.tencent.com/ds-injection: {}
            f:labels:
              .: {}
              f:app: {}
              f:component: {}
          f:spec:
            f:containers:
              k:{"name":"deepflow-agent"}:
                .: {}
                f:args: {}
                f:command: {}
                f:env:
                  .: {}
                  k:{"name":"CTRL_NETWORK_INTERFACE"}:
                    .: {}
                    f:name: {}
                    f:value: {}
                  k:{"name":"K8S_NAMESPACE_FOR_DEEPFLOW"}:
                    .: {}
                    f:name: {}
                    f:valueFrom:
                      .: {}
                      f:fieldRef: {}
                  k:{"name":"K8S_NODE_IP_FOR_DEEPFLOW"}:
                    .: {}
                    f:name: {}
                    f:valueFrom:
                      .: {}
                      f:fieldRef: {}
                  k:{"name":"K8S_NODE_NAME_FOR_DEEPFLOW"}:
                    .: {}
                    f:name: {}
                    f:valueFrom:
                      .: {}
                      f:fieldRef: {}
                  k:{"name":"K8S_POD_IP_FOR_DEEPFLOW"}:
                    .: {}
                    f:name: {}
                    f:valueFrom:
                      .: {}
                      f:fieldRef: {}
                  k:{"name":"K8S_POD_NAME_FOR_DEEPFLOW"}:
                    .: {}
                    f:name: {}
                    f:valueFrom:
                      .: {}
                      f:fieldRef: {}
                  k:{"name":"K8S_WATCH_POLICY"}:
                    .: {}
                    f:name: {}
                    f:value: {}
                  k:{"name":"PROCFS_ROOT"}:
                    .: {}
                    f:name: {}
                    f:value: {}
                  k:{"name":"SYSFS_ROOT"}:
                    .: {}
                    f:name: {}
                    f:value: {}
                f:image: {}
                f:imagePullPolicy: {}
                f:name: {}
                f:ports:
                  .: {}
                  k:{"containerPort":38086,"protocol":"TCP"}:
                    .: {}
                    f:containerPort: {}
                    f:name: {}
                    f:protocol: {}
                f:resources:
                  .: {}
                  f:limits:
                    .: {}
                    f:cpu: {}
                    f:memory: {}
                  f:requests:
                    .: {}
                    f:cpu: {}
                    f:memory: {}
                f:securityContext:
                  .: {}
                  f:capabilities:
                    .: {}
                    f:add: {}
                f:terminationMessagePath: {}
                f:terminationMessagePolicy: {}
                f:volumeMounts:
                  .: {}
                  k:{"mountPath":"/etc/deepflow-agent"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                  k:{"mountPath":"/host/proc"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                    f:readOnly: {}
                  k:{"mountPath":"/host/sys"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                    f:readOnly: {}
                  k:{"mountPath":"/sys/kernel/debug"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                  k:{"mountPath":"/var/log/"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                  k:{"mountPath":"/var/log/deepflow-agent/"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                  k:{"mountPath":"/var/log/pods/"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                    f:readOnly: {}
                  k:{"mountPath":"/var/run/netns"}:
                    .: {}
                    f:mountPath: {}
                    f:mountPropagation: {}
                    f:name: {}
                  k:{"mountPath":"/vector-log-checkpoint"}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
            f:dnsPolicy: {}
            f:hostNetwork: {}
            f:hostPID: {}
            f:imagePullSecrets:
              .: {}
              k:{"name":"pass"}: {}
            f:restartPolicy: {}
            f:schedulerName: {}
            f:securityContext: {}
            f:serviceAccount: {}
            f:serviceAccountName: {}
            f:terminationGracePeriodSeconds: {}
            f:tolerations: {}
            f:volumes:
              .: {}
              k:{"name":"checkpoint"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"deepflow-agent-conf"}:
                .: {}
                f:configMap:
                  .: {}
                  f:defaultMode: {}
                  f:name: {}
                f:name: {}
              k:{"name":"logs"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"netns"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"pod-log"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"procfs"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"sys-kernel-debug"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"sysfs"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
              k:{"name":"var-log"}:
                .: {}
                f:hostPath:
                  .: {}
                  f:path: {}
                  f:type: {}
                f:name: {}
        f:updateStrategy:
          f:rollingUpdate:
            .: {}
            f:maxSurge: {}
            f:maxUnavailable: {}
          f:type: {}
    manager: tke-platform-api
    operation: Update
    time: "2025-08-31T09:02:38Z"
  name: deepflow-agent
  namespace: yunshan-deepflow
  resourceVersion: "915170088"
  uid: 620404c4-6852-4e1d-b585-39aae07d0b8d
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: deepflow
      component: deepflow-agent
  template:
    metadata:
      annotations:
        container.apparmor.security.beta.kubernetes.io/deepflow-agent: unconfined
        eks.tke.cloud.tencent.com/ds-injection: "true"
      creationTimestamp: null
      labels:
        app: deepflow
        component: deepflow-agent
    spec:
      containers:
      - args:
        - --sidecar
        - -f
        - /etc/deepflow-agent/deepflow-agent.yaml
        command:
        - /usr/bin/deepflow-agent
        env:
        - name: K8S_NAMESPACE_FOR_DEEPFLOW
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: K8S_NODE_IP_FOR_DEEPFLOW
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: status.hostIP
        - name: K8S_NODE_NAME_FOR_DEEPFLOW
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: CTRL_NETWORK_INTERFACE
          value: eth0
        - name: K8S_POD_NAME_FOR_DEEPFLOW
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: K8S_WATCH_POLICY
          value: watch-disabled
        - name: K8S_POD_IP_FOR_DEEPFLOW
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: status.hostIP
        - name: PROCFS_ROOT
          value: /host/proc
        - name: SYSFS_ROOT
          value: /host/sys
        image: yunshan.tencentcloudcr.com/yunshan/deepflow-agent:1.0-5469
        imagePullPolicy: IfNotPresent
        name: deepflow-agent
        ports:
        - containerPort: 38086
          name: receive
          protocol: TCP
        resources:
          limits:
            cpu: "1"
            memory: 768Mi
          requests:
            cpu: 100m
            memory: 128Mi
        securityContext:
          capabilities:
            add:
            - SYS_ADMIN
            - SYS_RESOURCE
            - SYS_PTRACE
            - NET_ADMIN
            - NET_RAW
            - IPC_LOCK
            - SYSLOG
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /sys/kernel/debug
          name: sys-kernel-debug
        - mountPath: /etc/deepflow-agent
          name: deepflow-agent-conf
        - mountPath: /var/log/deepflow-agent/
          name: logs
        - mountPath: /var/run/netns
          mountPropagation: HostToContainer
          name: netns
        - mountPath: /host/proc
          name: procfs
          readOnly: true
        - mountPath: /host/sys
          name: sysfs
          readOnly: true
        - mountPath: /vector-log-checkpoint
          name: checkpoint
        - mountPath: /var/log/
          name: var-log
        - mountPath: /var/log/pods/
          name: pod-log
          readOnly: true
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      hostPID: true
      imagePullSecrets:
      - name: pass
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: deepflow-agent
      serviceAccountName: deepflow-agent
      terminationGracePeriodSeconds: 30
      tolerations:
      - effect: NoSchedule
        key: eks.tke.cloud.tencent.com/eklet
        operator: Exists
      volumes:
      - hostPath:
          path: /sys/kernel/debug
          type: ""
        name: sys-kernel-debug
      - configMap:
          defaultMode: 420
          name: deepflow-agent-config
        name: deepflow-agent-conf
      - hostPath:
          path: /var/log/deepflow-agent
          type: DirectoryOrCreate
        name: logs
      - hostPath:
          path: /var/run/netns
          type: ""
        name: netns
      - hostPath:
          path: /proc
          type: ""
        name: procfs
      - hostPath:
          path: /sys
          type: ""
        name: sysfs
      - hostPath:
          path: /var/lib/vector
          type: DirectoryOrCreate
        name: checkpoint
      - hostPath:
          path: /var/log
          type: ""
        name: var-log
      - hostPath:
          path: /var/log/pods/
          type: ""
        name: pod-log
  updateStrategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 5%
    type: RollingUpdate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

#3.2 Deployment 的 yaml 文件样例

  • 注意事项:
    • 需根据环境修改 image 配置项

      调整参数一

      调整参数一

    • 需配置 POD 环境变量“K8S_WATCH_POLICY”,设置为“watch-only”

      调整参数二

      调整参数二

    • 副本数修改为 1

      调整参数三

      调整参数三

#3.2.1 样例 Yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deepflow-agent-watcher
  namespace: yunshan-deepflow
  labels:
    app: deepflow
    component: deepflow-agent
spec:
  ### Update policy with a maximum update ratio of 10% and a maximum number of unavailable Pods of 5%
  replicas: 1
  updateStrategy:
    rollingUpdate:
      maxUnavailable: 5%
    type: RollingUpdate
  selector:
    matchLabels:
      app: deepflow
      component: deepflow-agent
  template:
    metadata:
      annotations:
        eks.tke.cloud.tencent.com/ds-injection: "true"
        container.apparmor.security.beta.kubernetes.io/deepflow-agent: unconfined
      labels:
        app: deepflow
        component: deepflow-agent
    spec:
      ## 如果使用 HostNetwork 模式,dnsPolicy 需配置为 ClusterFirstWithHostNet
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      hostPID: true
      imagePullSecrets: []
      serviceAccountName: deepflow-agent
      tolerations:
        - key: eks.tke.cloud.tencent.com/eklet
          operator: Exists
          effect: NoSchedule
      # 需确认集群是否有需要主动开启 net.core.bpf_jit_enable=1
      # initContainers:
      # - name: configure-sysctl
      #   securityContext:
      #     runAsUser: 0
      #     privileged: true
      #   image: "deepflow-agent:latest"
      #   imagePullPolicy: Always
      #   command: ["sysctl", "-w", "net.core.bpf_jit_enable=1"]
      containers:
        - name: deepflow-agent
          securityContext:
            capabilities:
              add:
              - SYS_ADMIN
              - SYS_RESOURCE
              - SYS_PTRACE
              - NET_ADMIN
              - NET_RAW
              - IPC_LOCK
              - SYSLOG
          image: "yunshan.tencentcloudcr.com/yunshan/deepflow-agent:1.0-5469"
          imagePullPolicy: Always
          ## K8s 环境下,资源限制由此配置,页面配置的 CPU/MEM 无法生效
          resources:
            limits:
              cpu: "1"
              memory: 768Mi
            requests:
              cpu: 100m
              memory: 128Mi
          ports:
            - name: receive
              containerPort: 38086
              protocol: TCP
          # livenessProbe:
          #   tcpSocket:
          #     port: otel
          #   initialDelaySeconds: 5
          #   periodSeconds: 10
          # readinessProbe:
          #   tcpSocket:
          #     port: otel
          #   initialDelaySeconds: 5
          #   periodSeconds: 10
          env:
          - name: K8S_WATCH_POLICY
            value: "watch-only"
          - name: K8S_NAMESPACE_FOR_DEEPFLOW
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: K8S_NODE_IP_FOR_DEEPFLOW
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: K8S_NODE_NAME_FOR_DEEPFLOW
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: K8S_POD_NAME_FOR_DEEPFLOW
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: K8S_POD_IP_FOR_DEEPFLOW
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: PROCFS_ROOT
            value: /host/proc
          - name: SYSFS_ROOT
            value: /host/sys
          volumeMounts:
            - name: sys-kernel-debug
              mountPath: /sys/kernel/debug
            - name: deepflow-agent-conf
              mountPath: /etc/deepflow-agent
            - name: logs
              mountPath: /var/log/deepflow-agent/
              subPath: ""
            - name: netns # required to access net namespace info
              mountPath: /var/run/netns
              mountPropagation: HostToContainer
            - name: procfs
              mountPath: /host/proc
              readOnly: true
            - name: sysfs
              mountPath: /host/sys
              readOnly: true
            - name: checkpoint
              mountPath: /vector-log-checkpoint
            - name: var-log
              mountPath: /var/log/
            - name: pod-log
              mountPath: /var/log/pods/
              readOnly: true
      volumes:
        - name: sys-kernel-debug
          hostPath:
            path: /sys/kernel/debug
        - name: deepflow-agent-conf
          configMap:
            name: deepflow-agent-config
        - name: logs
          hostPath:
            type: DirectoryOrCreate
            path: /var/log/deepflow-agent
        - name: netns
          hostPath:
            path: /var/run/netns
        - name: procfs
          hostPath:
            path: /proc
            type: ""
        - name: sysfs
          hostPath:
            path: /sys
            type: ""
        - name: checkpoint
          hostPath:
            path: /var/lib/vector
            type: DirectoryOrCreate
        - name: var-log
          hostPath:
            path: /var/log
            type: ""
        - name: pod-log
          hostPath:
            path: /var/log/pods/
            type: ""

            
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

#3.3 ConfigMap文件

与普通 K8s 部署文件相同

#4. 安装 deepflow-agent

kubectl create ns yunshan-deepflow
kubectl -n yunshan-deepflow apply -f deepflow-agent-cm.yaml
kubectl -n yunshan-deepflow apply -f deepflow-agent-ds.yaml
kubectl -n yunshan-deepflow apply -f deepflow-agent-deploy.yaml
1
2
3
4

#5. 结果

在采集器列表中能看到 Deployment、DaemonSet 的 DeepFlow Agent,其中 DaemonSet 的采集器名、IP、MAC 与业务 POD 相同。
1