<p>Hi just A noobiew question.
I manage(?) to implement PV and PVC over mongo DB. I'm using PV as local and not on the cloud.
There is a way to save the data when k8s runs on my pc after container restart ?</p>
<p>I'm not sure I got this right <strong>but what I need is to save the mongo data after he restart</strong>. What is the best way ? (no mongo atlas)</p>
<p><strong>UPDATE:
I managed to make tickets service db work great, but I have 2 other services that it just wont work ! i update the yaml files so u can see the current state. the auth-mongo is just the same as tickets-mongo so why it wont work ?</strong></p>
<p>the ticket-depl-mongo yaml file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tickets-mongo-depl

spec:
  replicas: 1
  selector:
    matchLabels:
      app: tickets-mongo
  template:
    metadata:
      labels:
        app: tickets-mongo
    spec:
      containers:
        - name: tickets-mongo
          image: mongo
          args: [&quot;--dbpath&quot;, &quot;data/auth&quot;]
          livenessProbe:
            exec:
              command:
                - mongo
                - --disableImplicitSessions
                - --eval
                - &quot;db.adminCommand('ping')&quot;
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          volumeMounts:
            - mountPath: /data/auth
              name: tickets-data
      volumes:
        - name: tickets-data
          persistentVolumeClaim:
            claimName: tickets-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: tickets-mongo-srv
spec:
  selector:
    app: tickets-mongo
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<p>auth-mongo-depl.yaml :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-mongo-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth-mongo
  template:
    metadata:
      labels:
        app: auth-mongo
    spec:
      containers:
        - name: auth-mongo
          image: mongo
          args: [&quot;--dbpath&quot;, &quot;data/db&quot;]
          livenessProbe:
            exec:
              command:
                - mongo
                - --disableImplicitSessions
                - --eval
                - &quot;db.adminCommand('ping')&quot;
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          volumeMounts:
            - mountPath: /data/db
              name: auth-data
      volumes:
        - name: auth-data
          persistentVolumeClaim:
            claimName: auth-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: auth-mongo-srv
spec:
  selector:
    app: auth-mongo
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017



NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                 STORAGECLASS   REASON   AGE
pv-auth      1Gi        RWO            Retain           Bound    default/auth-pvc      auth                    78m
pv-orders    1Gi        RWO            Retain           Bound    default/orders-pvc    orders                  78m
pv-tickets   1Gi        RWO            Retain           Bound    default/tickets-pvc   tickets                 78m
</code></pre>
<p>I'm using mongo containers with tickets, orders, and auth services.
Just adding some info to make it clear.</p>
<pre><code>NAME                                     READY   STATUS    RESTARTS   AGE
auth-depl-66c5d54988-ffhwc               1/1     Running   0          36m
auth-mongo-depl-594b98fcc5-k9hj8         1/1     Running   0          36m
client-depl-787cf6c7c6-xxks9             1/1     Running   0          36m
expiration-depl-864d846445-b95sh         1/1     Running   0          36m
expiration-redis-depl-64bd9fdb95-sg7fc   1/1     Running   0          36m
nats-depl-7d6c7dc46-m6mcg                1/1     Running   0          36m
orders-depl-5478cf4dfd-zmngj             1/1     Running   0          36m
orders-mongo-depl-5f974847d7-bz9s4       1/1     Running   0          36m
payments-depl-78f85d94fd-4zs55           1/1     Running   0          36m
payments-mongo-depl-5d5c47494b-7zjrl     1/1     Running   0          36m
tickets-depl-84d59fd47c-cs4k5            1/1     Running   0          36m
tickets-mongo-depl-66798d9874-cfbqb      1/1     Running   0          36m
</code></pre>
<p>example for pv:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-tickets
  labels:
    type: local
spec:
  storageClassName: tickets
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/tmp&quot;
</code></pre>

YanivCode
<p>All I had to do is to change the path of hostPath in each PV. the same path will make the app to faill.</p>
<p>pv1:</p>
<pre><code> hostPath:
    path: &quot;/path/x1&quot;
</code></pre>
<p>pv2:</p>
<pre><code> hostPath:
        path: &quot;/path/x2&quot;
</code></pre>
<p>like so.. just not the same path.</p>
