added conf files for k8s
This commit is contained in:
58
cluster2/configmap-init-scripts.yaml
Normal file
58
cluster2/configmap-init-scripts.yaml
Normal file
@@ -0,0 +1,58 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: cluster2-init-scripts
|
||||
namespace: cluster2
|
||||
data:
|
||||
mongo1-init.js: |
|
||||
db = db.getSiblingDB('db1');
|
||||
|
||||
db.documents.insertMany([
|
||||
{ name: "Документ 1 бд 1", value: Math.random() * 100, timestamp: new Date() },
|
||||
{ name: "Документ 2 бд 1", value: Math.random() * 100, timestamp: new Date() }
|
||||
]);
|
||||
|
||||
db = db.getSiblingDB('admin');
|
||||
|
||||
db.createUser({
|
||||
user: "user1",
|
||||
pwd: "user1pass",
|
||||
roles: [{ role: "readWrite", db: "db1" }]
|
||||
});
|
||||
|
||||
db.createUser({
|
||||
user: "user-shared",
|
||||
pwd: "user2pass",
|
||||
roles: [
|
||||
{ role: "readWrite", db: "db1" },
|
||||
{ role: "readWrite", db: "db2" }
|
||||
]
|
||||
});
|
||||
|
||||
mongo2-init.js: |
|
||||
db = db.getSiblingDB('db2');
|
||||
|
||||
db.documents.insertMany([
|
||||
{ name: "Документ A бд 2", value: Math.random() * 100, timestamp: new Date() },
|
||||
{ name: "Документ B бд 2", value: Math.random() * 100, timestamp: new Date() }
|
||||
]);
|
||||
|
||||
db = db.getSiblingDB('admin');
|
||||
|
||||
db.createUser({
|
||||
user: "user2",
|
||||
pwd: "user1pass",
|
||||
roles: [{ role: "readWrite", db: "db2" }]
|
||||
});
|
||||
|
||||
db.createUser({
|
||||
user: "user-shared",
|
||||
pwd: "user2pass",
|
||||
roles: [
|
||||
{ role: "readWrite", db: "db1" },
|
||||
{ role: "readWrite", db: "db2" }
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
|
||||
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" }
|
||||
]
|
||||
})'
|
||||
|
||||
|
||||
|
||||
61
cluster2/deployment-mongo1.yaml
Normal file
61
cluster2/deployment-mongo1.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mongo1
|
||||
namespace: cluster2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo1
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:7
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
env:
|
||||
- name: MONGO_INITDB_ROOT_USERNAME
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cluster2-mongo-secret
|
||||
key: MONGO_INITDB_ROOT_USERNAME
|
||||
- name: MONGO_INITDB_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cluster2-mongo-secret
|
||||
key: MONGO_INITDB_ROOT_PASSWORD
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data/db
|
||||
- name: init-scripts
|
||||
mountPath: /docker-entrypoint-initdb.d/init.js
|
||||
subPath: mongo1-init.js
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo1-data
|
||||
- name: init-scripts
|
||||
configMap:
|
||||
name: cluster2-init-scripts
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo1
|
||||
namespace: cluster2
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo1
|
||||
ports:
|
||||
- name: mongo
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
|
||||
|
||||
|
||||
61
cluster2/deployment-mongo2.yaml
Normal file
61
cluster2/deployment-mongo2.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mongo2
|
||||
namespace: cluster2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo2
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:7
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
env:
|
||||
- name: MONGO_INITDB_ROOT_USERNAME
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cluster2-mongo-secret
|
||||
key: MONGO_INITDB_ROOT_USERNAME
|
||||
- name: MONGO_INITDB_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cluster2-mongo-secret
|
||||
key: MONGO_INITDB_ROOT_PASSWORD
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data/db
|
||||
- name: init-scripts
|
||||
mountPath: /docker-entrypoint-initdb.d/init.js
|
||||
subPath: mongo2-init.js
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo2-data
|
||||
- name: init-scripts
|
||||
configMap:
|
||||
name: cluster2-init-scripts
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo2
|
||||
namespace: cluster2
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo2
|
||||
ports:
|
||||
- name: mongo
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
|
||||
|
||||
|
||||
6
cluster2/namespace.yaml
Normal file
6
cluster2/namespace.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: cluster2
|
||||
|
||||
|
||||
62
cluster2/pvc-mongo.yaml
Normal file
62
cluster2/pvc-mongo.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo1-data
|
||||
namespace: cluster2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo2-data
|
||||
namespace: cluster2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo-rs1-data
|
||||
namespace: cluster2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo-rs2-data
|
||||
namespace: cluster2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo-rs3-data
|
||||
namespace: cluster2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
|
||||
|
||||
|
||||
12
cluster2/secrets-mongo.yaml
Normal file
12
cluster2/secrets-mongo.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: cluster2-mongo-secret
|
||||
namespace: cluster2
|
||||
type: Opaque
|
||||
stringData:
|
||||
MONGO_INITDB_ROOT_USERNAME: admin
|
||||
MONGO_INITDB_ROOT_PASSWORD: adminpass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user