Rajesh
Rajesh

Reputation: 479

How does kubernetes volume mounts map to docker volume

I am new to kubernetes and experimenting with volumes. I have a docker image which declares 2 volumes as in :

VOLUME ["/db/mongo/data" , "/db/mongo/log"]

I am using a StatefulSet , wherein I have 2 volume mounts, as in --

volumeMounts:
            - name: mongo-vol
              mountPath: << path1 >>
              subPath: data
            - name: mongo-vol
              mountPath: << path2 >>
              subPath: log

My question is i) should path1 & path2 be mentioned as "/db/mongo/data" and "/db/mongo/log" respectively ??

ii) Or it can be any path where the volumes would be mounted inside the container, and "/db/mongo/data" & "/db/mongo/log" container paths would be automatically mapped to those mount points ?

I tried reading up the documentation and tried both options but some confusion still remains. Appreciate some help here.

Upvotes: 0

Views: 96

Answers (1)

Burak Serdar
Burak Serdar

Reputation: 51512

Your both volume mounts reference to the same volume mongo-vol. That tells me this is a volume containing the data and log directories. You should use /db/mongo/log and /db/mongo/data as your mountPaths, and specify the subPath as log and data respectively. That will mount the volume referenced by mongo-vol, and mount data and log directories in that volume on to those directories.

If you had two seperate volumes, a mongo-data and mongo-log, then you would mount them the same way, without the subPath, because you are not referencing sub-directories under the volume.

Upvotes: 2

Related Questions