kubernetes 为Loki配置本地文件系统存储

dxxyhpgq  于 2023-05-22  发布在  Kubernetes
关注(0)|答案(1)|浏览(491)

我在我的microk 8 s集群上成功运行了Grafana和Prometheus。我现在正试图陷害洛基。它基本上工作正常,但是我仍然无法配置本地文件系统。我在用洛基-斯塔克导航图来部署。
我是这么做的:

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm upgrade --install loki grafana/loki-stack -f loki-values.yaml

以下是loki-values.yaml的内容:

loki:
  commonConfig:
    replication_factor: 1
  storage:
    type: filesystem
    filesystem:
      chunks_directory: /home/djipey/loki/chunks
      rules_directory: /home/djipey/loki/rules
  rulerConfig:
    storage:
      type: local
singleBinary:
  replicas: 1

目录/home/djipey/loki存在于机器上,我修改了777,所以我不希望有任何权限问题。
上面的设置可以工作,我可以在Grafana中创建一个Loki数据源,它包含我期望的数据。但是,loki文件夹保持为空。loki pod上的描述提示存储配置被忽略:

Volumes:
  tmp:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:     
    SizeLimit:  <unset>
  config:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  loki
    Optional:    false
  storage:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:     
    SizeLimit:  <unset>
  kube-api-access-w5tz2:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true

你知道怎么配置吗?
编辑:
@Petter我尝试了你的建议。singleBinary.persistence的可能配置选项包括:

persistence:
    # -- Enable StatefulSetAutoDeletePVC feature
    enableStatefulSetAutoDeletePVC: true
    # -- Enable persistent disk
    enabled: true
    # -- Size of persistent disk
    size: 10Gi
    # -- Storage class to be used.
    # If defined, storageClassName: <storageClass>.
    # If set to "-", storageClassName: "", which disables dynamic provisioning.
    # If empty or set to null, no storageClassName spec is
    # set, choosing the default provisioner (gp2 on AWS, standard on GKE, AWS, and OpenStack).
    storageClass: null
    # -- Selector for persistent disk
    selector: null

所以我试着:

loki:
  auth_enabled: false
  commonConfig:
    replication_factor: 1
  storage:
    type: filesystem
  rulerConfig:
    storage:
      type: local
singleBinary:
  replicas: 1
  persistence:
    storageClass: local-loki
    enabled: true
    size: 5Gi

关于PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: loki-db
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 10Gi
  hostPath:
    path: /home/djipey/loki
    type: DirectoryOrCreate
  storageClassName: local-loki

但它不起作用,它从来没有声称:

NAME            CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                                                                                     STORAGECLASS    REASON   AGE
prometheus-db   10Gi       RWO            Retain           Bound       monitoring/prometheus-kube-prometheus-stack-prometheus-db-prometheus-kube-prometheus-stack-prometheus-0   local                    37h
grafana-db      10Gi       RWO            Retain           Bound       monitoring/kube-prometheus-stack-grafana                                                                  local-grafana            37h
loki-db         10Gi       RWO            Retain           Available                                                                                                             local-loki               18m

我在这里有点卡住了,日志或事件中没有任何东西表明loki正在尝试使用这个存储。

e3bfsja2

e3bfsja21#

正确配置Loki持久性是一个相当复杂的过程。首先,您必须了解Pods文件系统与主机上的任何文件系统之间的区别。pod中不存在/home/djipey/loki。SingleBinary模式下的Loki helm chart尝试创建一个名为“storage”的持久卷,并将其挂载到/var/loki,因此chunk和rules文件夹位于/var/loki下。如何排序以及什么排序取决于您的Kubernetes设置。在您的情况下,它似乎是emptyDir,即磁盘存储但短暂。您可以在配置中设置singleBinary.persistence.storageClass值,以选择主机路径存储类,如microk8s-hostpath,或使用singleBinary.persistence.selector选择预配置的卷。我不熟悉microk8s存储配置的细节,所以你可能需要进一步挖掘。

相关问题