MongoDB on Google Cloud Platform (GCP)

Learn via video courses
Topics Covered

Overview

Businesses rely on effective and scalable databases to manage their constantly expanding data requirements in today's data-driven environment. An adaptable and scalable option for managing huge amounts of organized and unstructured data is provided by the well-known NoSQL database MongoDB. MongoDB becomes even more potent when integrated with the strong infrastructure offered by Google Cloud Platform (GCP), allowing businesses to make use of cloud computing for their data management requirements. The integration of MongoDB with GCP will be covered in this article, along with the different configuration options, installation procedures, and best practices for maximizing MongoDB's capabilities on GCP.

What is GCP?

The Google Cloud Platform (GCP) is a collection of cloud computing services that Google provides. It offers a comprehensive range of platform and infrastructure services, enabling companies to develop, launch, and scale applications effectively. GCP provides a dependable and safe environment for managing data, hosting apps, and enabling advanced analytics. GCP guarantees low-latency access to services and high availability for vital applications thanks to a worldwide network of data centers.

GCP Zones

A specific number of separate zones are present in each Google Cloud region. Power, cooling, networking, and control planes are isolated from those of neighboring zones in each zone.

Atlas deploys clusters across the zones in regions with multiple zones, such as 2Z (for two zones) or 3Z (for three zones).

Regions that support 3Z clusters are marked as Recommended on the Atlas Add New Cluster form because they offer greater availability.

The amount of MongoDB nodes that Atlas may deploy is unaffected by the number of zones in a region. Replica sets made up of a minimum of three MongoDB nodes are the foundation of all MongoDB Atlas clusters.

By leveraging the multi-zone capabilities offered by Google Cloud Platform and deploying MongoDB Atlas clusters across these zones, organizations can ensure high availability and fault tolerance for their MongoDB deployments. This distributed architecture helps safeguard against single points of failure and contributes to a more robust and resilient data infrastructure.

Configuration Options in MongoDB Cluster

A standard set of resources is included with each Atlas cluster tier. The following resource configuration options are offered by Atlas.

Custom Storage Size The server root volume's size is reflected in the storage capacity. Clusters of Atlas running on Google Cloud make use of SSD persistent storage.

Usually, workloads don't need more than 2TB of storage.

The following resources are automatically configured by Atlas, and user alteration is not permitted:

  • Encrypted Storage Volumes
  • High Storage Speed

MongoDB Integration Options

Along with providing support for all geographical areas, the aforementioned product integrations make it possible for Google Cloud applications like Google Compute Engine, Google Cloud Functions, Google Cloud Run, and Google App Engine to quickly and safely use Atlas instances.

Networking Services Setting up network peering connections with GCP MongoDB using Google Virtual Private Cloud (VPC)

Identity and Security Services Sign up and log in to Atlas using your Google identity.

Key Management Service (KMS) for Google Cloud:

  • Set up KMS encryption for Atlas disk.
  • Set up KMS for client-side field-level encryption.

Procurement

GCP Marketplace for Procurement: Use GCP to pay for Atlas usage.

How to Use MongoDB On GCP

Out of all cloud providers, GCP has the most dominant network. You may take advantage of Google's low-latency infrastructure by running MongoDB on GCP(Google Cloud Platform).

Because GCP offers live migration, you can move your current VMs from one host to a different one without experiencing any downtime. Security is ingrained in Google's culture. You will gain from all the security procedures that Google has figured out and put into place throughout the years.

Using MongoDB on GCP involves several steps, from selecting the appropriate instance types to the installation and configuration process. Let's explore the key considerations for leveraging MongoDB on GCP effectively:

Selecting the Correct Instance Types

To use MongoDB on GCP, you initially require a compute instance. You should also assess the volume of data you have, the questions you have, and the service level agreements you have with your clients. Ideally, your chosen instance would be equipped with enough RAM to handle your workload and fast enough persistent storage. Databases function effectively in general with quick persistent storage. Start by creating a new instance.

Step 1: Open GCP and navigate to Compute Engine. Click Create Instance.

Open GCP

Step 2: Enter the information for your instance type and click Create. If it takes a few seconds, do not be concerned.

click Create

Configuring Firewall

Step 3: Configuring Firewall Rules for MongoDB

GCP MongoDB listens on port 27017, and it is essential to ensure that this port is accessible only to the specific IP addresses you want to grant access. It is crucial not to open this port to the entire world, as it can pose security risks. To restrict access and enhance security, you can create a new firewall rule in your Virtual Private Cloud (VPC) with the following specifications:

Source IP address ranges: Define the specific IP addresses or IP address ranges that are allowed to access your GCP MongoDB instance. This can include the IP addresses of your application servers or any other authorized entities.

Server IP addresses: Specify the IP addresses of your GCP MongoDB server instances that are allowed to receive incoming connections on port 27017. This ensures that only the designated GCP MongoDB instances can accept incoming connections.

Protocols and ports: Specify the protocol (TCP) and port number (27017) that should be allowed for incoming connections to GCP MongoDB.

By configuring these firewall rules within your VPC, you can ensure that access to your GCP MongoDB instances is restricted to the authorized IP addresses and ports, reducing the risk of unauthorized access and enhancing the overall security of your deployment.

Once you have successfully set up the necessary firewall rules and ensured secure access to GCP MongoDB, you can proceed to the next step: the installation of MongoDB on GCP(Google Cloud Platform).

MongoDB Installation on GCP

Step 1: First things first, the Ubuntu instance you've set up needs SSH. There are various ways to accomplish this. The use of SSH through GCP's browser feature is one option. To import the GPG MongoDB public key, use the following command in the terminal:

wget -qO – https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add –

Step2: Now you need to execute the following command to make a new file

Now to begin the MongoDB installation, you have to execute the below-mentioned command:

Run the following command to install MongoDB:

After that, MongoDB should be installed. If MongoDB is currently installed but not active. Launch MongoDB by using this command.

After following all these steps, you should verify whether the MongoDB is installed without any errors. Execute the following command in your terminal to verify the GCP MongoDB installation:

FAQs

Q. Can I run MongoDB on the Google Cloud Platform (GCP)?

A. MongoDB can be deployed and run on the Google Cloud Platform. GCP provides a variety of services and resources, such as Compute Engine and Kubernetes Engine, which can be utilized to host and manage MongoDB deployments. This allows you to leverage the scalability and reliability of GCP while utilizing the flexibility and power of MongoDB.

Q. What are the benefits of running MongoDB on GCP?

A Running MongoDB on GCP offers several advantages. Firstly, GCP provides a highly available and globally distributed infrastructure, allowing you to deploy MongoDB across multiple regions and zones for enhanced availability and disaster recovery. Additionally, GCP offers managed services like Compute Engine and Kubernetes Engine, simplifying the deployment and management of MongoDB. GCP also integrates well with other Google Cloud services, such as BigQuery and Dataflow, enabling advanced analytics and data processing capabilities.

Q. How can I ensure high availability for my MongoDB deployment on GCP?**

A. To ensure high availability, you can configure MongoDB replica sets across different zones within a GCP region. This allows for automatic failover and data redundancy in case of zone failures. Additionally, leveraging GCP's load-balancing capabilities can help distribute incoming traffic across MongoDB instances, further enhancing availability and scalability.

Conclusion

In this article, we have covered the following points:

  • The Google Cloud Platform (GCP) is a collection of cloud computing services that Google provides.
  • A specific number of separate zones are present in each Google Cloud region. Power, cooling, networking, and control planes are isolated from those of neighboring zones in each zone.
  • Atlas deploys clusters across the zones in regions with multiple zones, such as 2Z (for two zones) or 3Z (for three zones), and 3Z is the recommended one if available.
  • Custom storage sizes with high storage speeds and encrypted storage volumes are provided as the configuration options for the cluster.