<p>Recently, I installed the k8s via <code>kubeadm init</code> on my CentOS7 clusters. Unfortunately, I suffered a lots of problems. The biggest problem is &quot;How to create a dynamic local storage/volume for automatically assign PVs for PVCs?&quot;</p>
<p>Q: Why local storage not cloud storage service?</p>
<p>A: This is a limitation of new lab of my university.</p>
<p>Problem description:</p>
<p>The k8s(v1.18.0) did not create a default storage class for me after the installing process successfully. I not sure about that whether the situation normally. However, when I install my first application, <a href="https://zero-to-jupyterhub.readthedocs.io/en/latest/setup-jupyterhub/setup-jupyterhub.html" rel="nofollow noreferrer">JupyterHub</a>, on k8s, I got error from it because it could found a suitable PV to fit a PVC <code>hub-db-dir</code>. And then I attempt to manually a local storage class and a PV such below:</p>
<p><code>local-storage.yaml</code></p>
<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
</code></pre>
<p><code>hub-db-pv.yaml</code></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: hub-db-pv
  namespace: jhub
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /home/k8s_data_dir/jhub_dir
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node1
          - node2
          - node3
          - node4
</code></pre>
<p>The JupyterHub work after I apply these <code>yaml</code> files. I thought that will success to use JupyterHub. But I so naive. I enter the main page of JupyterHub then failure to running, <strong>because the JupyterHub create a new PVC for me but it could not bound a suitable PV.</strong>
I guess that the error cause by my local storage class which unable to auto create a PV to fit a PVC. Then I try to use an external provisioner <a href="https://github.com/kubernetes-sigs/sig-storage-lib-external-provisioner" rel="nofollow noreferrer"><code>sig-storage-lib-external-provisioner</code></a> but it can not fix my problem of local storage. (I according to the tutorial of <code>sig-storage-lib-external-provisioner</code> to do.)</p>
<p>So, my questions are:</p>
<ol>
<li>What is the best practice to fix the problem of local storage?</li>
<li>If you have a compromise method to do the same thing, please help me!</li>
</ol>
<p>Finally, I honest to thank you for your help!</p>

Guanzhou Ke
<p>High level steps to achieve dynamic PV creation using <code>local-storage</code> <code>StorageClass</code></p>
<p>From the docs <a href="https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner/blob/master/docs/operations.md" rel="nofollow noreferrer">here</a> on how to manage local volumes in your Kubernetes cluster.</p>
<ol>
<li>Create a directory for provisioner discovering</li>
<li>Prepare and set up local volumes in discovery directory</li>
</ol>
<p>Next from the docs <a href="https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner/blob/master/docs/getting-started.md#step-2-creating-a-storageclass-19" rel="nofollow noreferrer">here</a></p>
<ol start="3">
<li>Create a StorageClass</li>
<li>Create local persistent volumes</li>
</ol>
