-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo-statefulset.yaml
46 lines (46 loc) · 1.5 KB
/
mongo-statefulset.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# For MongoDB, I created a StatefulSet, which differs from a Deployment. In a StatefulSet, pod/container data persists in a single storage location.
# We use AWS EBS to store this data. If a pod restarts or fails, it will be recreated using the data stored in EBS, ensuring no data loss.
# StatefulSets are primarily designed for databases. In the volume mounts section, you can see that I mount `/data/db` to AWS EBS (gp2).
# First, I created a StorageClass, then a VolumeClaim template. You need to apply the StorageClass file (`kind: StorageClass`)
# using the `kubectl apply -f` command before applying the MongoDB StatefulSet.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongodb
labels:
app: mongodb
spec:
serviceName: "mongodb"
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:7.0.12
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: "root"
- name: MONGO_INITDB_ROOT_PASSWORD
value: "example"
- name: MONGO_INITDB_DATABASE
value: Ecommerce
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: aws-ebs-gp2
resources:
requests:
storage: 1Gi