Fluentd설치(k8s 1.30이상에서 Elasticsearch 8.x 연동)
아래 가이드는 제대로 설치 안되어 보다 경량화된 Fluentd인 Fluentbit를 설치할 것을 권고합니다. https://happycloud-lee.tistory.com/296 |
이 가이드는 k8s 1.30이상에 Elasticsearch 8.x를 설치한 경우 Fluentd를 설치하는 방법을 안내합니다.
Elasticsearch 8.x 설치 가이드는 아래 글을 참조하세요.
https://happycloud-lee.tistory.com/294
k8s 1.30이상에서 Elasticsearch 8.x 설치
k8s 1.30으로 업그레이드 되면서 elastic에서 제공하는 helm chart도 많은 변화가 있습니다.이 가이드에서는 최신 버전의 elastic helm chart를 k8s 1.30 클러스터에 설치하는 방법을 다룹니다. 엘라스틱 서치
happycloud-lee.tistory.com
엘라스틱 서치 헬름 저장소 추가
아래와 같이 엘라스틱 서치 헬름 차트 저장소를 추가 하고 차트 리스트를 업데이트 합니다.
[root@osboxes ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
[root@osboxes ~]# helm repo update
Fluentd의 헬름 차트명과 버전을 찾습니다.
ubuntu@bastion:~/install/efk$ helm search repo fluentd
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/fluentd 6.5.13 1.17.1 Fluentd collects events from various data sourc...
설치 Config파일 작성
작업 디렉토리를 만들고 이동 합니다.
[root@osboxes ~]# mkdir -p ~/install/efk && cd ~/install/efk
설치를 위한 환경설정 파일을 만듭니다. fluentd.yaml이라는 이름을 만들었다고 가정하고 설명하겠습니다.
Forwarder는 각 노드에 Daemon으로 설치되어 로그를 수집하여 Aggregator로 보냅니다.
Aggregator는 수집된 로그를 연결된 Elasticsearch로 보냅니다.
## Forwarder parameters
forwarder:
enabled: true
configMapFiles:
fluentd.conf: |
# Ignore fluentd own events
<match fluent.**>
@type null
</match>
@include fluentd-inputs.conf
@include fluentd-output.conf
fluentd-inputs.conf: |
# HTTP input for the liveness and readiness probes
<source>
@type http
port 9880
</source>
# Get the logs from the containers running in the node
<source>
@type tail
path /var/log/containers/*.log
# exclude Fluentd logs
exclude_path /var/log/containers/*fluentd*.log
pos_file /opt/bitnami/fluentd/logs/buffers/fluentd-docker.pos
tag kubernetes.*
read_from_head true
<parse>
@type json
time_key time
time_format %Y-%m-%dT%H:%M:%S.%NZ
</parse>
</source>
# enrich with kubernetes metadata
<filter kubernetes.**>
@type kubernetes_metadata
</filter>
fluentd-output.conf: |
# Forward all logs to the aggregators
<match **>
@type forward
<server>
host fluentd-aggregator
port 24224
</server>
</match>
## Aggregator parameters
aggregator:
enabled: true
replicaCount: 1
configMapFiles:
fluentd.conf: |
# Ignore fluentd own events
<match fluent.**>
@type null
</match>
@include fluentd-inputs.conf
@include fluentd-output.conf
fluentd-inputs.conf: |
# HTTP input for the liveness and readiness probes
<source>
@type http
port 9880
</source>
# Receive logs from forwarders
<source>
@type forward
port 24224
</source>
fluentd-output.conf: |
# Send the logs to Elasticsearch
<match **>
@type elasticsearch
host "elasticsearch-master-hl.efk.svc.cluster.local"
port 9200
user "elastic"
password "P@ssw0rd$"
scheme https
ssl_verify true
ssl_version TLSv1_2
ca_file /opt/bitnami/fluentd/certs/elasticsearch/ca.crt
client_cert /opt/bitnami/fluentd/certs/elasticsearch/tls.crt
client_key /opt/bitnami/fluentd/certs/elasticsearch/tls.key
index_name fluentd
type_name fluentd
logstash_format true
logstash_prefix fluentd
reconnect_on_error true
reload_on_failure true
<buffer>
flush_thread_count 8
flush_interval 5s
chunk_limit_size 2M
queue_limit_length 32
retry_max_interval 30
retry_forever true
</buffer>
</match>
# SSL인증서 mount
extraVolumes:
- name: elasticsearch-certs
secret:
secretName: elasticsearch-master-crt
extraVolumeMounts:
- name: elasticsearch-certs
mountPath: /opt/bitnami/fluentd/certs/elasticsearch
readOnly: true
# Disable TLS
tls:
enabled: false
# Disable metrics for simplicity
metrics:
enabled: false
이 설정에서 중요한 부분은 Elasticsearch 연결 정보를 셋팅하는 아래 부분입니다.
- host: Elasticsearch의 service객체 주소로서, SSL통신을 하므로 인증서의 SAN(Subject Alternative Name)과 반드시 일치해야 함
- scheme: 반드시 SSL통신을 해야 함
- password: elastic 서버 인증 암호. Secret 'elasticsearch-master-credentials'에서 구함
- ca_file: SSL인증서를 서명한 CA(Certificate Authority)의 인증서 경로
- client_cert: SSL 인증서 경로
- client_key: SSL 인증서의 개인 키 경로
CA, Cert, Key는 Secret 'elasticsearch-master-crt'에서 마운트 함
aggregator:
...
fluentd-output.conf: |
# Send the logs to Elasticsearch
<match **>
@type elasticsearch
host "elasticsearch-master-hl.efk.svc.cluster.local"
port 9200
user "elastic"
password "P@ssw0rd$"
scheme https
ssl_verify true
ssl_version TLSv1_2
ca_file /opt/bitnami/fluentd/certs/elasticsearch/ca.crt
client_cert /opt/bitnami/fluentd/certs/elasticsearch/tls.crt
client_key /opt/bitnami/fluentd/certs/elasticsearch/tls.key
아래는 인증서들을 Secret 'elasticsearch-master-crt'에서 마운트 하기 위한 설정입니다.
aggregator:
...
# SSL인증서 mount
extraVolumes:
- name: elasticsearch-certs
secret:
secretName: elasticsearch-master-crt
extraVolumeMounts:
- name: elasticsearch-certs
mountPath: /opt/bitnami/fluentd/certs/elasticsearch
readOnly: true
아래는 SSL인증서(tls.crt)의 SAN값을 확인하는 방법입니다.
kubectl get secret elasticsearch-master-crt -o jsonpath="{.data['tls\.crt']}" | base64 --decode > elastic-tls.crt
openssl x509 -in elastic-tls.crt -text -noout
아래와 같이 SAN을 확인할 수 있습니다.
...
X509v3 Subject Alternative Name:
DNS:*.elasticsearch-master-hl.efk.svc.cluster.local, DNS:elasticsearch-master-hl.efk.svc.cluster.local, DNS:elasticsearch-master, DNS:127.0.0.1, DNS:localhost
...
설치하기
namespace를 만들고 이동합니다.
k create ns efk
kubens efk
helm 명령으로 설치합니다.
helm upgrade fluentd -i -f fluentd.yaml bitnami/fluentd
Pod가 실행될때까지 기다립니다. 아래와 같이 모든 Pod가 실행되어야 합니다.
fluentd-0, fluentd-1이 Aggregator이고, fluentd-xxx 파드들이 Forwarder입니다.
Forwarder파드는 DaemonSet으로 설치되므로 각 노드 당 1개씩 생성됩니다.
$ k get po
NAME READY STATUS RESTARTS AGE
elasticsearch-master-0 1/1 Running 0 158m
fluentd-0 1/1 Running 0 58m
fluentd-1 1/1 Running 0 57m
fluentd-j8xkr 1/1 Running 1 (57m ago) 58m
fluentd-jv4qq 1/1 Running 1 (58m ago) 58m
fluentd-klh8p 1/1 Running 2 (55m ago) 58m
fluentd-pnj8b 1/1 Running 4 (56m ago) 58m
fluentd-pnk4b 1/1 Running 1 (58m ago) 58m