Last active
January 15, 2026 18:39
-
-
Save giraffesyo/b2213d31bcbf3b0d7e04be25f084756d to your computer and use it in GitHub Desktop.
mongo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: mongo | |
| namespace: mongo6 | |
| spec: | |
| clusterIP: None | |
| ports: | |
| - port: 27017 | |
| name: mongodb | |
| selector: | |
| app: mongo | |
| --- | |
| apiVersion: apps/v1 | |
| kind: StatefulSet | |
| metadata: | |
| name: mongo | |
| namespace: mongo6 | |
| spec: | |
| serviceName: mongo | |
| replicas: 3 | |
| selector: | |
| matchLabels: | |
| app: mongo | |
| template: | |
| metadata: | |
| labels: | |
| app: mongo | |
| spec: | |
| terminationGracePeriodSeconds: 30 | |
| initContainers: | |
| - name: fix-permissions | |
| image: ghcr.io/parallelworks/busybox:latest | |
| command: ["sh", "-c", "chown -R 999:999 /data/db"] | |
| securityContext: | |
| runAsUser: 0 | |
| volumeMounts: | |
| - name: mongo-persistent-storage | |
| mountPath: /data/db | |
| containers: | |
| - name: mongo | |
| image: ghcr.io/parallelworks/mongo:6.0 | |
| imagePullPolicy: IfNotPresent | |
| command: | |
| - "mongod" | |
| - "--replSet=rs0" | |
| - "--bind_ip=0.0.0.0" | |
| ports: | |
| - containerPort: 27017 | |
| name: mongodb | |
| volumeMounts: | |
| - name: mongo-persistent-storage | |
| mountPath: /data/db | |
| volumes: | |
| - name: workdir | |
| emptyDir: {} | |
| volumeClaimTemplates: | |
| - metadata: | |
| name: mongo-persistent-storage | |
| spec: | |
| accessModes: [ "ReadWriteOnce" ] | |
| resources: | |
| requests: | |
| storage: 8Gi | |
| --- | |
| apiVersion: batch/v1 | |
| kind: Job | |
| metadata: | |
| name: mongo-init-rs | |
| namespace: mongo6 | |
| spec: | |
| template: | |
| spec: | |
| restartPolicy: Never | |
| containers: | |
| - name: init-rs | |
| image: ghcr.io/parallelworks/mongo:6.0 | |
| command: | |
| - "bash" | |
| - "-c" | |
| - | | |
| echo "Waiting for mongo-0 to be ready..." | |
| until mongosh --host mongo-0.mongo.mongo6.svc.cluster.local:27017 --eval "db.adminCommand('ping')" > /dev/null 2>&1; do | |
| sleep 3 | |
| done | |
| echo "Waiting for mongo-1 to be ready..." | |
| until mongosh --host mongo-1.mongo.mongo6.svc.cluster.local:27017 --eval "db.adminCommand('ping')" > /dev/null 2>&1; do | |
| sleep 3 | |
| done | |
| echo "Waiting for mongo-2 to be ready..." | |
| until mongosh --host mongo-2.mongo.mongo6.svc.cluster.local:27017 --eval "db.adminCommand('ping')" > /dev/null 2>&1; do | |
| sleep 3 | |
| done | |
| echo "All nodes ready. Initializing replica set..." | |
| mongosh --host mongo-0.mongo.mongo6.svc.cluster.local:27017 <<EOF | |
| rs.initiate({ | |
| _id: "rs0", | |
| members: [ | |
| { _id: 0, host: "mongo-0.mongo.mongo6.svc.cluster.local:27017" }, | |
| { _id: 1, host: "mongo-1.mongo.mongo6.svc.cluster.local:27017" }, | |
| { _id: 2, host: "mongo-2.mongo.mongo6.svc.cluster.local:27017" } | |
| ] | |
| }) | |
| EOF | |
| echo "Replica set initialized." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment