Home > OS >  Using PersistentStorage to my workdir deletes everything?
Using PersistentStorage to my workdir deletes everything?

Time:04-10

I'm using a PersistentVolume and a Claim and then mounting it to my workdir '/server' to create a simple Minecraft server using K8s, and when I deploy it the jar file isn't there anymore?enter image description here

deployment.yaml
---------------
    spec:
      volumes:
        - name: minecraft-pvstorage
          persistentVolumeClaim:
            claimName: minecraft-pvclaim
      containers:
        - name: minecraft-deployment
          image: localhost:32000/minecraft:1.18.2-new
          imagePullPolicy: Always
          ports:
            - containerPort: 30007
          volumeMounts:
            - name: minecraft-pvstorage
              mountPath: /server
pv.yaml
-------
apiVersion: v1
kind: PersistentVolume
metadata:
  name: minecraft-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/minecraft"
pvclaim.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minecraft-pvclaim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Can anyone help me with this? It works when I delete the volumeMounts from the deployment.yaml.

CodePudding user response:

When you mount something onto a directory in the image that already has content, the content in the image becomes obscured, i.e. hidden and replaced with the content of the mount.

More info here: https://docs.docker.com/storage/bind-mounts/#mount-into-a-non-empty-directory-on-the-container

CodePudding user response:

I figured it out.

In my deployment.yaml I defined a mount for just the world and that ended up saving all of the world data.

deployment.yaml
--------------
volumeMounts:
    - name: minecraft-pvstorage
      mountPath: /server/1.18.2/world
      subPath: world
  • Related