Deploying the MongoDB Deployment
Let’s create a post now. I added a description of the MongoDB post file again at the end of this section. Save the following manifest as mongodb-deployment.yaml. Here we use the official mongo image from the docker hub.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mongo
name: mongo
spec:
replicas: 1
selector:
matchLabels:
app: mongo
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mongo
spec:
containers:
– image: mongo
name: mongo
args: [“–dbpath”,”/data/db”]
livenessProbe:
exec:
command:
– mongo
– –disableImplicitSessions
– –eval
– “db.adminCommand(‘ping’)”
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
readinessProbe:
exec:
command:
– mongo
– –disableImplicitSessions
– –eval
– “db.adminCommand(‘ping’)”
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
env:
– name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-creds
key: username
– name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-creds
key: password
volumeMounts:
– name: “mongo-data-dir”
mountPath: “/data/db”
volumes:
– name: “mongo-data-dir”
persistentVolumeClaim:
claimName: “pvc”
Create usage.
kubectl apply -f mongodb-deployment.yaml
YAML Application MongoDB has many features such as env vars from secrets, probes, etc. Let’s dig deeper into what each part does.
How to Install and Run MongoDB on Kubernetes?
MongoDB is known as a document-oriented database server. A New York-based organization called 10 gen was building a platform as a service similar to window azure, and then developed MongoDB as a PAAS (Platform As A Service) in 2007 and later released it as an open source database. server in 2009 and then the company gained popularity as MongoDB Inc where the word Mongo is derived from Humongous. In simpler terms, we can define it as an open-source database server product that is used to store documents. Here, each component needed to use MongoDB in Kubernetes is described, also how to make the collection accessible outside of Kubernetes. Also how to perform basic tasks within MongoDB. As a beginner, creating individual sections while understanding the steps involved is a great way to learn about Kubernetes and MongoDB.