-
Notifications
You must be signed in to change notification settings - Fork 474
/
mongo.deployment.yml
123 lines (115 loc) · 2.96 KB
/
mongo.deployment.yml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: mongo-secrets-env
name: mongo-secrets-env
data:
MONGODB_DBNAME: codeWithDan
MONGO_INITDB_ROOT_USERNAME: admin
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
# The reclaim policy applies to the persistent volumes not the storage class itself.
# pvs and pvcs that are created using that storage class will inherit the reclaim policy set here.
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
---
# Note: While a local storage PV works, going with a more durable solution (NFS, cloud option, etc.) is recommended
# Adding this for demo purposes to run on Docker Desktop Kubernetes since it only supports a single Node
# https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 1Gi
# volumeMode block feature gate enabled by default with 1.13+
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
# StorageClass has a reclaim policy default so it'll be "inherited" by the PV
# persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /tmp/data/db
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- docker-desktop
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: mongo
name: mongo
spec:
serviceName: mongo
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
volumes:
- name: mongo-volume
persistentVolumeClaim:
claimName: mongo-pvc
# Example only - environment vars actually used here
- name: secrets
secret:
secretName: db-passwords
containers:
- env:
- name: MONGODB_DBNAME
valueFrom:
configMapKeyRef:
key: MONGODB_DBNAME
name: mongo-secrets-env
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
configMapKeyRef:
name: mongo-secrets-env
key: MONGO_INITDB_ROOT_USERNAME
# Pull password from secrets
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: db-passwords
key: db-password
image: mongo
name: mongo
ports:
- containerPort: 27017
resources: {}
volumeMounts:
- name: mongo-volume
mountPath: /data/db
# Example only - environment vars actually used here
- name: secrets
mountPath: /etc/db-passwords
readOnly: true