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.

Similar Reads

MongoDB Cluster Kubernetes Manifests

All Kubernetes Mongodb YAML used in this guide is hosted on GitHub. Clone the repository for reference and use....

Create MongoDB Secrets

Secrets in Kubernetes are objects used to provide vessels with sensitive information. They are similar to ConfigMaps with the difference that data is stored in a coded format. For the security of our MongoDB model, it is wise to limit access to a website with a password. We will use secrets to mount the desired passwords into containers. Save the following manifest:...

Create MongoDB Persistent Volume

We need volumes to keep track of data. This way, even if our pod goes down – the data is not lost. For Kubernetes, there are two essentials for creating volumes....

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....

Connecting to MongoDB from Outside

Let’s try and access the database without collection. To do so, we need to build another Kubernetes Service. The services at Kubernetes are things that pods use to communicate. ClusterIP type services are often used for inter-pod communication. For starters, it is important to know that there are two types of ClusterIP services:...