<p>I am trying to deploy a persistentvolume for 3 pods to work on and i want to use the cluster's node storage i.e. not an external storage like ebs spin off.</p>

<p>To achieve the above i did the following experiment's -</p>

<p>1) I applied only the below PVC resource defined below -</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: pv1
  name: pv1
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
status: {}
</code></pre>

<p>This spin's up a storage set by default storageclass, which in my case was digital ocean's volume. So it created a 1Gi volume.</p>

<p>2) Created a PV resource and PVC resource like below -</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
</code></pre>

<hr>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: pv1
  name: pv1
spec:
  storageClassName: manual
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
status: {}
</code></pre>

<p>Post this i see my claim is bound.</p>

<pre><code>    pavan@p1:~$ kubectl get pvc
    NAME        STATUS   VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    pv1   Bound    task-pv-volume   10Gi       RWO            manual         2m5s
    pavan@p1:~$ kubectl get pv
    NAME             CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM               STORAGECLASS   REASON   AGE
    task-pv-volume   10Gi       RWO            Retain           Bound    default/pv1   manual                  118m
pavan@p1:~$ kubectl describe pvc
Name:          pv1
Namespace:     default
StorageClass:  manual
Status:        Bound
Volume:        task-pv-volume
Labels:        io.kompose.service=pv1
Annotations:   kubectl.kubernetes.io/last-applied-configuration:
                 {"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"io.kompose.service":"mo...
               pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      10Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Mounted By:    &lt;none&gt;
Events:
  Type     Reason              Age                 From                         Message
  ----     ------              ----                ----                         -------
  Warning  ProvisioningFailed  28s (x8 over 2m2s)  persistentvolume-controller  storageclass.storage.k8s.io "manual" not found
</code></pre>

<p>Below are my questions that i am hoping to get answers/pointers to -</p>

<ol>
<li><p>The above warning, storage class could not be found, do i need to
create one? If so, can you tell me why and how? or any pointer. (Somehow this link misses to state that - <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/</a>)</p></li>
<li><p>Notice the PV has storage capacity of 10Gi and PVC with request capacity of 1Gi, but still PVC was bound with 10Gi capacity? Can't i share the same PV capacity with other PVCs?</p></li>
</ol>

<p>For question 2) If i have to create different PVs for different PVC with the required capacity, do i have to create storageclass as-well? Or same storage class and use selectors to select corresponding PV?</p>

<p>I was trying to reproduce all behavior to answer all your questions. However, I don't have access to DigitalOcean, so I tested it on GKE.</p>
<blockquote>
<p>The above warning, storage class could not be found, do i need to
create one?</p>
</blockquote>
<p>According to the documentation and best practices, it is highly recommended to create a <code>storageclass</code> and later create PV / PVC based on it. However, there is something called &quot;manual provisioning&quot;. Which you did in this case.</p>
<p>Manual provisioning is when you need to manually create a PV first, and then a PVC with matching <code>spec.storageClassName:</code> field. Examples:</p>
<ul>
<li>If you create a PVC without <code>default storageclass</code>, <code>PV</code> and <code>storageClassName</code> parameter (afaik <code>kubeadm</code> is not providing default <code>storageclass</code>) - PVC will be stuck on <code>Pending</code> with event: <code>no persistent volumes available for this claim and no storage class is set</code>.</li>
<li>If you create a PVC with <code>default storageclass</code> setup on cluster but without <code>storageClassName</code> parameter it will be created based on default <code>storageclass</code>.</li>
<li>If you create a PVC with <code>storageClassName</code> parameter (somewhere in the Cloud, Minikube, or Microk8s), PVC will also get stuck <code>Pending</code> with this warning: <code>storageclass.storage.k8s.io &quot;manual&quot; not found.</code>
However, if you create <code>PV with the same</code>storageClassName` parameter, it will be bound in a while.</li>
</ul>
<p>Example:</p>
<pre><code>$ kubectl get pv,pvc
NAME                              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
persistentvolume/task-pv-volume   10Gi       RWO            Retain           Available           manual                  4s

NAME                        STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/pv1   Pending                                      manual         4m12s

...

kubectl get pv,pvc
NAME                              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM         STORAGECLASS   REASON   AGE
persistentvolume/task-pv-volume   10Gi       RWO            Retain           Bound    default/pv1   manual                  9s

NAME                        STATUS   VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/pv1   Bound    task-pv-volume   10Gi       RWO            manual         4m17s
</code></pre>
<p>The disadvantage of <code>manual provisioning</code> is that you have to create PV for each PVC (only 1:1 pairings will work). If you use <code>storageclass</code>, you can just create <code>PVC</code>.</p>
<blockquote>
<p>If so, can you tell me why and how? or any pointer.</p>
</blockquote>
<p>You can use <a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/" rel="nofollow noreferrer">documentation</a> examples or check <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="nofollow noreferrer">here</a>. As you are using a Cloud provider with default <code>storageclass</code> (or <code>sc</code> for short) set up for you, you can export it to a yaml file by: <br>
<code>$ kubectl get sc -o yaml &gt;&gt; storageclass.yaml</code>
(you will then need to clean it up, removing unique metadata, before you can reuse it).</p>
<p>Or, if you have more than one <code>sc</code>, you have to specify which one. Names of <code>storageclass</code> can be obtained by <br> <code>$ kubectl get sc</code>.
Later you can refer to <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#storageclass-v1-storage-k8s-io" rel="nofollow noreferrer">K8s API</a> to customize your <code>storageclass</code>.</p>
<blockquote>
<p>Notice the PV has storage capacity of 10Gi and PVC with request
capacity of 1Gi, but still PVC was bound with 10Gi capacity?</p>
</blockquote>
<p>You created manually a PV with 10Gi and the PVC requested 1Gi. As PVC and PV are bound 1:1 to each other, PVC searched for a PV which meets all conditions and has bound to it. PVC (&quot;pv1&quot;) requested 1Gi and the PV (&quot;task-pv-volume&quot;) met those requirements, so Kubernetes bound them. Unfortunately much of the space was wasted in this case.</p>
<blockquote>
<p>Can't i share the same PV capacity with other PVCs</p>
</blockquote>
<p>Unfortunately, you cannot bind more than 1 PVC to the same PV as the relationship between PVC and PV is 1:1, but you can configure many pods or deployments to use the same PVC (within the same namespace).</p>
<p>I can advise you to look at <a href="https://stackoverflow.com/questions/57798267/kubernetes-persistent-volume-access-modes-readwriteonce-vs-readonlymany-vs-read">this SO case</a>, as it explains <code>AccessMode</code> specifics very well.</p>
<blockquote>
<p>If i have to create different PVs for different PVC with the required
capacity, do i have to create storageclass as-well? Or same storage
class and use selectors to select corresponding PV?</p>
</blockquote>
<p>As I mentioned before, if you create PV manually with a specific size and a PVC bound to it, which requests less storage, the extra space will be wasted. So, you have to create PV and PVC with the same resource request, or let <code>storageclass</code> adjust the storage based on the PVC request.</p>
