<p>I use Kompose to convert docker-compose to Kubernetes files. When I used images runned on Docker (no Kubernetes), it used postgres volume to have persistent data. Now, with the same docker-compose, if I run with Kubernetes using the file created with Kompose, every time I launch Kubernetes the database is empty.
How is this possible? If I look at Docker Desktop, in fact, I see that the volumes do not have the tag &quot;IN USE&quot;.</p>
<p>How do I do that?</p>
<p><strong>Thank you in advance!</strong></p>
<p><strong>docker-compose.yaml:</strong></p>
<pre><code>version: '3'
services:
  eureka-server:
    image: com.petcare/eureka-server:0.0.1-SNAPSHOT
    container_name: eureka-server
    expose:
      - 8761

  auth-service:
    image: com.petcare/auth-service:0.0.1-SNAPSHOT
    container_name: auth-service
    expose:
      - 8081
    depends_on:
      - eureka-server
      - postgresqldb

  map-service:
    image: com.petcare/map-service:0.0.1-SNAPSHOT
    container_name: map-service
    expose:
      - 8082
    depends_on:
      - eureka-server
      - postgresqldb

  reservation-service:
    image: com.petcare/reservation-service:0.0.1-SNAPSHOT
    container_name: reservation-service
    expose:
      - 8083
    depends_on:
      - eureka-server
      - postgresqldb

  user-service:
    image: com.petcare/user-service:0.0.1-SNAPSHOT
    container_name: user-service
    expose:
      - 8084
    depends_on:
      - eureka-server
      - postgresqldb

  api-gateway:
    image: com.petcare/api-gateway:0.0.1-SNAPSHOT
    container_name: api-gateway
    expose:
      - 8080
    depends_on:
      - eureka-server
    labels:
      kompose.service.type: NodePort
      kompose.service.nodeport.port: &quot;30000&quot;

  postgresqldb:
    image: postgres
    container_name: postgres
    ports:
      - &quot;5432:5432&quot;
    environment:
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_DB=websitepetcare
    volumes:
      - database-data:/var/lib/postgresql/data/
    labels:
      kompose.service.type: NodePort
      kompose.service.nodeport.port: &quot;30002&quot;

  pgadmin:
    container_name: pgadmin4_container
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: root
      PGADMIN_LISTEN_PORT: 50
    ports:
      - &quot;5050:50&quot;
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    links:
      - &quot;postgresqldb:pgsql-server&quot;
    depends_on:
      - postgresqldb
    labels:
      kompose.service.type: NodePort
      kompose.service.nodeport.port: &quot;30001&quot;

volumes:
  database-data:
    external: true
  pgadmin-data:
    external: true
</code></pre>
<p><strong>file created with kompose convert:</strong></p>
<pre><code>apiVersion: v1
items:
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -o kubernetes-services-deployments.yaml
        kompose.service.nodeport.port: &quot;30001&quot;
        kompose.service.type: NodePort
        kompose.version: 1.26.0 (40646f47)
      creationTimestamp: null
      labels:
        io.kompose.service: pgadmin
      name: pgadmin
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: pgadmin
      strategy:
        type: Recreate
      template:
        metadata:
          annotations:
            kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -o kubernetes-services-deployments.yaml
            kompose.service.nodeport.port: &quot;30001&quot;
            kompose.service.type: NodePort
            kompose.version: 1.26.0 (40646f47)
          creationTimestamp: null
          labels:
            io.kompose.service: pgadmin
        spec:
          containers:
            - env:
                - name: PGADMIN_DEFAULT_EMAIL
                  value: admin@admin.com
                - name: PGADMIN_DEFAULT_PASSWORD
                  value: root
                - name: PGADMIN_LISTEN_PORT
                  value: &quot;50&quot;
              image: dpage/pgadmin4
              name: pgadmin4-container
              ports:
                - containerPort: 50
              resources: {}
              volumeMounts:
                - mountPath: /var/lib/pgadmin
                  name: pgadmin-data
          restartPolicy: Always
          volumes:
            - name: pgadmin-data
              persistentVolumeClaim:
                claimName: pgadmin-data
    status: {}
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: pgadmin-data
      name: pgadmin-data
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Mi
    status: {}
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -o kubernetes-services-deployments.yaml
        kompose.service.nodeport.port: &quot;30002&quot;
        kompose.service.type: NodePort
        kompose.version: 1.26.0 (40646f47)
      creationTimestamp: null
      labels:
        io.kompose.service: postgresqldb
      name: postgresqldb
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: postgresqldb
      strategy:
        type: Recreate
      template:
        metadata:
          annotations:
            kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -o kubernetes-services-deployments.yaml
            kompose.service.nodeport.port: &quot;30002&quot;
            kompose.service.type: NodePort
            kompose.version: 1.26.0 (40646f47)
          creationTimestamp: null
          labels:
            io.kompose.service: postgresqldb
        spec:
          containers:
            - env:
                - name: POSTGRES_DB
                  value: websitepetcare
                - name: POSTGRES_PASSWORD
                  value: postgres
                - name: POSTGRES_USER
                  value: postgres
              image: postgres
              name: postgres
              ports:
                - containerPort: 5432
              resources: {}
              volumeMounts:
                - mountPath: /var/lib/postgresql/data/
                  name: database-data
          restartPolicy: Always
          volumes:
            - name: database-data
              persistentVolumeClaim:
                claimName: database-data
    status: {}
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: database-data
      name: database-data
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Mi
    status: {}
kind: List
metadata: {}
</code></pre>

BlowLore
<p>In a comment you write:</p>
<blockquote>
<p>When I want to delete all, I run this command:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl delete -f kubernetesFile.yaml
</code></pre>
<p>When I start again all services with:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f kubernetesFile.yaml
</code></pre>
<p>I have the database empty.</p>
</blockquote>
<p>The Kompose-converted <code>kubernetesFile.yaml</code> contains all of the Kubernetes resources, including the PersistentVolumeClaim that tells it to hold persistent data.  So when you <code>kubectl delete -f kubernetesFile.yaml</code>, it deletes the PersistentVolumeClaim and the data, and then when you re-<code>apply</code> it, you get a new empty volume.</p>
<p>You don't need to run <code>kubectl delete</code> here.  Just run <code>kubectl apply -f kubernetesFile.yaml</code> when your setup changes.  Anything that's updated will be changed, and the cluster will delete and recreate Pods as needed.  Anything that's not updated will stay unchanged.  If you delete a Deployment or another resource you'll have to delete that by hand (<code>kubectl delete deployment unused-deployment</code>).</p>
