- DigitalOcean account: To easily manage kubernetes resources.
- doctl CLI: To configure k8s cluster on DigitalOcean
- kubectl CLI: To interact with the k8s cluster
- In the dashboard, go to
kubernetes
section from the side menu and selectCreate Cluster
option. - Select k8s version (leave untouched to use recommended version). Choose nearest datacenter region according to your location.
- Choose cluster capacity according to your requirement.
- Give this cluster a name, select project and give any optional tags if you want. And click
Create Cluster
. - Once the cluster is created, scroll down and run the given command to add the cluster credentials to your local system.
- Run the following commands in the terminal:
git clone https://github.com/Rishabh510/digital-ocean-k8s-challenge.git cd digital-ocean-k8s-challenge cd mongodb-config
- Modify the
yaml
files in themongodb-config
folder as per your requirements (leave untouched for default configuration).NOTE: Make sure to modify the
username
andpassword
in themongodb-secrets.yaml
file encoded in base64 format. - Run the following after all confirming the configuration.
kubectl apply -f .
- Run the following command to check if the created services are up and running.
kubectl get all
- Run the following command to exec into the mongo client interactively in bash.
kubectl exec deployment/mongo-client -it -- /bin/bash
- Run the following to access the created mongo shell via nodeport
NOTE: Make sure you have subsituted the username and password in the below command.
mongo --host mongo-nodeport-svc --port 27017 -u rishabh -p rishabh
Congratulations! MongoDB has been successfully deployed to your k8s cluster.