open /prometheus/queries.active: permission denied(已解决)

部署prom时,prom的
kubectl -n monitoring get pod
pod的状态为error
在这里插入图片描述
出现error一般是容器里面有报错,所以需要查看日志
#查看pod的log日志

kubectl logs prometheus-deployment-6495dcc86c-jtkxw

在这里插入图片描述
可知,没有创建这个目录的权限,
解决办法,使用initcontainer为目录赋予权限

我的配置:

    spec:
      initContainers:
          - name: "init-datapath"
            image: debian:stable
            command: ["chown", "-R", "65534:65534", "/prometheus"]
            command: ["/bin/chmod","-R","777","/prometheus"]
            volumeMounts:
            - name: prometheus-storage-volume
              mountPath: /prometheus
              subPath: ""
      containers:
        - name: prometheus
          image: prom/prometheus
          args:
            - "--storage.tsdb.retention.time=12h"
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus/"
          ports:
            - containerPort: 9090
          resources:
            requests:
              cpu: 500m
              memory: 500M
            limits:
              cpu: 1
              memory: 1Gi
          volumeMounts:
            - name: prometheus-config-volume
              mountPath: /etc/prometheus/
            - name: prometheus-storage-volume
              mountPath: /prometheus/
      volumes:
        - name: prometheus-config-volume
          configMap:
            defaultMode: 420
            name: prometheus-server-conf
  
        - name: prometheus-storage-volume
          persistentVolumeClaim:
            claimName: pvc-nfs-data

最后查看状态,
在这里插入图片描述
解决!

猜你喜欢

转载自blog.csdn.net/zb199738/article/details/126070849