BlogAtlas Vector Search voted most loved vector database in 2024 Retool State of AI reportLearn more >>
MongoDB Developer
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right

Deploying the MongoDB Enterprise Kubernetes Operator on Google Cloud

Arek Borucki6 min read • Published Jan 13, 2023 • Updated Jan 13, 2023
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
This article is part of a three-parts series on deploying MongoDB across multiple Kubernetes clusters using the operators.
Deploying and managing MongoDB on Kubernetes can be a daunting task. It requires creating and configuring various Kubernetes resources, such as persistent volumes, services, and deployments, which can be time-consuming and require a deep understanding of both Kubernetes and MongoDB products. Furthermore, tasks such as scaling, backups, and upgrades must be handled manually, which can be complex and error-prone. This can impact the reliability and availability of your MongoDB deployment and may require frequent manual intervention to keep it running smoothly. Additionally, it can be hard to ensure that your MongoDB deployment is running in the desired state and is able to recover automatically from failures.
Fortunately, MongoDB offers operators, which are software extensions to the Kubernetes API that use custom resources to manage applications and their components. The MongoDB Operator translates human knowledge of creating a MongoDB instance into a scalable, repeatable, and standardized method, and leverages Kubernetes features to operate MongoDB for you. This makes it easier to deploy and manage MongoDB on Kubernetes, providing advanced features and functionality for running MongoDB in cloud-native environments.
There are three main Kubernetes operators available for deploying and managing MongoDB smoothly and efficiently in Kubernetes environments:
  • The MongoDB Community Kubernetes Operator is an open-source operator that is available for free and can be used to deploy and manage MongoDB Replica Set on any Kubernetes cluster. It provides basic functionality for deploying and managing MongoDB but does not include some of the more advanced features available in the Enterprise and Atlas operators.
  • The MongoDB Enterprise Kubernetes Operator is a commercial Kubernetes operator included with the MongoDB Enterprise subscription. It allows you to easily deploy and manage any type of MongoDB deployment (standalone, replica set, sharded cluster) on Kubernetes, providing advanced features and functionality for deploying and managing MongoDB in cloud-native environments.
  • The MongoDB Atlas Kubernetes Operator is an operator that is available as part of the Atlas service. It allows you to quickly deploy and manage MongoDB on the Atlas cloud platform, providing features such as automatic provisioning and scaling of MongoDB clusters, integration with Atlas features and services, and automatic backups and restores. You can learn more about this operator in our blog post on application deployment in Kubernetes.
This article will focus on the Enterprise Operator. The MongoDB Enterprise Kubernetes Operator seamlessly integrates with other MongoDB Enterprise features and services, such as MongoDB Ops Manager (which can also run on Kubernetes) and MongoDB Cloud Manager. This allows you to easily monitor, back up, upgrade, and manage your MongoDB deployments from a single, centralized location, and provides access to a range of tools and services for managing, securing, and optimizing your deployment.

MongoDB Enterprise Kubernetes Operator

The MongoDB Enterprise Kubernetes Operator automates the process of creating and managing MongoDB instances in a scalable, repeatable, and standardized manner. It uses the Kubernetes API and tools to handle the lifecycle events of a MongoDB cluster, including provisioning storage and computing resources, configuring network connections, setting up users, and making changes to these settings as needed. This helps to ease the burden of manually configuring and managing stateful applications, such as databases, within the Kubernetes environment.
The Kubernetes Operator manages the typical lifecycle events for a MongoDB cluster: provisioning storage and computing power, configuring network connections, setting up users, and changing these settings as needed

Kubernetes Custom Resource Definitions

Kubernetes CRDs (Custom Resource Definitions) is a feature in Kubernetes that allows users to create and manage custom resources in their Kubernetes clusters. Custom resources are extensions of the Kubernetes API that allow users to define their own object types and associated behaviors. With CRDs, you can create custom resources that behave like built-in Kubernetes resources, such as StatefulSets, Deployments, Pods, and Services, and manage them using the same tools and interfaces. This allows you to extend the functionality of Kubernetes and tailor it to their specific needs and requirements.
The MongoDB Enterprise Operator currently provides the following custom resources for deploying MongoDB on Kubernetes:
The following diagram describes how the Kubernetes Operator behaves if you make changes to a sharded cluster's

Installing and configuring Enterprise Kubernetes Operator

For this tutorial, we will need the following tools: 

GKE Kubernetes cluster creation 

To start, let's create a Kubernetes cluster in a new project. We will be using GKE Kubernetes. I use this script to create the cluster. The cluster will have four worker nodes and act as Ops Manager and MongoDB Enterprise Operators Kubernetes Cluster.
Now that the cluster has been created, we need to obtain the credentials.
Display the newly created cluster.
You should see your cluster listed here. Make sure your context is set to master cluster.
We are able to start MongoDB Kubernetes Operator installation on our newly created Kubernetes cluster! 

Enterprise Kubernetes Operator 

We can install the MongoDB Enterprise Operator with a single line Helm command. The first step is to  add the MongoDB Helm Charts for Kubernetes repository to Helm.
I want to create the operator in a separate, dedicated Kubernetes namespace (the operator uses default namespace by default). This will allow me to isolate the operator and any resources it creates from other resources in my cluster. The following command will install the CRDs and the Enterprise Operator in the mongodb-operatornamespace. The operator will be watching only the mongodb-operator namespace. You can read more about setting up the operator to watch more namespaces in the official MongoDB documentation.
Start by creating the mongodb-operatornamespace.
Install the MongoDB Kubernetes Operator and set it to watch only the mongodb-operator namespace.
The namespace has been created and the operator is running! You can see this by listing the pods in the newly created namespace.
You can see that the helm chart is running with this command.

Verify the installation

You can verify that the installation was successful and is currently running with the following command.
Let's display Custom Resource Definitions installed in the step above in the watched namespace.
All required service accounts has been created in watched namespace.
Validate if the Kubernetes Operator was installed correctly by running the following command and verify the output.
Finally, double-check watched namespaces.
The MongoDB Enterprise Operator is now running in your GKE cluster.

MongoDB Atlas Kubernetes Operator

It's worth mentioning another operator here --- a new service that integrates Atlas resources with your Kubernetes cluster. Atlas can be deployed in multi-cloud environments including Google Cloud. The Atlas Kubernetes Operator allows you to deploy and manage cloud-native applications that require data services in a single control plane with secure enterprise platform integration.
This operator is responsible for managing resources in Atlas using Kubernetes custom resources, ensuring that the configurations of projects, database deployments, and database users in Atlas are consistent with each other. The Atlas Kubernetes Operator uses the AtlasProject, AtlasDeployment, and AtlasDatabaseUser Custom Resources that you create in your Kubernetes cluster to manage resources in Atlas.
These custom resources allow you to define and configure the desired state of your projects, database deployments, and database users in Atlas. To learn more, head over to our blog post on application deployment in Kubernetes with the MongoDB Atlas Operator.


Upon the successful installation of the Kubernetes Operator, we are able to use the capabilities of the MongoDB Enterprise Kubernetes Operator to run MongoDB objects on our Kubernetes cluster. The Operator enables easy deploy of the following applications into Kubernetes clusters:
  • MongoDB --- replica sets, sharded clusters, and standalones --- with authentication, TLS, and many more options.
  • Ops Manager --- enterprise management, monitoring, and backup platform for MongoDB. The Operator can install and manage Ops Manager in Kubernetes for you. Ops Manager can manage MongoDB instances both inside and outside Kubernetes. Installing Ops Manager is covered in the second article of the series.
  • MongoMulti --- Multi-Kubernetes-cluster deployments allow you to add MongoDB instances in global clusters that span multiple geographic regions for increased availability and global distribution of data. This is covered in the final part of this series.
Want to see the MongoDB Enterprise Kubernetes Operator in action and discover all the benefits it can bring to your Kubernetes deployment? Continue reading the next blog of this series and we'll show you how to best utilize the Operator for your needs

Facebook Icontwitter iconlinkedin icon
Rate this tutorial
This is part of a series
Deploying MongoDB Across Multiple Kubernetes Clusters
Up Next

More in this series

Streaming Data with Apache Spark and MongoDB

Jul 11, 2023 | 7 min read

Tuning the MongoDB Connector for Apache Kafka

Jul 19, 2024 | 10 min read

Learn How to Leverage MongoDB Data within Kafka with New Tutorials!

Jun 14, 2022 | 1 min read

Spark Up Your MongoDB and BigQuery using BigQuery Spark Stored Procedures

Apr 09, 2024 | 5 min read
Table of Contents