helm安裝的也行,並且helm安裝的stable/elasticsearch可用性更高,可是使用資源更多。node
#下載資源文件 wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/es-statefulset.yaml wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/es-service.yaml #替換鏡像和修改配置 docker.elastic.co/elasticsearch/elasticsearch-oss:6.7.0 #其它配置根據本身狀況修改,我這裏修改了name的值,其它的測試就不添加或修改了
[root@k8s-m elk]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE elasticsearch ClusterIP 10.102.165.164 <none> 9200/TCP 108s [root@k8s-m elk]# curl 10.102.165.164:9200/_cluster/health?pretty { "cluster_name" : "docker-cluster", "status" : "green", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 0, "active_shards" : 0, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
#下載logtsash資源清單 helm fetch stable/logstash #修改的配置(我這裏就拿messages和audit日誌作演示,我去掉了pvc的存儲,這裏就不記錄了) #鏡像6.7.0 #elasticsearch配置 elasticsearch: host: elasticsearch.kube-system.svc.cluster.local port: 9200 #輸入輸出等配置 inputs: main: |- input { beats { port => 5044 } } filters: main: |- filter { if "audit_log" in [tags] { mutate { rename => { "[host][name]" => "host" } } } if "messages_log" in [tags] { mutate { rename => { "[host][name]" => "host" } } } } outputs: main: |- output { if "audit_log" in [tags] { elasticsearch { hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"] index => "audit-%{+YYYY.MM.dd}" } } if "messages_log" in [tags] { elasticsearch { hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"] index => "messages-%{+YYYY.MM.dd}" } } }
helm install stable/logstash --name logstash -f values.yaml --namespace kube-system #查看 [root@k8s-m logstash]# kubectl get sts -n kube-system NAME READY AGE elasticsearch 2/2 33m logstash 1/1 19m
#下載清單 helm fetch stable/filebeat #修改鏡像等配置(演示messages和audit日誌) config: filebeat.config: modules: path: ${path.config}/modules.d/*.yml # Reload module configs as they change: reload.enabled: false processors: - add_cloud_metadata: filebeat.inputs: - type: log enabled: true paths: - /var/log/messages close_eof: true tags: messages_log clean_*: true - type: log paths: - /var/log/audit/audit.log close_eof: true tags: audit_log clean_*: true - type: docker containers.ids: - "*" processors: - add_kubernetes_metadata: in_cluster: true - drop_event: when: equals: kubernetes.container.name: "filebeat" output.file: enabled: false output.logstash: hosts: ["logstash.kube-system.svc.cluster.local:5044"] http.enabled: true http.port: 5066
#安裝 helm install stable/filebeat --name filebeat -f values.yaml --namespace kube-system #查看 [root@k8s-m filebeat]# kubectl get ds -n kube-system NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE calico-node 3 3 3 3 3 beta.kubernetes.io/os=linux 45m filebeat 2 2 2 2 2 <none> 21m
#下載清單 helm fetch stable/kibana #修改的配置(我把443改爲了80端口訪問) files: kibana.yml: server.name: kibana server.host: "0" elasticsearch.hosts: http://elasticsearch.kube-system.svc.cluster.local:9200 service: type: ClusterIP externalPort: 80 internalPort: 5601
#安裝 helm install stable/kibana --name kibana -f values.yaml --namespace kube-system #讓kibana能外網訪問 kubectl patch svc kibana -n kube-system -p '{"spec":{"type":"NodePort"}}'
安裝fluentd就不必安裝logtsah和filebeat了,上面的架構能夠說是ELFK,特色是logstash對日誌較強的格式處理,格式化輸出,還有特色就是以前用過或學過,不用再學習了,能夠直接拿來就用。而且logstash保存到Elasticsearch之間還能夠添加個消息隊列。linux
EFK (Elasticsearch + Fluentd + Kibana) 是kubernetes官方推薦的日誌收集方案。git
Fluentd官方安裝的就已經收集了許多日誌了。能夠根據本身的需求添加修改。github
推薦一篇博客:https://blog.laisky.com/p/fluentd/#docker
wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/fluentd-es-configmap.yaml wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/fluentd-es-ds.yaml
[root@k8s-m fluentd]# kubectl get ds -n kube-system fluentd-es-v2.7.0 NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE fluentd-es-v2.7.0 2 2 2 2 2 <none> 101m
EFK的安裝徹底可使用官方的yaml文件安裝,而且官方安裝的方式使用的EFK版本都比較新。瀏覽器