You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

microk8s集群Loki本地文件系统存储配置失败求助

问题诊断

  1. 首次配置loki.storage.filesystem的宿主机路径时,helm chart的singleBinary组件默认使用EmptyDir临时存储,不会直接映射宿主机路径,必须通过PVC/PV挂载实现持久化,因此直接指定宿主机路径无效。
  2. 第二次配置的PV未添加节点亲和规则,local类型PV只能被同一节点上的Pod绑定,若Pod调度时未匹配到PV所在节点,就会导致PV始终处于Available状态。

解决方案

1. 修正loki-values.yaml配置

确保Loki的存储路径与PVC挂载到容器内的路径一致,同时让ruler组件也使用该挂载路径:

loki:
  auth_enabled: false
  commonConfig:
    replication_factor: 1
  storage:
    type: filesystem
    filesystem:
      chunks_directory: /var/loki/chunks
      rules_directory: /var/loki/rules
  rulerConfig:
    storage:
      type: local
      local:
        directory: /var/loki/rules
singleBinary:
  replicas: 1
  persistence:
    enabled: true
    storageClass: local-loki
    size: 5Gi
    path: /var/loki

2. 修正PersistentVolume配置

添加节点亲和规则,指定PV归属的microk8s节点(先用kubectl get nodes确认节点名称):

apiVersion: v1
kind: PersistentVolume
metadata:
  name: loki-db
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 10Gi
  hostPath:
    path: /home/djipey/loki
    type: DirectoryOrCreate
  storageClassName: local-loki
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          # 替换为你的microk8s节点名称
          - your-microk8s-node-name

3. 重新部署Loki-stack

先卸载现有部署(替换为你的实际命名空间):

helm uninstall loki-stack -n monitoring

应用修正后的PV:

kubectl apply -f loki-pv.yaml

使用新values文件重新安装:

helm install loki-stack grafana/loki-stack -n monitoring -f loki-values.yaml

4. 验证配置

  • 检查PVC状态:kubectl get pvc -n monitoring,状态应为Bound
  • 检查Pod状态:kubectl get pods -n monitoring,确保Loki Pod正常运行
  • 验证存储写入:进入Loki容器执行ls /var/loki,同时查看宿主机/home/djipey/loki目录,应有chunks、rules子目录及数据文件

内容的提问来源于stack exchange,提问作者JPFrancoia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 20:43:16