WaitForFirstConsumer PersistentVolumeClaim 在绑定之前等待创建第一个消费者。自动配置不起作用

WaitForFirstConsumer PersistentVolumeClaim waiting for first consumer to be created before binding. Auto provisioning does not work

您好,我知道这可能是重复的,但我无法从中得到答案

我有一个 prometheus 部署,想给它一个持久卷。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-deployment
  namespace: monitoring
  labels:
    app: prometheus-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-server
  template:
    metadata:
      labels:
        app: prometheus-server
    spec:
      containers:
        - name: prometheus
          image: prom/prometheus
          args:
            - "--storage.tsdb.retention.time=60d"
            - "--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: prometheus-pv-claim

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-pv-claim
spec:
  storageClassName: default
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi

现在 pvc 和 deployment 都无法安排,因为 pvc 等待部署,反之亦然。就我而言,我们有一个自动配置的集群,因此我不能只创建一个 pv。我该如何解决这个问题,因为其他部署确实使用相同样式的pvc并且可以正常工作。

这是因为命名空间。 PVC 是命名空间对象 。您的 PVC 位于默认名称空间中。将其移至监控命名空间应该可以。

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-pv-claim
  namespace: monitoring
spec:
  storageClassName: default
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi

您的 PVC 部署时是否部署了正确的命名空间?
并确保 StorageClass 具有 volumeBindingMode: WaitForFirstConsumer

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
...
volumeBindingMode: WaitForFirstConsumer