Categories: BlogCanonicalUbuntu

Running MongoDB on Kubernetes

Running mongodb on kubernetes

Containers are a lightweight, portable, and consistent way to package applications and their dependencies. Containers provide an isolated environment, ensuring an application runs reliably across different environments. Enterprises and tech-savvy individuals are using container technologies because of their benefits. However,  container orchestration tools have become necessary to manage clusters with the rise in container usage.

Sponsored

Kubernetes, or k8s for short, is the most known container orchestrator and has grown into a feature-rich cloud-native platform. Kubernetes helps manage the lifecycle of containers, particularly in large, dynamic environments. It automates containerised workloads and services’ deployment, networking, scaling, and availability. Running containers – lightweight and usually ephemeral by nature – in small numbers is easy to do manually. However, managing them at scale in production environments can be a significant challenge without a container orchestration platform’s automation.

On the database front, organisations want to build and run scalable database applications in public, private and hybrid environments. This is why containerised databases like MongoDB can run in Kubernetes and benefit from portability, helping teams minimise vendor lock-in, get DevOps friendliness, scalability and cost-effectiveness.

Why run MongoDB on Kubernetes?

Running MongoDB on Kubernetes can be complex yet valuable, as it allows you to containerise and orchestrate MongoDB instances for scalability, resilience, and easier management. Here are some of the benefits: 

Scalability: Kubernetes makes it easier to scale MongoDB horizontally by adding or removing replicas of your database instances. This allows you to dynamically handle increased workloads and traffic as your application grows or as usage spikes.

High availability: Kubernetes provides features like replica sets and StatefulSets that ensure high availability for your MongoDB instances. In case of node failures, Kubernetes can automatically reschedule pods to maintain the desired number of replicas, helping to prevent downtime.

Orchestration: Kubernetes abstracts the underlying infrastructure, making managing and orchestrating your MongoDB deployment easier. In declarative configuration files, you can define your MongoDB resources, including pods, services, and storage.

Running MongoDB in Kubernetes can be very beneficial, but what exactly do you need to have a production-ready database running in Kubernetes? There can be multiple considerations besides those listed above, like security, deployment readiness, backup and restore, monitoring, and more.

Ubuntu as your host for MongoDB on Kubernetes

Canonical is currently maintaining a project called Charmed MongoDB, a K8s operator that contains code that takes over automated tasks to manage MongoDB hosted in Ubuntu. The K8s operator is also called a K8s charm, a business logic encapsulated in reusable software packages that automate every aspect of an application’s life, in this case, for MongoDB. 

The operator is based on Juju, an open source orchestration engine for software operators that enables the deployment, integration and lifecycle management of applications at any scale on any infrastructure.

To support applications running in Kubernetes, Canonical also maintains two other CNCF-certified Kubernetes distributions: Charmed Kubernetes and MicroK8s, which help simplify and accelerate the deployment of Kubernetes.

Sponsored

Get started

The Charmed MongoDB K8s Operator delivers automated operations management from day 0 to day 2 for MongoDB. Charmed MongoDB is a continuously developing project; we constantly offer richer features over time. 

To get started, you must have the environment: the Ubuntu OS, a minimum set of CPU, storage and RAM. You must also be familiar with basic terminal commands and MongoDB concepts such as replication and users. 

Afterwards, you need to set up your environment using Microk8s and Juju.

You can then use Charmed MongoDB to manage the following operations:

  • Deploy MongoDB using a single command.
  • Access the admin database directly.
  • Add high availability with replication.
  • Change the admin password.
  • Automatically create MongoDB users via Juju relations.
  • Enable secure communications with TLS.

Learn to use Charmed MongoDB (K8s operator) in your machine.

Conclusion

Running database clusters in public, private and hybrid environments provides multiple benefits. Kubernetes provides the additional advantages of portability, reduced vendor lock-in, DevOps friendliness, scalability and cost-effectiveness.

While there are many advantages to running MongoDB in Kubernetes, it’s important to note that managing a distributed database in a containerised environment comes with its challenges, and careful planning, monitoring, and optimisation are required for a successful deployment. Additionally, it helps to stay up-to-date with best practices and evolving technologies to make the most of this approach.

Canonical offers security patching, support, advisory and managed services for databases like MongoDB so you can seamlessly deploy and run your database in Kubernetes. Contact us to learn more.

Trademark Notice

“MongoDB” is a trademark or registered trademark of MongoDB Inc. Other trademarks are property of their respective owners. Charmed MongoDB is not sponsored, endorsed, or affiliated with MongoDB, Inc.

Ubuntu Server Admin

Recent Posts

Building RAG with enterprise open source AI infrastructure

One of the most critical gaps in traditional Large Language Models (LLMs) is that they…

20 hours ago

Life at Canonical: Victoria Antipova’s perspective as a new joiner in Product Marketing

Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…

2 days ago

What is patching automation?

What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…

3 days ago

A beginner’s tutorial for your first Machine Learning project using Charmed Kubeflow

Wouldn’t it be wonderful to wake up one day with a desire to explore AI…

4 days ago

Ubuntu brings comprehensive support to Azure Cobalt 100 VMs

Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…

4 days ago

Ubuntu Weekly Newsletter Issue 870

Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…

5 days ago