2024-04-19 11:46:33 +08:00
|
|
|
apiVersion: apps/v1
|
|
|
|
kind: StatefulSet
|
|
|
|
metadata:
|
|
|
|
name: mongo
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
serviceName: mongo
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
|
|
|
app: mongo
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels:
|
|
|
|
app: mongo
|
|
|
|
spec:
|
|
|
|
initContainers:
|
|
|
|
- name: init
|
|
|
|
image: busybox
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
command:
|
|
|
|
- sh
|
|
|
|
- -c
|
|
|
|
- |
|
|
|
|
sysctl -w net.ipv4.tcp_keepalive_time=300
|
|
|
|
sysctl -w net.ipv4.tcp_keepalive_intvl=10
|
|
|
|
sysctl -w net.ipv4.tcp_keepalive_probes=3
|
2024-04-19 16:55:50 +08:00
|
|
|
# chown 999 /etc/mongodb/keyfile.key
|
|
|
|
# chmod 400 /etc/mongodb/keyfile.key
|
2024-04-19 11:46:33 +08:00
|
|
|
securityContext:
|
|
|
|
privileged: true
|
2024-04-19 16:55:50 +08:00
|
|
|
# volumeMounts:
|
|
|
|
# - name: mongo-keyfile
|
|
|
|
# mountPath: /etc/mongodb/keyfile.key
|
|
|
|
# subPath: keyfile.key
|
2024-04-19 11:46:33 +08:00
|
|
|
containers:
|
|
|
|
- name: mongo
|
|
|
|
image: mongo:6.0
|
2024-04-19 16:35:41 +08:00
|
|
|
imagePullPolicy: IfNotPresent
|
2024-04-19 15:20:49 +08:00
|
|
|
args:
|
2024-04-19 16:35:41 +08:00
|
|
|
- "--bind_ip_all"
|
2024-04-19 15:41:03 +08:00
|
|
|
- "--replSet=bfs-mongo-rs0"
|
2024-04-19 16:35:41 +08:00
|
|
|
- "--keyFile=/etc/mongodb/keyfile.key"
|
2024-04-19 11:46:33 +08:00
|
|
|
ports:
|
|
|
|
- containerPort: 27017
|
|
|
|
volumeMounts:
|
|
|
|
- name: mongo-data
|
|
|
|
mountPath: /data/db
|
2024-04-19 16:35:41 +08:00
|
|
|
- name: mongo-keyfile
|
|
|
|
mountPath: /etc/mongodb/keyfile.key
|
|
|
|
subPath: keyfile.key
|
2024-04-19 11:46:33 +08:00
|
|
|
volumes:
|
|
|
|
- name: mongo-data
|
|
|
|
hostPath:
|
|
|
|
path: /data/mongodb/rs0
|
2024-04-19 16:35:41 +08:00
|
|
|
- name: mongo-keyfile
|
|
|
|
configMap:
|
|
|
|
name: mongo-keyfile
|
|
|
|
items:
|
|
|
|
- key: keyFile
|
|
|
|
path: keyfile.key
|
2024-04-19 15:16:15 +08:00
|
|
|
affinity:
|
2024-04-19 11:46:33 +08:00
|
|
|
nodeAffinity:
|
|
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
|
|
nodeSelectorTerms:
|
|
|
|
- matchExpressions:
|
|
|
|
- key: "app.kubernetes.io/component"
|
|
|
|
operator: In
|
|
|
|
values:
|
|
|
|
- mongo
|
|
|
|
tolerations:
|
|
|
|
- key: "app.kubernetes.io/component"
|
|
|
|
operator: "Equal"
|
|
|
|
value: "mongo"
|
|
|
|
effect: "NoSchedule"
|
|
|
|
|
|
|
|
---
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
|
|
|
metadata:
|
|
|
|
name: mongo
|
|
|
|
spec:
|
|
|
|
ports:
|
|
|
|
- name: mongo
|
|
|
|
protocol: TCP
|
|
|
|
port: 27017
|
|
|
|
targetPort: 27017
|
2024-04-19 15:17:14 +08:00
|
|
|
type: ClusterIP
|
|
|
|
selector:
|
|
|
|
app: mongo
|
2024-04-19 11:46:33 +08:00
|
|
|
|