1

I'm currently trying to create a Persistent Volume Claim but is throwing the error: "Cannot bind to requested volume "pv": storageClassName does not match"

resource "google_compute_disk" "default" {
  name = "pv"
  type = "pd-ssd"
  zone = "us-east1-a"
  size = 2
}

resource "kubernetes_persistent_volume" "default" {
  metadata {
   name = "pv"
  }
  spec {
    capacity = {
     storage = "2Gi"
   }
 access_modes = ["ReadWriteMany"]
 persistent_volume_source {
  gce_persistent_disk {
    pd_name = "pv"
    fs_type = "ext4"
    }
  }
 }
}

resource "kubernetes_persistent_volume_claim" "default" {
 metadata {
  name = "pv"
 }
 spec {
  access_modes = ["ReadWriteMany"]
  resources {
    requests = {
      storage = "2Gi"
    }
  }
  storage_class_name = "pv"
  volume_name        = "pv"
  }
 }

I've tried to follow Why does a match Persistent Volume not bind to a match Persistent Volume Claim (using k3s)?, however I still get the same issue of "Cannot bind to requested volume "pv": storageClassName does not match"

How can I fix this issue? - I've tried to ensure that the name of all the resources match, but I think I'm missing something.

Any help on this will be greatly appreciated!

fuzzi
  • 1,967
  • 9
  • 46
  • 90
  • What is the syntax you're using here? In any case, in your PVC you're setting `storage_class_name = "pv"`. What is the storage class name of the PV itself? (E.g., if you `kubectl get pv pv -o yaml`; you're looking for the `storageClassName` attribute). – larsks Feb 07 '22 at 21:26
  • Hi - I ran the command, and it does not have a `storageClassName` attribute. There is a `name` under `metadata` and that is `pv` – fuzzi Feb 07 '22 at 21:40
  • What happens if you remove the `storage_class_name` setting from your PVC? – larsks Feb 07 '22 at 21:45
  • 1
    So I updated the kubernetes_persistent_volume to also have `storage_class_name = "pv"`. This seems to set the persistent volume to Bound and get past the error. However, the pod never starts up due to `6 persistentvolumeclaim "pv" not found` so I'm not sure if this is the correct solution. – fuzzi Feb 07 '22 at 22:27
  • Well, it's the opposite of what I suggested (and to be fair, I don't know if my suggestion will work, either), but perhaps it's worth a try. – larsks Feb 07 '22 at 22:37
  • Thanks @larsks I removed `storage_class_name ` from PVC and I get the error: `storageClassName does not match` same as in the original question. – fuzzi Feb 08 '22 at 14:19
  • Hi fuzzi, can you provide what k8s version and cluster platform/infrastructure are you using? – Piotr Malec Feb 08 '22 at 17:58
  • @PiotrMalec GKE, version 1.21.6-gke.1500 – fuzzi Feb 08 '22 at 20:26

1 Answers1

0

You might change

storage_class_name = "pv" 

to

storage_class_name = "manual"
xiaojueguan
  • 870
  • 10
  • 19