【超级节点】使用 DS 注入能力收集容器业务日志

使用背景:

想要使用 filebeat 等第三方日志收集工具采集业务容器日志, 如何将业务容器的日志暴露给 filebeat ,可以通过超级节点注入 Daemonset 容器实现, 这里给出一个最小挂载配置的示例 YAML 供参考(注意日志收集逻辑需要业务自行配置)。

注入能力版本要求:

挂载示例:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    k8s-app: filebeat
  name: filebeat
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: filebeat
  template:
    metadata:
      annotations:
        eks.tke.cloud.tencent.com/ds-injection: "true"
      labels:
        k8s-app: filebeat
    spec:
      containers:
      - name: filebeat
        image: filebeat:8.0.0
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /var/log/containers
          name: containers-log
          readOnly: true
        - mountPath: /var/log/pods
          name: pods-log
          readOnly: true
      volumes:
      - hostPath:
          path: /var/log/pods # 需确保 pods 标准输出日志的真实文件目录被挂载,要不然无法获取日志。
          type: ""
        name: pods-log
      - hostPath:
          path: /var/log/containers # 挂载容器日志的软链目录
          type: ""
        name: containers-log
      tolerations:
      - key: eks.tke.cloud.tencent.com/eklet
        operator: Exists
        effect: NoSchedule

使用说明:

本示例 filebeat 感知的收集目录格式为 /var/log/containers/<pod_name>_<namespace>_<container_name>-<container_id>.log,可登陆容器查看相关目录文件是否可以获取容器日志:

cat  /var/log/containers/<pod_name>_<namespace>_<container_name>-<container_id>.log

注意如果登陆或查看注入容器报错 “container xxx is not valid for pod xxx” ,请使用官网文档描述的 kubectl 版本(linux 版本),下载命令:curl -LO "https://dl.k8s.io/release/v1.16.0/bin/linux/amd64/kubectl"

参考文档:

超级节点 Daemonset 注入:https://cloud.tencent.com/document/product/457/98730

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值