<p>I just saw a yaml file for Postgres with <code>PersistentVolumeClaim</code> and <code>volumeMounts</code> and <code>volumes</code> with the <code>persistentVolumeClaim</code> in the <code>postgres</code> container. I couldn't find any <code>PersistentVolume</code> defined. </p>

<p>However, when the <code>postgres</code> container pod has been brought up, I can see a 
<code>PersistentVolume</code> bound to the <code>persistentVolumeClaim</code> defined in the yaml file.</p>

<p>So will k8s create the <code>PersistentVolume</code> if we only define the <code>PersistentVolumeClaim</code>? </p>

<p>yea that's correct, so when your cluster has dynamic provisioning with  <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="noreferrer">storage-classes</a> then you just need to provide the <a href="https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim" rel="noreferrer">PVC</a> , provisioner will get relevant information from PVC and storageClass, then based on these info it will create the PV.</p>

<ul>
<li>Provisioning of PV happens  dynamically 

<blockquote>
  <p>When none of the static PVs the administrator created matches a user’s PersistentVolumeClaim, the cluster may try to dynamically provision a volume specially for the PVC. This provisioning is based on StorageClasses: the PVC must request a storage class and the administrator must have created and configured that class in order for dynamic provisioning to occur.
  <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#dynamic" rel="noreferrer">dynamic-provisining</a></p>
</blockquote></li>
</ul>

<p>For example here you provide the following info in PVC</p>

<ol>
<li><p>StorageClassName</p></li>
<li><p>Requested Storage size</p></li>
<li><p>AccessModes </p></li>
</ol>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>

<p>In the StorageClass you provide the following information</p>

<ol>
<li><p>Provisioner </p></li>
<li><p>Other information </p></li>
</ol>

<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: manual
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
volumeBindingMode: Immediate
</code></pre>

<ul>
<li>PVC is a namespace scoped kubernetes object but storageclass in a cluster scope k8s object. So there is always a default storageclass in your cluster.so when you do not specify the name of the storgaeclass in your pvc, PV will be provisioned from the  default storage class.</li>
</ul>

<p><code>kubectl get sc,pvc,pv</code> will provide the relevant information </p>
