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

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

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

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

从官网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 createdservice/elasticsearch-logging createdserviceaccount/elasticsearch-logging createdclusterrole.rbac.authorization.k8s.io/elasticsearch-logging createdclusterrolebinding.rbac.authorization.k8s.io/elasticsearch-logging createdstatefulset.apps/elasticsearch-logging createdconfigmap/fluentd-es-config-v0.2.1 createdserviceaccount/fluentd-es createdclusterrole.rbac.authorization.k8s.io/fluentd-es createdclusterrolebinding.rbac.authorization.k8s.io/fluentd-es createddaemonset.apps/fluentd-es-v3.1.1 createddeployment.apps/kibana-logging createdservice/kibana-logging created

查看pod状态:

[root@hello ~]# kubectl  get pod -n loggingNAME                              READY   STATUS    RESTARTS       AGEelasticsearch-logging-0           1/1     Running   0              2m17selasticsearch-logging-1           1/1     Running   0              96sfluentd-es-v3.1.1-qw9dj           1/1     Running   1 (97s ago)    2m16skibana-logging-75bd6cccf5-pskrr   1/1     Running   1 (106s ago)   2m16s[root@hello ~]#[root@hello ~]# kubectl  get service -n loggingNAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGEelasticsearch-logging   ClusterIP   None            <none>        9200/TCP,9300/TCP   2m41skibana-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索引

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

Linux运维交换社区

Linux运维交换社区,互联网新闻以及技术交换。

73篇原创内容

公众号

https://blog.csdn.net/qq\_33921750

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

https://www.zhihu.com/people/...

https://segmentfault.com/u/hp...

https://juejin.cn/user/331578...

https://space.bilibili.com/35...

https://cloud.tencent.com/dev...

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