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

GKE实例中无法查看已挂载Persistent Volume的问题求助

Let's break down what's going wrong here and fix it step by step. I see a few key issues in your StatefulSet configuration that are preventing your GCE disk from showing up when you run df -hT.

First: Your StatefulSet is using an emptyDir instead of your persistent volume

Looking at your StatefulSet YAML, you've defined a volumes section with emptyDir: {} for my-volume. This creates a temporary, ephemeral directory that gets deleted when the pod restarts—this has nothing to do with your GCE disk or the PV/PVC you created. Worse, your volumeMounts are pointing to this emptyDir volume, so your persistent disk isn't being mounted at all.

Second: Your manual PV isn't being used by your PVC (or StatefulSet)

When you created your PVC my-claim, it automatically bound to a dynamically provisioned PV (the ones starting with pvc-...) instead of your manual my-volume PV. That's because your manual PV doesn't specify a storageClassName matching the default one your cluster uses (likely standard), so the PVC opted for dynamic provisioning.

Plus, your StatefulSet is using volumeClaimTemplates which creates separate PVCs for each replica (like my-claim-xxx_0), but your volume mounts aren't referencing these correctly.


Fix Option 1: Use your manually created PV/PVC with the StatefulSet

If you want to stick with the GCE disk you created manually, follow these steps:

  1. Update your manual PV to match the default storage class
    Edit your PV to add a storageClassName so it can bind to your PVC:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: my-volume
    spec:
      capacity:
        storage: 200Gi
      accessModes:
        - ReadWriteOnce
      storageClassName: standard # Match your cluster's default storage class
      gcePersistentDisk:
        pdName: my-disk
        fsType: ext4
    

    Apply the update: kubectl apply -f your-pv.yaml

  2. Delete and re-create your PVC to bind to the manual PV
    First delete the existing PVC that's bound to the dynamic PV:

    kubectl delete pvc my-claim
    

    Re-create your PVC, and it should now bind to my-volume instead of creating a new PV.

  3. Fix your StatefulSet configuration
    Remove the emptyDir volume and volumeClaimTemplates, then reference your existing PVC directly:

    apiVersion: apps/v1beta2
    kind: StatefulSet
    metadata:
      name: your-statefulset-name # Fill in your actual name
    spec:
      serviceName: your-service-name # Required for StatefulSets
      replicas: 3 # Adjust to your desired number of replicas
      template:
        metadata:
          labels:
            app: your-app-label
        spec:
          containers:
            - name: your-container-name # Fill in your actual container name
              image: your-container-image # Fill in your actual image
              volumeMounts:
                - name: my-volume
                  mountPath: /mnt/disks
          volumes:
            - name: my-volume
              persistentVolumeClaim:
                claimName: my-claim # Reference your existing PVC
    

    Apply the updated StatefulSet: kubectl apply -f statefulset.yaml


StatefulSets are designed to create unique PVCs for each replica automatically via volumeClaimTemplates. If you don't need the specific manual disk you created, this is the simpler approach:

  1. Delete your manual PV and existing PVCs

    kubectl delete pv my-volume
    kubectl delete pvc my-claim my-claim-xxx_0 my-claim-xxx_1 # Delete all related PVCs
    
  2. Fix your StatefulSet configuration
    Remove the emptyDir volume, and ensure your volumeMounts reference the name in volumeClaimTemplates:

    apiVersion: apps/v1beta2
    kind: StatefulSet
    metadata:
      name: your-statefulset-name
    spec:
      serviceName: your-service-name
      replicas: 3
      template:
        metadata:
          labels:
            app: your-app-label
        spec:
          containers:
            - name: your-container-name
              image: your-container-image
              volumeMounts:
                - name: my-claim # Matches the name in volumeClaimTemplates
                  mountPath: /mnt/disks
      volumeClaimTemplates:
        - metadata:
            name: my-claim
          spec:
            accessModes: [ "ReadWriteOnce" ]
            resources:
              requests:
                storage: 200Gi
            storageClassName: standard # Use your cluster's default storage class
    

    Apply the updated StatefulSet: kubectl apply -f statefulset.yaml


Verify the fix

After applying the corrected StatefulSet, wait for the pods to restart. Then SSH into an instance and run df -hT—you should see your /mnt/disks mount listed with the ext4 filesystem type, pointing to your GCE disk.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 03:48:52