简体   繁体   English

如果 Loki pod 在 EKS Fargate 中意外终止,EFS 是否是一个好的日志备份选项

[英]Is EFS a good logs backup option if Loki pod terminated accidentally in EKS Fargate

I am currently using Loki to store logs generated by my applications from EKS Fargate.我目前正在使用 Loki 来存储我的应用程序从 EKS Fargate 生成的日志。 Sidecar pattern with promtail is used to scrape logs.带有 promtail 的 Sidecar 模式用于抓取日志。 Single Loki pod is used and S3 is configured as a destination to store logs.使用单个 Loki pod,并将 S3 配置为存储日志的目的地。 It works nicely as expected.它按预期工作得很好。 However, when I tested the availability of the logging system by deleting pods, I discovered that if Loki's pod was deleted, some logs would be missing (range around 20 mins before the pod was deleted to the time the pod was deleted) even after the pod restarted.然而,当我通过删除 pod 来测试日志系统的可用性时,我发现如果删除 Loki 的 pod,即使在删除 pod 之后,也会丢失一些日志(范围从删除 pod 前 20 分钟到删除 pod 时)豆荚重新启动。

To solve this problem, I tried to use EFS as the persistent volume of Loki' pod, mounting the path /loki.为了解决这个问题,我尝试使用EFS作为Loki'pod的持久卷,挂载路径为/loki。 The whole process is followed by this article ( https://aws.amazon.com/blogs/aws/new-aws-fargate-for-amazon-eks-now-supports-amazon-efs/ ).整个过程遵循本文 ( https://aws.amazon.com/blogs/aws/new-aws-fargate-for-amazon-eks-now-supports-amazon-efs/ )。 But I have got an error from the Loki pod with msg "error running loki" err="mkdir /loki/compactor: permission denied”但是我从 Loki pod 收到错误信息“运行 loki 时出错”err="mkdir /loki/compactor: permission denied"

Therefore, I have 2 questions in my mind:因此,我有两个问题:

Should I use EFS as a solution for log backup in my case?在我的案例中,我应该使用 EFS 作为日志备份的解决方案吗? Why did I get a permission denied inside the pod, any ways to solve this problem?为什么我在 pod 中得到了拒绝的权限,有什么方法可以解决这个问题?

My Loki-config.yaml我的 Loki-config.yaml

auth_enabled: false

server:
  http_listen_port: 3100
  # grpc_listen_port: 9096

ingester:
  wal:
    enabled: true
    dir: /loki/wal
  lifecycler:
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    # final_sleep: 0s
  chunk_idle_period: 3m       
  chunk_retain_period: 30s    
  max_transfer_retries: 0     
  chunk_target_size: 1048576 

schema_config:
  configs:
    - from: 2020-05-15
      store: boltdb-shipper
      object_store: aws
      schema: v11
      index:
        prefix: index_
        period: 24h

storage_config:
  boltdb_shipper:
    active_index_directory: /loki/index
    cache_location: /loki/index_cache
    shared_store: s3

  aws:
    bucketnames: bucketnames
    endpoint: s3.us-west-2.amazonaws.com
    region: us-west-2
    access_key_id: access_key_id
    secret_access_key:  secret_access_key
    sse_encryption: true

compactor:
  working_directory: /loki/compactor
  shared_store: s3
  compaction_interval: 5m

limits_config:
  reject_old_samples: true
  reject_old_samples_max_age: 48h

chunk_store_config:
  max_look_back_period: 0s

table_manager:
  retention_deletes_enabled: true
  retention_period: 96h

querier:
  query_ingesters_within: 0

analytics:
  reporting_enabled: false

Deploy.yaml部署.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: fargate-api-dev
  name: dev-loki
spec:
  selector:
    matchLabels:
      app: dev-loki
  template:
    metadata:
      labels:
        app: dev-loki
    spec:
      volumes:
        - name: loki-config
          configMap:
            name: dev-loki-config
        - name: dev-loki-efs-pv
          persistentVolumeClaim:
            claimName: dev-loki-efs-pvc


      containers:
        - name: loki
          image: loki:2.6.1
          args:
            - -print-config-stderr=true
            - -config.file=/tmp/loki.yaml
         
          resources:
            limits:
              memory: "500Mi"
              cpu: "200m"
          ports:
            - containerPort: 3100
          volumeMounts:
            - name: dev-loki-config
              mountPath: /tmp
              readOnly: false
             - name: dev-loki-efs-pv
               mountPath: /loki

Promtail-config.yaml Promtail-config.yaml

server:
  log_level: info
  http_listen_port: 9080

clients:
  - url: http://loki.com/loki/api/v1/push

positions:
  filename: /run/promtail/positions.yaml

scrape_configs:
  - job_name: api-log
    static_configs:
    - targets:
      - localhost
      labels:
        job: apilogs
        pod: ${POD_NAME}
        __path__: /var/log/*.log  

I had a similar issue using EFS as volume to store the logs and I found this solution https://github.com/grafana/loki/issues/2018#issuecomment-1030221498我在使用 EFS 作为卷来存储日志时遇到了类似的问题,我找到了这个解决方案https://github.com/grafana/loki/issues/2018#issuecomment-1030221498

Basically loki container by it's own is not able to create a directory to start working, so we used a initcotainer to do it for it.基本上 loki 容器本身无法创建一个目录来开始工作,所以我们使用了一个 initcotainer 来为它做这件事。

This solution worked like a charm for.这个解决方案就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM