EFK是 Elasticsearch,Fluentbit,Kibana的缩写,是k8s集群常用的日志解决方案。
将EFK部署到k8s集群上也比较简单,安装步骤如下:
前期准备
为EFK创建namespace “logging”。
kubectl create namespace logging
安装Helm(Helm是kubernetes的包管理平台,目前的版本是3.0+,安装办法参考官网)
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
安装Elasticsearch
由于是为了测试目的,安装单节点, 这里安装的es版本是6.7.0
kubectl run elasticsearch --image=docker.elastic.co/elasticsearch/elasticsearch:6.7.0 --namespace=logging
kubectl expose deploy elasticsearch --port 9200
将集群上运行ES的节点执行下边的命令:
sysctl -w vm.max_map_count=262144
通过下边命令查看设置是否成功:
sysctl -a|grep vm.max_map_count
安装kibana(通过helm)
helm install kibana stable/kibana --set env.ELASTICSEARCH_URL=http://elasticsearch:9200 --namespace logging
安装flunetbit (参考Github)
Apply account,并绑定role:
kubectl apply -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-service-account.yaml
kubectl apply -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-role.yaml
kubectl apply -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-role-binding.yaml
安装fluentbit ,output到es。
kubectl apply -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-configmap.yaml
kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-ds.yaml
最后查看EFK运行状况如何
[root@k8s-master ~]# kubectl -n logging get pods
NAME READY STATUS RESTARTS AGE
elasticsearch-5bf5995c77-2fb9n 1/1 Running 1 11d
fluent-bit-5b8z4 1/1 Running 0 8d
fluent-bit-6bdnl 1/1 Running 0 8d
fluent-bit-6j7z7 1/1 Running 1 8d
fluent-bit-bddcx 1/1 Running 0 8d
kibana-5fbfdbc4db-8qfq2 1/1 Running 0 11d
[root@k8s-master ~]# kubectl -n logging get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch ClusterIP 10.96.83.179 <none> 9200/TCP 11d
kibana NodePort 10.111.19.55 <none> 443:31588/TCP 11d
注:默认情况下,kibana service 是不能对外访问的,类型ClusterIP需要改成NodePort,才能被对外提供访问。