본문 바로가기
kubernetes

Kubernetes EFK Helm

by aws-evan 2024. 5. 3.
728x90

 

 

https://velog.io/@raiders032/EFK-%EA%B5%AC%EC%B6%95%ED%95%98%EA%B8%B0

 

 

 

  • Repo 등록
 helm repo add elastic https://helm.elastic.co

 

 

  • Elastic Repo 검색
helm search repo elastic

 

 

 

helm search repo elastic/elasticsearch --versions

 

 

 

helm pull elastic/elasticsearch

 

 

 

 

  • 기존 PVC 설정
    • eanbled : false
    • existingClaim : PVC이름
persistence:
  enabled: false
  existingClaim : work-persistent-storage

 

 

  • ElasticSearch 설치
helm install elasticsearch elastic/elasticsearch -f elastic.yaml  -n efk

 

 

  • Kibana
    • Kibana Service Type 지정
helm install kibana elastic/kibana -f values.yaml -n logging

 

 

 

https://github.com/fluent/helm-charts

 

GitHub - fluent/helm-charts: Helm Charts for Fluentd and Fluent Bit

Helm Charts for Fluentd and Fluent Bit. Contribute to fluent/helm-charts development by creating an account on GitHub.

github.com

 

 

  • Fluentd : Configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: fluentd-config
  namespace: efk-logging
data:
  fluent.conf: |
    <match fluent.**>
        # this tells fluentd to not output its log on stdout
        @type null
    </match>
    # here we read the logs from Docker's containers and parse them
    <source>
      @type tail
      path /var/log/containers/*.log
      pos_file /var/log/app.log.pos
      tag kubernetes.*
      read_from_head true
      <parse>
        @type none
        time_format %Y-%m-%dT%H:%M:%S.%NZ
      </parse>
    </source>
    # we use kubernetes metadata plugin to add metadatas to the log
    <filter kubernetes.**>
        @type kubernetes_metadata
    </filter>
     # we send the logs to Elasticsearch
    <match **>
       @type elasticsearch_dynamic
       @log_level info
       include_tag_key true
       host "#{ENV['FLUENT_ELASTICSEARCH_HOST']}"
       port "#{ENV['FLUENT_ELASTICSEARCH_PORT']}"
       user "#{ENV['FLUENT_ELASTICSEARCH_USER']}"
       password "#{ENV['FLUENT_ELASTICSEARCH_PASSWORD']}"
       scheme "#{ENV['FLUENT_ELASTICSEARCH_SCHEME'] || 'http'}"
       ssl_verify "#{ENV['FLUENT_ELASTICSEARCH_SSL_VERIFY'] || 'false'}"
       reload_connections true
       logstash_format true
       logstash_prefix logstash
       <buffer>
           @type file
           path /var/log/fluentd-buffers/kubernetes.system.buffer
           flush_mode interval
           retry_type exponential_backoff
           flush_thread_count 2
           flush_interval 5s
           retry_forever true
           retry_max_interval 30
           chunk_limit_size 2M
           queue_limit_length 32
           overflow_action block
       </buffer>
    </match>

 

  • Fluentd : Daemonset , SA ,Role
apiVersion: v1
kind: ServiceAccount
metadata:
  name: fluentd
  namespace: efk-logging
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: fluentd
  namespace: efk-logging
rules:
- apiGroups:
  - ""
  resources:
  - pods
  - namespaces
  verbs:
  - get
  - list
  - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: fluentd
roleRef:
  kind: ClusterRole
  name: fluentd
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: fluentd
  namespace: efk-logging
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: efk-logging
  labels:
    k8s-app: fluentd-logging
    version: v1
    kubernetes.io/cluster-service: "true"
spec:
  selector:
    matchLabels:
      k8s-app: fluentd-logging
      version: v1
      kubernetes.io/cluster-service: "true"
  template:
    metadata:
      labels:
        k8s-app: fluentd-logging
        version: v1
        kubernetes.io/cluster-service: "true"
    spec:
      serviceAccount: fluentd # if RBAC is enabled
      serviceAccountName: fluentd # if RBAC is enabled
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: fluentd
        image: fluent/fluentd-kubernetes-daemonset:v1.1-debian-elasticsearch
        env:
        - name:  FLUENT_ELASTICSEARCH_HOST
          value: "elasticsearch-client.efk-logging.svc.cluster.local"
        - name:  FLUENT_ELASTICSEARCH_PORT
          value: "9200"
        - name: FLUENT_ELASTICSEARCH_SCHEME
          value: "http"
        - name: FLUENT_ELASTICSEARCH_USER # even if not used they are necessary
          value: "elastic"
        - name: FLUENT_ELASTICSEARCH_PASSWORD # even if not used they are necessary
          valueFrom:
            secretKeyRef:
              name: elasticsearch-pw-elastic
              key: password
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: fluentd-config
          mountPath: /fluentd/etc # path of fluentd config file
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluentd-config
        configMap:
          name: fluentd-config # name of the config map we will create

 

 

  • ElasticSearch 패스워드 찾기
    • Username : elastic
    • password : secret base64 
kubectl get secret elasticsearch-master-credentials -n lead-gen -o jsonpath='{.data.password}' | base64 --decode; echo

 

 

 

 

728x90

'kubernetes' 카테고리의 다른 글

k3s 설치 가이드  (0) 2024.06.13
Kubernetes NFS Provisioner  (0) 2024.05.02
Kubernetes 모니터링 시스템(Promtail + Loki + Grafana) Helm  (0) 2024.05.01
Kubernetes PostgresSQL 설치  (0) 2024.04.25
Kubernetes LoadBalancer(MetalLB)  (0) 2024.04.23

댓글