๐Ÿ” AWS OpenSearch๋ฅผ ํ™œ์šฉํ•ด EFK Stack ๊ตฌ์ถ•ํ•˜๊ธฐ

2023๋…„ 4์›” 21์ผ

Overview

overview

๋“ค์–ด๊ฐ€๋ฉฐ

Kubernetes๋Š” ์ƒ์„ฑ๋œ Pod๋“ค์— ๋Œ€ํ•˜์—ฌ Statelessํ•˜๊ฒŒ ๊ด€๋ฆฌ๋˜์–ด์•ผํ•˜๋Š” ๊ฒƒ์ด ๊ธฐ๋ณธ ๊ด€๋ฆฌ ์›์น™์ด๋‹ค.

๊ทธ๋ ‡๊ธฐ์— STDOUT/STDERR๋“ฑ SYSOUT์˜ ํ˜•ํƒœ๋กœ ์Œ“์ด๋Š” ๋กœ๊ทธ๋“ค์„ ๋…ธ๋“œ๋‚ด์— ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด ์•„๋‹Œ ์ค‘์•™ ์ง‘์ค‘์‹ ๋กœ๊น… ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•ด์•ผ ํ•œ๋‹ค.

Pod๋กœ๋ถ€ํ„ฐ ์ˆ˜์‹ ๋œ ๋กœ๊ทธ๋ฅผ Fluent-bit๋ฅผ ํ†ตํ•ด AWS Kinesis๋กœ ์ „์†กํ•˜๊ณ , ์ˆ˜์‹ ๋œ ๋กœ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ AWS OpenSearch์˜ ElasticSearch๊ฐ€ ๋ฐ›๊ฒŒ ๋˜๊ณ  Kibana๋ฅผ ํ†ตํ•ด ์‹œ๊ฐํ™”ํ•˜๊ฒŒ ๋œ๋‹ค.

What Is EFK Stack?

ELF Stack

elk-stack

ELK Stack์€ ElasticSearch + Logstash + Kibana์˜ ๋กœ๊ทธ ๋ถ„์„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ง€์นญํ•œ๋‹ค.

ํ•˜์ง€๋งŒ ์ด ์ค‘ Logstash๋ณด๋‹ค fluent-bit์ด ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํ™˜๊ฒฝ์—์„œ ์ตœ์ ํ™” ๋˜์–ด์žˆ๋Š” ์‹œ์Šคํ…œ ๊ตฌ์ถ• ์‹œ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— Fluent-bit๋ฅผ ์„ ํƒํ•˜์˜€๋‹ค.

EFK Stack

efk-stack

  • Fluent-bit : ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•ด์„œ Elasticsearch๋กœ ์ „๋‹ฌ
  • Elasticsearch : Fluentd๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ ๋ฐ ๋ถ„์„ํ•˜์—ฌ ์ €์žฅ
  • Kibana : Elasticsearch์˜ ๋น ๋ฅธ ๊ฒ€์ƒ‰๋Šฅ๋ ฅ์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

์‚ฌ๋‚ด EFK Stack

ower-stack

k8s๋‚ด ํŒŒ๋“œ๋“ค์˜ ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” fluent-bit๊ฐ€ ๋…ธ๋“œ๋ณ„๋กœ DaemonSet์— ์กด์žฌํ•˜๊ณ  fluent-bit์—์„œ AWS Kinesis Datafirehose๋ฅผ ํ†ตํ•ด AWS OpenSearch์˜ ElasticSearch๋กœ ์ „์†กํ•˜๋ฉฐ Kibana๋ฅผ ํ†ตํ•ด ์‹œ๊ฐํ™” ํ•˜๊ฒŒ ๊ตฌ์„ฑํ•˜์˜€๋‹ค.

Set a EFK Stack

Install Fluent-bit

## create k8s namespace
kubectl create ns logging

๋จผ์ € loggging ์ „์šฉ namespace๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

## helm repo add
helm repo add fluent https://fluent.github.io/helm-charts

๊ทธ ํ›„ helm์„ ํ†ตํ•ด fluent chart๋ฅผ ๋‹ค์šด๋กœ๋“œํ•œ๋‹ค.

## helm install
helm upgrade --install fluent-bit fluent/fluent-bit -n logging

k8s cluster์— ํ•ด๋‹น helm repo๋ฅผ logging namespace์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

Result

namespace

Set AWS Kinesis Data Firehose

AWS Kinesis Data Firehose๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์ „ AWS Opensearch Domain๊ณผ ๋ฐฑ์—…์šฉ AWS S3 Buckect์„ ์ƒ์„ฑํ•ด์•ผ ํ•œ๋‹ค.

aws-kinesis

์™ผ์ชฝ ์ƒ๋‹จ์— ์ „์†ก์ŠคํŠธ๋ฆผ ์ƒ์„ฑ์„ ํด๋ฆญํ•œ๋‹ค.

kinesis-1

์†Œ์Šค ๋ฐ ๋Œ€์ƒ์„ ์„ ํƒํ•œ๋‹ค.

  • ์†Œ์Šค : Direct PUT
  • ๋Œ€์ƒ : Amazon OpenSearch Service

kinesis-2

๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘” AWS OpenSearch Domain์„ ์„ค์ •ํ•˜๊ณ  ํŠนํžˆ, index ์ด๋ฆ„์„ ์„ค์ •ํ•œ๋‹ค. ํ•ด๋‹น index ์ด๋ฆ„๊ณผ ๊ฐ™์€ fluent-bit๋กœ ๋ถ€ํ„ฐ ์ˆ˜์ง‘๋œ pod๋“ค์˜ ๋กœ๊ทธ๊ฐ€ ์ˆ˜์ง‘๋œ๋‹ค.

kinesis-3

๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘” ๋ฐฑ์—…์šฉ AWS S3 Bucket์„ ์„ค์ •ํ•œ๋‹ค. ํ•ด๋‹น AWS S3 Bucket์—๋Š” ์„ค์ •ํ•ด๋†“์€ ๋ฒ„ํผ์™€ ํŒŒ์ผ ํ˜•ํƒœ๋กœ log๋“ค์ด ์ˆ˜์ง‘๋œ๋‹ค.

Set Fluent-bit Configmap

apiVersion: v1
data:
  fluent-bit.conf: |
    [SERVICE]
        Parsers_File      parsers.conf
        HTTP_Server       On
        HTTP_Listen       0.0.0.0
        HTTP_Port         2020

    [INPUT]
        Name              tail
        Path              /var/log/containers/front-end-app-*.log
        DB                /var/log/flb_kube.db
        Mem_Buf_Limit     10MB
        Refresh_Interval  10
        Tag               front-end
        Parser            docker
    [FILTER]
        Name              record_modifier
        Match             front-end
        Whitelist_key     log
    [OUTPUT]
        Name              kinesis_firehose
        Match             front-end
        region            ap-northeast-2
        delivery_stream   kinesis-app
...

kind: ConfigMap
metadata:
  creationTimestamp: "2022-05-30T05:43:33Z"
  labels:
    k8s-app: fluent-bit
  name: fluent-bit
  namespace: logging

์œ„์˜ ๋‚ด์šฉ์ค‘ [INPUT] , [FILTER], [OUTPUT] ์— ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•œ๋‹ค.

  • INPUT : ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•  app log path๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.
  • FILTER : ํ•ด๋‹น INPUT ์˜ Type์„ ์ž‘์„ฑํ•œ๋‹ค.
  • OUTPUT : ์ˆ˜์ง‘๋œ ๋กœ๊ทธ๋“ค์„ ์–ด๋Š ๊ณณ์œผ๋กœ ์ „์†กํ• ์ง€ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. (์—ฌ๊ธฐ์„œ๋Š” AWS Kinesis delivery_stram์„ ์ž‘์„ฑํ•œ๋‹ค.)

Result

check-result

์ด์ œ AWS Kinesis๋กœ ์ ‘์†ํ•˜์—ฌ ํ•ด๋‹น DataFirehose์—์„œ ๋ชจ๋‹ˆํ„ฐ๋ง ํƒญ์—์„œ ํ™•์ธํ•ด๋ณด๋ฉด ์œ„์˜ ์‚ฌ์ง„ ์ฒ˜๋Ÿผ ์„ฑ๊ณต ๊ทธ๋ž˜ํ”„๊ฐ€ ์ฐํžˆ๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Finish

finish

์œ„์˜ ๊ณผ์ •์„ ๋ชจ๋‘ ๋งˆ์ณค์œผ๋ฉด AWS OpenSearch Domain์œผ๋กœ ์ ‘์†ํ•˜์—ฌ kibana๋ฅผ ๋ณด์ž.

Index patterns ์„ค์ •์„ ๋จผ์ € ํ•˜๊ณ  kibana์˜ Discover ๋ฉ”๋‰ด์— ์ ‘์†ํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ๋กœ๊ทธ๊ฐ€ ์Œ“์ด๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Reference