Home Explore Blog CI



kubernetes

2nd chunk of `content/en/blog/_posts/2017-01-00-Running-Mongodb-On-Kubernetes-With-Statefulsets.md`
0792c78eba313d5830bcb5492f0937bdb58b9de869098577000000010000092c
gcloud container clusters create "test-cluster"
 ```

This will make a three node Kubernetes cluster. Feel free to [customize the command](https://cloud.google.com/sdk/gcloud/reference/container/clusters/create) as you see fit.

Then, authenticate into the cluster:

```
gcloud container clusters get-credentials test-cluster
 ```

**Setting up the MongoDB replica set**

To set up the MongoDB replica set, you need three things: A [StorageClass](/docs/user-guide/persistent-volumes/#storageclasses), a [Headless Service](/docs/user-guide/services/#headless-services), and a [StatefulSet](/docs/concepts/abstractions/controllers/statefulsets/).

I’ve created the configuration files for these already, and you can clone the example from GitHub:

```
git clone https://github.com/thesandlord/mongo-k8s-sidecar.git

cd /mongo-k8s-sidecar/example/StatefulSet/
 ```

To create the MongoDB replica set, run these two commands:

```
kubectl apply -f googlecloud\_ssd.yaml

kubectl apply -f mongo-statefulset.yaml
 ```

That's it! With these two commands, you have launched all the components required to run an highly available and redundant MongoDB replica set.

At an high level, it looks something like this:

 ![](https://lh4.googleusercontent.com/ohALxLD4Ugj5FCwWqgqZ4xP9al4lTgrPDc9HsgPWYRZRz_buuYK6LKSC7A5n98DdOO-Po3Zq77Yt43-QhTWdIaXqltHI7PX0zMXAXbpiilYgdowGZapG0lJ9lgubwBj1CwNHHtXA)

Let’s examine each piece in more detail.

**StorageClass**

The storage class tells Kubernetes what kind of storage to use for the database nodes. You can set up many different types of StorageClasses in a ton of different environments. For example, if you run Kubernetes in your own datacenter, you can use [GlusterFS](https://www.gluster.org/). On GCP, your [storage choices](https://cloud.google.com/compute/docs/disks/) are SSDs and hard disks. There are currently drivers for [AWS](/docs/user-guide/persistent-volumes/#aws), [Azure](/docs/user-guide/persistent-volumes/#azure-disk), [Google Cloud](/docs/user-guide/persistent-volumes/#gce), [GlusterFS](/docs/user-guide/persistent-volumes/#glusterfs), [OpenStack Cinder](/docs/user-guide/persistent-volumes/#openstack-cinder), [vSphere](/docs/user-guide/persistent-volumes/#vsphere), [Ceph RBD](/docs/user-guide/persistent-volumes/#ceph-rbd), and [Quobyte](/docs/user-guide/persistent-volumes/#quobyte).

Title: Setting up MongoDB Replica Set Components
Summary
This section outlines the steps to set up a MongoDB replica set on Kubernetes, involving creating a Kubernetes cluster, authenticating to it, and then applying configuration files for a StorageClass and a StatefulSet. It highlights that the setup launches all necessary components for a highly available MongoDB replica set, and it mentions that the StorageClass defines the type of storage used for the database nodes, listing several options like GlusterFS, SSDs, and hard disks across different environments like GCP, AWS, Azure, and others.