How to persist data from mongodb running in kubernetes cluster

Hello all! I’m still very much learning the basics of kubernetes so forigve this question.

I have an application deployed to a digital ocean kubernetes cluster. One of the deployments in the cluster is a mongodb database using the mongo image from docker hub.

I’m trying to figure out how I can persist the data such that if I restart the mongo deployment / pod the data is not lost… Trying to google this is making me feel all kinds of dumb. I’m guessing the solution has something to do with block storage volumes? Any nudge in the right direction would be beyond appreciated!

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

I feel your pain, you need to read up on persistent volumes (pv) and persistent volume claims (pvc).

Block storage is something DO sells you PV is the connection from the block storage to kubernetes PVC is a pod making a claim on that storage all or in part so it is usable by an application.

You can also have storage on a (node) droplet but if the node goes away so does your data. Block storage -> pv -> pvc is the best way.

Good luck.

Digital ocean provides a “storage class” that automates the provisioning of the block storage to your cluster. Now I do not know this for certain, I do believe that you can tell the cluster not to auto provision. I am pretty sure you can manually provision the DO block storage from the previous cluster to the new cluster, and recreate the pv from that physical device. This would never be an automated procedure. You would have to dig into the docs further and learn more than just creating deployment yaml files etc. I haven’t done this yet. There is a great kubernetes slack channel, and there is a specific digital ocean channel. There are some staff from DO that hang out there and help.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel