unable to automate the step of creating replicaset in mongodb through kubernetes deployment file

5/13/2020

I have copied install_replicaSet.sh inside the mongo docker image. this script needs to run when all the replica sets have come up.

  1. added entrypoint in dockerfile: This is not working.
FROM mongo:4.2.6

COPY install_replicaSet.sh /install_replicaSet.sh
RUN chmod +x /install_replicaSet.sh
ENTRYPOINT ["/bin/bash/","/install_replicaSet.sh"]
  1. added in deployment file: This is also not working.
kind: StatefulSet
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
      app: mongo
  serviceName: "mongo"
  replicas: 3
  template:
    metadata:
      labels:
        app: mongo
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongo
       # image: mongo
        image: xxxxxxx/mongo:v4.2.6
        command:
        - mongod
        - "--bind_ip_all"
        - "--replSet"
        - rs0
        - ["/bin/bash/", "-c", "/install_replicaSet.sh"]
        ports:
        - containerPort: 27107
        volumeMounts:
        - name: mongo-volume
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-volume
    spec:
      storageClassName: ebs
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

install_replicaSet.sh

#!/bin/bash
cfg="{
    _id: 'rs0',
    members: [
        {_id: 1, host: 'mongo-0.mongo:27017'},
        {_id: 2, host: 'mongo-1.mongo:27017'},
        {_id: 3, host: 'mongo-2.mongo:27017'}
    ]
}"

mongo mongo-0.mongo:27017 --eval "JSON.stringify(db.adminCommand({'replSetInitiate' : $cfg}))"
-- Vageesh S M
kubernetes
mongodb

0 Answers