124 lines
3.2 KiB
YAML
124 lines
3.2 KiB
YAML
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: mongo-rs0
|
|
spec:
|
|
replicas: 3
|
|
serviceName: mongo-rs0
|
|
selector:
|
|
matchLabels:
|
|
app: mongo-rs0
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: mongo-rs0
|
|
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
|
|
sysctl -w vm.max_map_count=262144
|
|
echo never > /sys/kernel/mm/transparent_hugepage/enabled
|
|
echo never > /sys/kernel/mm/transparent_hugepage/defrag
|
|
cp /etc/keyfile.0 /etc/mongodb/keyfile.0
|
|
chown 999 /etc/mongodb/keyfile.0
|
|
chmod 400 /etc/mongodb/keyfile.0
|
|
securityContext:
|
|
privileged: true
|
|
volumeMounts:
|
|
- name: mongo-conf
|
|
mountPath: /etc/mongodb
|
|
- name: mongo-keyfile
|
|
mountPath: /etc/keyfile.0
|
|
subPath: keyfile.0
|
|
readOnly: true
|
|
containers:
|
|
- name: mongo
|
|
image: mongo:6.0
|
|
imagePullPolicy: IfNotPresent
|
|
args:
|
|
- "--bind_ip_all"
|
|
- "--replSet=bfs-mongo-rs0"
|
|
- "--keyFile=/etc/mongodb/keyfile.0"
|
|
env:
|
|
- name: MONGO_INITDB_ROOT_USERNAME
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: mongo
|
|
key: initdb_root_username
|
|
- name: MONGO_INITDB_ROOT_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: mongo
|
|
key: initdb_root_password
|
|
ports:
|
|
- containerPort: 27017
|
|
volumeMounts:
|
|
- name: mongo-data
|
|
mountPath: /data/db
|
|
- name: mongo-conf
|
|
mountPath: /etc/mongodb
|
|
volumes:
|
|
- name: mongo-data
|
|
hostPath:
|
|
path: /data/mongodb/rs0
|
|
- name: mongo-conf
|
|
emptyDir:
|
|
sizeLimit: 10Mi
|
|
- name: mongo-keyfile
|
|
configMap:
|
|
name: mongo-keyfile
|
|
items:
|
|
- key: keyFile
|
|
path: keyfile.0
|
|
affinity:
|
|
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"
|
|
|
|
# function: when primary node changes, update mongo-rs0 to primary;
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: mongo-rs0-0
|
|
spec:
|
|
ports:
|
|
- name: mongo
|
|
protocol: TCP
|
|
port: 27017
|
|
targetPort: 27017
|
|
type: ClusterIP
|
|
selector:
|
|
app: mongo-rs0
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: mongo-rs0
|
|
spec:
|
|
ports:
|
|
- name: mongo
|
|
protocol: TCP
|
|
port: 27017
|
|
targetPort: 27017
|
|
type: ClusterIP
|
|
selector:
|
|
app: mongo-rs0 |