0

i'm trying to create a persistent mongo database with kubernetes
here is my config

persistent volume yaml file:

kind: PersistentVolume  
apiVersion: v1  
metadata:  
  name: task-pv-volume  
  labels:  
    type: local  
spec:  
  storageClassName: manual  
  capacity:  
    storage: 2Gi  
  accessModes:  
    - ReadWriteOnce  
  hostPath:  
    path: "/home/moses/test"  

persistent volume claim yaml file

kind: PersistentVolumeClaim  
apiVersion: v1  
metadata:  
  name: task-pv-claim  
spec:  
  storageClassName: manual  
  accessModes:  
    - ReadWriteOnce  
  resources:  
    requests:  
      storage: 2Gi    

mongo database deployment yaml file

apiVersion: apps/v1  
kind: Deployment  
metadata:  
  name: mongodb  
  labels:   
    app: mongodb  
spec:  
  replicas: 1  
  selector:  
    matchLabels:  
      app: mongodb  
  template:  
    metadata:  
      labels:  
        app: mongodb  
    spec:  
      containers:  
        - name: mongodb  
          image: mongo:latest  
          imagePullPolicy: IfNotPresent  
          ports:  
           - containerPort: 27017  
          volumeMounts:  
           - mountPath: "/data"  
             name: task-pv-storage  
      volumes:  
        - name: task-pv-storage  
          persistentVolumeClaim:  
           claimName: task-pv-claim  

the problem is that files in the data directory(default for mango) of the container are not being copied to the volume (the folders configdb and db are copied but they are empty)

kubectl version

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.2", GitCommit:"81753b10df112992bf51bbc2c2f85208aad78335", GitTreeState:"clean", BuildDate:"2018-04-27T09:22:21Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

the directory used for volume has 777 permission

my cluster is setup with kubeadm on ubuntu also i,m using the mongo docker image (i did not build one myself)

Nick Rak
  • 167
  • 7
moses
  • 83
  • 1
  • 12
  • I think that the data are supposed to be copied only on bind mounts. Since this is not, they won't be copied. Of course whatever your container writes to the volume will still be written as expected. – Andrew Savinykh May 08 '18 at 02:06
  • even when i store something in database it does not write anything and restarting the pod will cause the data to be lost – moses May 08 '18 at 03:03

1 Answers1

0

the problem will be resolved if you change the mongo database yaml file
- mountPath: "/data"
to
- mountPath: "/data/db"
even if you delete the deployment and recreate it the data in mongodb will persist

moses
  • 83
  • 1
  • 12