1

I am running Mongodb pod in kunernetes cluster using nfs volume.I am writing pod.yml like this

enter image description here

but i am getting the below errorenter image description here

Could anybody suggest how to resolve the above issue?

RickL
  • 3,318
  • 10
  • 38
  • 39
BSG
  • 673
  • 2
  • 13
  • 33

1 Answers1

1

I am running Mongodb pod in kunernetes cluster using nfs volume.I am writing pod.yml like this

Putting mongo in the command: is erroneous. The daemon is mongod and the image would have started it automatically had you not provided any command: at all.

Further, all command: lines are exec-ed, so putting bash -c in front of a command is just moving that command out of pid 1 and unnecessarily adding memory consumption to your container.

mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • Thanks for responding my Question Matthew L Daniel. – BSG Jul 09 '18 at 12:39
  • I changed the daemon as mongod. I am getting the Error like, Exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating – BSG Jul 09 '18 at 12:40
  • I changed the daemon as mongod. I am getting the Error like, **Exception in initAndListen: Illegal Operation: Attempted to create a lock file on a read-only directory: /data/db, terminating**. Can u please suggest me which command we need to use for starting the image automatically? – BSG Jul 09 '18 at 12:58
  • _Attempted to create a lock file on a read-only directory: /data/db_ is almost certainly an indication that the directory in your PVC is owned by root, and not by the mongo user. You can `chown` it by hand or use an `initContainer:` to `chown` it every time, [as shown by the previous answer I gave you](https://stackoverflow.com/a/51203031/225016) – mdaniel Jul 09 '18 at 16:02
  • Thank you so much Matthew L Daniel. It is worked me for single pod mongodb container. – BSG Jul 09 '18 at 20:10
  • I tried with **3 replicas of mongodb** through deployment.yml . Only one container is running and remaining two were in Waiting status. Getting error as `exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Unknown error). Another mongod instance is already running on the /data/db directory, terminating ` – BSG Jul 09 '18 at 20:11
  • `You can **chown** it by hand or use an init Container: to chown it every time`. Is it applicable for single mongodb container? Could you please guide me one this issue? – BSG Jul 09 '18 at 20:15
  • Sorry, I just now mentally registered the "nfs" portion of your question; reasonable people can differ about whether NFS is appropriate for Mongo, but either way: you'll want to have dedicated PVCs for each member of [the `StatefulSet`](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/); I realize your yaml doesn't say `StatefulSet`, but that is absolutely the construct one should use for databases in-cluster. You can continue to use NFS, it'll just end up being a subdirectory inside the NFS volume for each Pod – mdaniel Jul 10 '18 at 03:59
  • I tried StatefulSets with 3 replicas of mongo containers.I created 3 directories and mapped each one with each pv and pvcs sequentially. 3 pods are in running.How Could i check the data persistency is maintained or not across the cluster? – BSG Jul 10 '18 at 16:10