在k8s 中部署有状态服务MongoDB高可用集群详解(附带镜像)
apiVersion: v1
kind: Service
metadata:
name: mongo-replset-svc
spec:
ports:
- port: 27017
clusterIP: None
selector:
app: mongo
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: mongo-pdb
spec:
selector:
matchLabels:
app: mongo
maxUnavailable: 1
---
apiVersion: v1
kind: Service
metadata:
name: mongo-arbiter-svc
spec:
ports:
- port: 27017
clusterIP: None
selector:
app: mongo
role: arbiter
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
spec:
selector:
matchLabels:
app: mongo
serviceName: "mongo-replset-svc"
replicas: 5
updateStrategy:
type: RollingUpdate
podManagementPolicy: OrderedReady
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: mongo:4.2
command:
- mongod
- "--replSet"
- rs0
- "--bind_ip"
- "0.0.0.0"
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
mongo.conf: |
rs0:
members:
0:
host: mongo-0.mongo-replset-svc.default.svc.cluster.local:27017
1:
host: mongo-1.mongo-replset-svc.default.svc.cluster.local:27017
2:
host: mongo-2.mongo-replset-svc.default.svc.cluster.local:27017
3:
host: mongo-3.mongo-replset-svc.default.svc.cluster.local:27017
4:
host: mongo-4.mongo-replset-svc.default.svc.cluster.local:27017
set
评论已关闭