PVC and PV usage - Confusion

Hi,

I am getting confused on how PVC claims a PV. Based on the lectures on CKAD i understood that once we create a PVC, it looks for a PV created and if that is a best fit, the PVC will be created else it will be in a pending state.

I tried replicating this in my system where i used minikube to setup my cluster.

Each time i am creating a PVC it is internally creating a PV and attaching itself to it. Even if i am creating a PV before a PVC, it is doing the same thing.

For e.g.,
Scenario 1:
In my PV i gave a capacity: 500Mi and in PVC i gave as request: 10000000Mi
I was expecting the PVC to be in pending state after creation. But it is internally creating one PV.

Scenario 2:
In my PV i gave a capacity: 500Mi and in PVC i gave as request: 500Mi
Same happens here where PVC creates its own PV and not using the PV i created

Scenario 3:
NO PV.
Created a PV as request: 10000000Mi.
I was expecting the PVC to be in pending state after creation. But it is internally creating one PV.

Any thoughts?

Can you please share YAML examples? Some other parameters could make sense and influence binding.

@kamil-dolmatov I have used the following. Have attached the code outputs as well. Thanks for taking time on this.

I have played around the storages as i experimented

===========================================
apiVersion: v1
kind: PersistentVolume
metadata:
name: myvol
labels:
app: myvol
spec:
accessModes:

  • ReadWriteOnce
    capacity:
    storage: 500Mi
    hostPath:
    path:

============================================

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myvolclaim
labels:
app: myvolclaim
spec:
accessModes:

  • ReadWriteOnce
    resources:
    requests:
    storage: 500Mi

==============================================

@kamil-dolmatov The second output as its not allowing to upload multiple

Have you tried specifying volume?

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myvolclaim
spec:
  volumeName: myvol
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi

Hello, @itschin2
Are you using minikube? By default, in minikube storage-provisioner addon is enabled.
You can check by running minikube addons list. You are getting different PV because of dynamic provisioning.

As a test you can try after disabling it.

Thanks @Tej-Singh-Rana - This makes sense.