Difficulty: Intermediate
Estimated Time: 20 minutes

Welcome to Sharded MongoDB with Kubernetes tutorial!
Learn how to deploy sharded cluster of MongoDB on Kubernetes cluster with pods affinity and NFS share as persistent volume claims.

Dawid 'Apoc' Prus

Sharded MongoDB on K8s with persistent volumes on NFS share

Step 1 of 8

Step 1 - Deploy a kubernetes cluster

In this scenario, We are going to deploy a Sharded MongoDB with two shards.
To add a bit real-life conditions, We are going to use two nodes with kubernetes cluster on it.
Next, We will configure persistent volume claims for each shard and config database using nfs-client-provisioner.
Also, We will try to achieve some minimal pod affinity for our two nodes.

Task

For this scenario, We are using a shell script which deploys for us k8s cluster:
/opt/launch-kubeadm.sh - This command is now running on HOST1. Please wait until it ends
If You are wondering what does this script do, please take a look at this tutorial.

You can now join the second host to the cluster by running the following command: kubeadm join [[HOST1_IP]]:6443 --token 96771a.f608976060d16396 --discovery-token-unsafe-skip-ca-verification

Allow scheduling of pods on Kubernetes master node:
kubectl taint node master node-role.kubernetes.io/master:NoSchedule-
After about a one minute both nodes should be Ready, You can check the statuses by executing this command on master node:
kubectl get nodes
You do not have to wait, in the next step, We need to install NFS packages so it may proceed in the background.

Terminal Host 2