added conf files for k8s
This commit is contained in:
171
cluster2/deployment-mongo-rs.yaml
Normal file
171
cluster2/deployment-mongo-rs.yaml
Normal file
@@ -0,0 +1,171 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mongo-rs1
|
||||
namespace: cluster2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo-rs1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo-rs1
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:7
|
||||
command: ["mongod", "--replSet", "rs0", "--bind_ip_all"]
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data/db
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo-rs1-data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo-rs1
|
||||
namespace: cluster2
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo-rs1
|
||||
ports:
|
||||
- name: mongo
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mongo-rs2
|
||||
namespace: cluster2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo-rs2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo-rs2
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:7
|
||||
command: ["mongod", "--replSet", "rs0", "--bind_ip_all"]
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data/db
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo-rs2-data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo-rs2
|
||||
namespace: cluster2
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo-rs2
|
||||
ports:
|
||||
- name: mongo
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mongo-rs3
|
||||
namespace: cluster2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo-rs3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo-rs3
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:7
|
||||
command: ["mongod", "--replSet", "rs0", "--bind_ip_all"]
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data/db
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo-rs3-data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo-rs3
|
||||
namespace: cluster2
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo-rs3
|
||||
ports:
|
||||
- name: mongo
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: mongo-rs-init
|
||||
namespace: cluster2
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: OnFailure
|
||||
containers:
|
||||
- name: mongo-rs-init
|
||||
image: mongo:7
|
||||
command:
|
||||
- bash
|
||||
- -c
|
||||
- |
|
||||
echo "Waiting for MongoDB replica set members..."
|
||||
sleep 30
|
||||
until mongosh --host mongo-rs1:27017 --eval "db.adminCommand({ping:1})" --quiet; do
|
||||
echo "Waiting for mongo-rs1..."
|
||||
sleep 5
|
||||
done
|
||||
until mongosh --host mongo-rs2:27017 --eval "db.adminCommand({ping:1})" --quiet; do
|
||||
echo "Waiting for mongo-rs2..."
|
||||
sleep 5
|
||||
done
|
||||
until mongosh --host mongo-rs3:27017 --eval "db.adminCommand({ping:1})" --quiet; do
|
||||
echo "Waiting for mongo-rs3..."
|
||||
sleep 5
|
||||
done
|
||||
echo "All nodes ready, initializing replica set..."
|
||||
mongosh --host mongo-rs1:27017 --eval 'rs.initiate({
|
||||
_id: "rs0",
|
||||
members: [
|
||||
{ _id: 0, host: "mongo-rs1:27017" },
|
||||
{ _id: 1, host: "mongo-rs2:27017" },
|
||||
{ _id: 2, host: "mongo-rs3:27017" }
|
||||
]
|
||||
})'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user