Kubernetes 开发了一个 Elasticsearch 附加组件来实现集群的日志管理。这是一个 Elasticsearch、Fluentd 和 Kibana 的组合。

Elasticsearch 是一个搜索引擎,负责存储日志并提供查询接口;

Fluentd 负责从 Kubernetes 搜集日志,每个node节点上面的fluentd监控并收集该节点上面的系统日志,并将处理过后的日志信息发送给Elasticsearch;

Kibana 提供了一个 Web GUI,用户可以浏览和搜索存储在 Elasticsearch 中的日志。

991bf3c8908296fe0128a35a4975186c.png

从官方github仓库下载yaml文件

[root@hello ~/efk]# git clone https://github.com/kubernetes/kubernetes.git
[root@hello ~/efk]# kubectl create namespace logging
[root@hello ~/efk]#

执行所有yaml文件

[root@hello ~/efk]# cd kubernetes/cluster/addons/fluentd-elasticsearch/
[root@hello ~/efk/kubernetes/cluster/addons/fluentd-elasticsearch]# kubectl apply -f ./
namespace/logging created
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
configmap/fluentd-es-config-v0.2.1 created
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
deployment.apps/kibana-logging created
service/kibana-logging created

查看pod状态:

[root@hello ~]# kubectl  get pod -n logging
NAME                              READY   STATUS    RESTARTS       AGE
elasticsearch-logging-0           1/1     Running   0              2m17s
elasticsearch-logging-1           1/1     Running   0              96s
fluentd-es-v3.1.1-qw9dj           1/1     Running   1 (97s ago)    2m16s
kibana-logging-75bd6cccf5-pskrr   1/1     Running   1 (106s ago)   2m16s
[root@hello ~]#




[root@hello ~]# kubectl  get service -n logging
NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
elasticsearch-logging   ClusterIP   None            <none>        9200/TCP,9300/TCP   2m41s
kibana-logging          ClusterIP   10.68.145.186   <none>        5601/TCP            2m40s
[root@hello ~]#

访问 kibana

[root@hello ~]# kubectl proxy --address='192.168.1.11' --port=8086 --accept-hosts='^*$'
#访问
http://192.168.1.11:8086//api/v1/namespaces/logging/services/kibana-logging/proxy/

创建一个index-pattern索引

a84dc55899137a8f29fcb3103bc89ab0.png

a91b413610c5ab0a0488a04c56d261a1.png

默认为 logstash-* 即可,之后这里会看到日志

977da2a393f13c2895d719a04ea5b716.png

3f5fa5364fb2fb148e1b6d636e486ea2.png

https://blog.csdn.net/qq_33921750

https://my.oschina.net/u/3981543

https://www.zhihu.com/people/chen-bu-yun-2

https://segmentfault.com/u/hppyvyv6/articles

https://juejin.cn/user/3315782802482007

https://space.bilibili.com/352476552/article

https://cloud.tencent.com/developer/column/93230

知乎、CSDN、开源中国、思否、掘金、哔哩哔哩、腾讯云

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐