Skip to content

Build a mongodb instance on a kubernetes cluster using a statefulset configuration, it works for microservice-based applications on kubernetes to be able to use mongodb instances without having to create a database in the cloud.

License

Notifications You must be signed in to change notification settings

regiapriandi012/mongodb-kube

Repository files navigation

Build MongoDB Instance on Kubernetes

Build a mongodb instance on a kubernetes cluster using a statefulset configuration, it works for microservice-based applications on kubernetes to be able to use mongodb instances without having to create a database in the cloud.

Technology Used

MongoDB Kubernetes

Configure User

$ cd mongodb-instance-kubernetes
$ vi secret.yaml

Apply to Kubernetes Cluster

$ cd mongodb-instance-kubernetes
$ kubectl apply -f .
configmap/mongodb-configmap created
persistentvolume/mongodb-pv created
persistentvolumeclaim/mongodb-pvc created
secret/mongodb-secret created
service/mongodb created
statefulset.apps/mongodb created
storageclass.storage.k8s.io/mongodb-storageclass created

Access the Instance

$ kubectl get pods
NAME                              READY   STATUS    RESTARTS        AGE
mongodb-0                         1/1     Running   1 (13m ago)     6h44m
$ kubectl exec -it mongodb-0 -- sh
# mongo
MongoDB shell version v4.0.8
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("151c79c8-f6bc-44de-bae0-b8c2948e2b7f") }
MongoDB server version: 4.0.8
>

Access the Service

$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                          AGE
mongodb      NodePort    10.101.102.187   <none>        27017:30005/TCP                  2d12h

Connect the instance in MongoDB Compass

image

Successfuly Connected on MongoDB Compass

image

Instance Perfomance

image

About

Build a mongodb instance on a kubernetes cluster using a statefulset configuration, it works for microservice-based applications on kubernetes to be able to use mongodb instances without having to create a database in the cloud.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages