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.
$ cd mongodb-instance-kubernetes
$ vi secret.yaml
$ 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
$ 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
>
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mongodb NodePort 10.101.102.187 <none> 27017:30005/TCP 2d12h