<p>I am trying to setup couchbase operator 1.2 on my local system.
i followed the following steps :</p>
<ul>
<li><a href="https://docs.couchbase.com/operator/1.2/install-admission-controller.html" rel="nofollow noreferrer">Install the Couchbase Admission Controller</a>.</li>
<li><a href="https://docs.couchbase.com/operator/1.2/install-kubernetes.html" rel="nofollow noreferrer">Deploy the Couchbase Autonomous Operator</a>.</li>
<li><a href="https://docs.couchbase.com/operator/1.2/deploying-couchbase.html" rel="nofollow noreferrer">Deploy the Couchbase Cluster</a>.</li>
<li><a href="https://docs.couchbase.com/operator/1.2/accessing-couchbase.html" rel="nofollow noreferrer">Access CouchBase from UI</a>.</li>
</ul>
<p>But the problem with this is that as soon as the system or docker resets or the pod resets, the cluster's data is lost.</p>
<p>So for the same I tried to do it by adding persistent volume with local storage class as mentioned in the <a href="https://docs.couchbase.com/operator/1.2/persistent-volumes-setup.html#local-storage-class-experimental" rel="nofollow noreferrer">docs</a> but the result was still the same. The pod still gets resets. and i am unable to find the reason for the same.</p>
<p>So if anyone can advise on how to do the same with persistent volume on local storage class. I have successfully created a storage class. Just having problem while getting the cluster up and keep the consistency for the same.</p>
<p>Here is the yamls that i used to create the storage class and pv and pv claim</p>
<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
 name: myssd
provisioner: local
</code></pre>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
 name: couchbase-data-2
 labels:
    type: local
spec:
 capacity:
  storage: 10Gi
 accessModes:
  - ReadWriteOnce
 storageClassName: myssd
 hostPath:
    path: &quot;/home/&lt;user&gt;/cb-storage/&quot;
</code></pre>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-test-claim-2
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: myssd
  resources:
    requests:
      storage: 1Gi
</code></pre>
<p>Thanks in advance</p>

Abhishek tomar
<p>Persistent volume using <code>hostPath</code> is not durable. Use a <a href="https://kubernetes.io/docs/concepts/storage/volumes/#local" rel="nofollow noreferrer"><code>local</code></a> volume. Compared to <code>hostPath</code> volumes, <code>local</code> volumes can be used in a durable and portable manner without manually scheduling Pods to nodes, as the system is aware of the volume's node constraints by looking at the node affinity on the <code>PersistentVolume</code>.</p>
<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: couchbase-data
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /home/&lt;User&gt;/cb-storage/
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node1
          - node2
          - node3
          - node4
</code></pre>
<p>You don't need to create a PersistentVolume manually because the storage class will do that internally.</p>
<p>Also you need to configure the <code>local</code> volume provisioner as discussed <a href="https://stackoverflow.com/questions/62739026/kubernetes-what-is-the-best-practice-for-create-dynamic-local-volume-to-auto-as/62740063#62740063">here</a> so that dynamic provisioning using the local storage class happens.</p>
