当前位置: 首页 > news >正文

使用EFK收集k8s日志

首先我们使用EFK收集Kubernetes集群中的日志,本次实验讲解的是在Kubernetes集群中启动一个Elasticsearch集群,如果企业内已经有了Elasticsearch集群,可以直接将日志输出至已有的Elasticsearch集群。

文章目录

  • 部署elasticsearch
  • 创建Kibana
  • 创建Fluentd:
  • 查看kibana

部署elasticsearch

下载需要的部署文件:

git clone https://gitee.com/qfxcoffee/shield.gitcd shield/sh/k8s/efk

创建EFK所用的命名空间:

kubectl create -f create-logging-namespace.yaml

创建Elasticsearch集群:

[root@control-plane efk-7.10.2]# kubectl create -f es-service.yaml -f es-statefulset.yaml
service/elasticsearch-logging created
serviceaccount/elasticsearch-logging created
clusterrole.rbac.authorization.k8s.io/elasticsearch-logging created
clusterrolebinding.rbac.authorization.k8s.io/elasticsearch-logging created
statefulset.apps/elasticsearch-logging created

创建Kibana

[root@control-plane efk-7.10.2]# kubectl create -f kibana-deployment.yaml -f kibana-service.yaml
deployment.apps/kibana-logging created
service/kibana-logging created

创建Fluentd:

由于在Kubernetes集群中,可能并不需要对所有的机器都采集日志,因此可以更改Fluentd的部署文件如下,添加一个NodeSelector,只部署至需要采集的主机即可:

[root@control-plane efk-7.10.2]# kubectl get node
NAME                              STATUS   ROLES                  AGE   VERSION
control-plane.minikube.internal   Ready    control-plane,master   18d   v1.23.7[root@control-plane efk-7.10.2]# kubectl label node control-plane.minikube.internal fluentd=true[root@control-plane efk-7.10.2]# kubectl get node -l fluentd=true --show-labels
NAME                              STATUS   ROLES                  AGE   VERSION   LABELS
control-plane.minikube.internal   Ready    control-plane,master   18d   v1.23.7   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,fluentd=true,kubernetes.io/arch=amd64,kubernetes.io/hostname=control-plane.minikube.internal,kubernetes.io/os=linux,minikube.k8s.io/commit=210b148df93a80eb872ecbeb7e35281b3c582c61,minikube.k8s.io/name=minikube,minikube.k8s.io/primary=true,minikube.k8s.io/updated_at=2024_11_05T14_44_37_0700,minikube.k8s.io/version=v1.34.0,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=

创建Fluentd:

[root@control-plane efk-7.10.2]# kubectl create -f fluentd-es-ds.yaml -f fluentd-es-configmap.yaml
serviceaccount/fluentd-es created
clusterrole.rbac.authorization.k8s.io/fluentd-es created
clusterrolebinding.rbac.authorization.k8s.io/fluentd-es created
daemonset.apps/fluentd-es-v3.1.1 created
configmap/fluentd-es-config-v0.2.1 created

Fluentd的ConfigMap有一个字段需要注意,在fluentd-es-configmap.yaml最后有一个output.conf:

在这里插入图片描述

查看kibana

http://192.168.56.115:32678/kibana/app/home#/

在这里插入图片描述
可以看到整个流程已经打通了。

http://www.lryc.cn/news/490607.html

相关文章:

  • 聚水潭与MySQL数据集成案例分享
  • Python 版本的 2024详细代码
  • SpringCloud框架学习(第四部分:Gateway网关)
  • C++ 类和对象 (上 )
  • HAProxy面试题及参考答案(精选80道面试题)
  • 探索PyCaret:一个简化机器学习的全栈库
  • 英语写作中“联系、关联”associate correlate 及associated的用法
  • 深度学习之目标检测的技巧汇总
  • 【Flask+Gunicorn+Nginx】部署目标检测模型API完整解决方案
  • Spark核心组件解析:Executor、RDD与缓存优化
  • “AI玩手机”原理揭秘:大模型驱动的移动端GUI智能体
  • 离散数学【关系】中的一些特殊关系
  • docker 配置代理
  • Dockerfile详解:构建简单高效的容器镜像
  • RHCD-----shell
  • <硬件有关> 内存攒机认知入门,内存的选择 配置 laptop PC 服务器
  • 基于springboot的来访管理系统的设计与实现
  • window11编译pycdc.exe
  • 11.22.2024 面试后记
  • Bug Fix 20241122:缺少lib文件错误
  • Pinia 实战教程:构建高效的 Vue 3 状态管理系统
  • springboot3如何集成knife4j 4.x版本及如何进行API注解
  • 区块链讲解
  • 使用eclipse构建SpringBoot项目
  • uniapp input限制输入负数,以及保留小数点两位.
  • 《FreeRTOS任务删除篇》
  • 递归算法专题一>Pow(x, n)
  • 数据结构第一讲
  • SHELL笔记(循环)
  • SpringBoot多文件上传