美文网首页
log-pilot在k8s中运行报/var/run/docker

log-pilot在k8s中运行报/var/run/docker

作者: sexy_cyber | 来源:发表于2023-08-29 13:54 被阅读0次

背景


  • 我的K8s是用Kind部署安装的,Kind部署安装的K8s默认用的是containerd作为容器运行时,这是问题的根本
  • 最新版本的log-pilot registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.7-filebeat 根本不支持containerd容器运行时

解决方案


  • 1、有大佬做了个改进版:镜像地址
    image.png
  • 2、示例启动命令中其他配置都和原生的log-pilot一致,但是需要注意这一行-v /run/k3s/containerd/containerd.sock:/var/run/containerd/containerd.sock \,冒号前面的是宿主机的containerd运行时地址;一般来说是/run/containerd/containerd.sock,需要根据你自己的情况做修改
docker run -d \
   --name log-pilot-filebeat \
   -v /run/k3s/containerd/containerd.sock:/var/run/containerd/containerd.sock \
   -v /etc/localtime:/etc/localtime \
   -v /:/host:ro \
   --cap-add SYS_ADMIN \
   -e PILOT_LOG_PREFIX=glinux \
   -e LOGGING_OUTPUT=logstash \
   -e LOGSTASH_HOST=logstash.glinux.top \
   -e LOGSTASH_PORT=5063 \
   --restart=always \
   williamguozi/log-pilot-filebeat:containerd
  • 3、若要收集stdout日志(输出类型),那么还得再基于williamguozi/log-pilot-filebeat:containerd 做修改,参考

  • 4、完整的修改流程:

  • 4.1、进入服务器执行

docker pull williamguozi/log-pilot-filebeat:containerd
mkdir filebeat-modification
cd filebeat-modification
touch Dockerfile
vim Dockerfile
  • 4.2、Dockerfile 输入下面的内容(因为不能完全确定filebeat.tpl在容器内的什么路劲,故copy到了两个路劲,总有一个对吧)
FROM williamguozi/log-pilot-filebeat:containerd

# 将修改后的 filebeat.tpl 文件复制到镜像中
COPY filebeat.tpl /pilot/filebeat.tpl
COPY filebeat.tpl /pilot/assets/filebeat/filebeat.tpl
  • 4.3、从该地址下载文件 filebeat.tpl
  • 4.4、删除文件filebeat.tpl中的第8-10行
  {{if .Stdout}}
  docker-json: true
  {{end}}
  • 4.5、构建新的镜像
docker build -t uhub.service.ucloud.cn/drakespider/spider:logpilotc -f Dockerfile .
  • 4.6、将构建好的镜像推送到仓库
  • 4.7、K8s部署log-pilot
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: log-pilot-filebeat
spec:
  selector:
    matchLabels:
      app: log-pilot-filebeat
  template:
    metadata:
      labels:
        app: log-pilot-filebeat
    spec:
      imagePullSecrets:
        - name: ucloud-aliyun
      containers:
        - name: log-pilot-filebeat
          image: uhub.service.ucloud.cn/drakespider/spider:logpilotc
          volumeMounts:
            - name: containerd-sock
              mountPath: /var/run/containerd/containerd.sock
            - name: localtime
              mountPath: /etc/localtime
            - name: rootfs
              mountPath: /host
              readOnly: true
          securityContext:
            capabilities:
              add:
                - SYS_ADMIN
          env:
            - name: PILOT_LOG_PREFIX
              value: "bitget"
            - name: LOGGING_OUTPUT
              value: "elasticsearch"
            - name: ELASTICSEARCH_HOSTS
              value: "http://elasticsearch:9200"
            - name: ELASTICSEARCH_USER
              value: "elastic"
            - name: ELASTICSEARCH_PASSWORD
              value: "xxxx"
      volumes:
        - name: containerd-sock
          hostPath:
            path: /run/containerd/containerd.sock
        - name: localtime
          hostPath:
            path: /etc/localtime
        - name: rootfs
          hostPath:
            path: /
          readOnly: true
  • 4.8、完活(成功采集到日志并且推送到ES在kibana展示)


    爽歪歪

相关文章

网友评论

      本文标题:log-pilot在k8s中运行报/var/run/docker

      本文链接:https://www.haomeiwen.com/subject/ubgnmdtx.html