k8s部署mongodb分⽚集
配置节点label
1apiVersion: v1
2kind: Node
3metadata:
4 name: host1
5 labels:
6 mongodb: "mongo-0"
7---
8apiVersion: v1
9kind: Node
10metadata:
11 name: host2
12 labels:
13 mongodb: "mongo-1"
14---
15apiVersion: v1
16kind: Node
17metadata:
18 name: host3
19 labels:
20 mongodb: "mongo-2"
配置keyfile和docker私有仓库
1apiVersion: v1
2data:
3 .dockerconfigjson: eyJhdXRocyI6eyIxOTIuMTY4LjEzLjUiOnsidXNlcm5hbWUiOiJ6eWNsb3VkIiwicGFzc3dvcmQiOiJaaGl5dWFuQ2xvdWQxMjM0ISIsImF1dG
4kind: Secret
5metadata:
6 name: zlgdocker
7 namespace: zlg-zws
8type: kubernetes.io/dockerconfigjson
9---
10apiVersion: v1
11data:
12 keyfile.key: ZGNDTWd4T3B3dGdsNlpFeExialZxajhvMmFENjVwVGtPVFVxTG0vMGJXd1FvMUhUZmtUM0pFSXZSN1pYRk41ZQoyWDI0TTJ1L2xremN0Ujd 13kind: Secret
14metadata:
15 name: zlgmongo-keyfile
16 namespace: zlg-zws
17type: Opaque
config server
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4 name: zlgmongo-config
5 namespace: zlg-zws
6spec:
7 serviceName: zlgmongo-config
8 replicas: 1
9 selector:
10 matchLabels:
11 app: zlgmongo-config
12 template:
13 metadata:
13 metadata:
14 labels:
15 app: zlgmongo-config
16 spec:
17 imagePullSecrets:
18 - name: zlgdocker
19 nodeSelector:
20 mongodb: "mongo-0"
21 containers:
22 - name: zlgmongo-config
23 image: 192.168.13.5/solar/zlgmongo:master
24 imagePullPolicy: Always
25 resources:
26 limits:
27 memory: "128Mi"
28 cpu: "500m"
29 requests:
30 memory: "1Mi"
31 cpu: "1m"
32 env:
33 - name: POD_NAME
34 valueFrom:
35 fieldRef:
36 apiVersion: v1
37 fieldPath: metadata.name
38 ports:
39 - containerPort: 27019
40 volumeMounts:
41 - name: configdb
42 mountPath: /data/configdb
43 subPathExpr: $(POD_NAME)
44 - mountPath: /data/auth/keyfile.key
45 name: keyfile
46 subPath: keyfile.key
47 readOnly: true
48 command:
49 - "mongod"
50 - "--keyFile"
51 - "/data/auth/keyfile.key"
52 - "--configsvr"
53 - "--replSet"
54 - "config"
55 - "--bind_ip_all"
56 volumes:
57 - name: configdb
58 hostPath:
59 path: /dockershare/zlgmongo/data/configdb
60 type: DirectoryOrCreate
61 - name: keyfile
62 secret:
63 secretName: zlgmongo-keyfile
64 defaultMode: 0600
65 items:
66 - key: keyfile.key
67 path: keyfile.key
68---
69apiVersion: v1
70kind: Service
71metadata:
72 name: zlgmongo-config
73 namespace: zlg-zws
74spec:
75 selector:
76 app: zlgmongo-config
77 clusterIP: None
78 ports:
78 ports:
79 - port: 27019
80 targetPort: 27019
81 name: "27019"
shard
配置3个shard分别是zlgmongo-shard-0、zlgmongo-shard-1、zlgmongo-shard-2对应nodeSelector为mongo-0、mongo-1、mongo-2
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4 name: zlgmongo-shard-0
5 namespace: zlg-zws
6spec:
7 serviceName: zlgmongo-shard-0
8 selector:
9 matchLabels:
10 app: zlgmongo-shard-0
11 replicas: 1
12 template:
13 metadata:
14 labels:
15 app: zlgmongo-shard-0
16 spec:
17 imagePullSecrets:
18 - name: zlgdocker
19 nodeSelector:
20 mongodb: "mongo-0"
21 containers:
22 - name: zlgmongo-shard
23 image: 192.168.13.5/solar/zlgmongo:master
24 imagePullPolicy: Always
25 resources:
26 limits:
27 memory: "4Gi"
28 cpu: "4000m"
29 requests:
30 memory: "1Mi"
31 cpu: "10m"
32 env:
33 - name: POD_NAME
34 valueFrom:
35 fieldRef:
36 apiVersion: v1
37 fieldPath: metadata.name
38 ports:
39 - containerPort: 27018
40 volumeMounts:
41 - name: db
42 mountPath: /data/db
43 subPathExpr: $(POD_NAME)
44 - mountPath: /data/auth/keyfile.key
45 name: keyfile
46 subPath: keyfile.key
47 readOnly: true
48 command:
49 - "mongod"
50 - "--wiredTigerCacheSizeGB"
51 - "3"
52 - "--keyFile"
53 - "/data/auth/keyfile.key"
54 - "--shardsvr"
55 - "--replSet"
56 - "$(POD_NAME)"
57 - "--bind_ip_all"
58 volumes:
59 - name: db
60 hostPath:
61 path: /dockershare/zlgmongo/data/db
62 type: DirectoryOrCreate
63 - name: keyfile
64 secret:
65 secretName: zlgmongo-keyfile
66 defaultMode: 0600
67 items:
68 - key: keyfile.key
69 path: keyfile.key
70---
71apiVersion: v1
72kind: Service
73metadata:
74 name: zlgmongo-shard-0
75 namespace: zlg-zws
76spec:
77 selector:
78 app: zlgmongo-shard-0
79 clusterIP: None
80 ports:
81 - port: 27018
82 targetPort: 27018
83 name: "27018"
mongos
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: zlgmongo
5 namespace: zlg-zws
6spec:
7 selector:
8 matchLabels:
9 app: zlgmongo
10 template:
11 metadata:
12 labels:
13 app: zlgmongo
14 spec:
15 imagePullSecrets:
16 - name: zlgdocker
17 affinity:
18 podAntiAffinity:
19 requiredDuringSchedulingIgnoredDuringExecution:
20 - topologyKey: "kubernetes.io/hostname"
21 labelSelector:
22 matchLabels:
23 app: zlgmongo
24 containers:
25 - name: zlgmongo
26 image: 192.168.13.5/solar/zlgmongo:master
27 imagePullPolicy: Always
28 resources:
29 limits:
30 memory: "2Gi"
31 cpu: "4000m"
32 requests:
32 requests:
33 memory: "64Mi"
34 cpu: "10m"
35 env:
36 - name: DATADIR
37 valueFrom:
38 configMapKeyRef:
39 name: zlgconfigmap
40 key: datadir
41 - name: SHAREDIR
42 valueFrom:
43 configMapKeyRef:
44 name: zlgconfigmap
45 key: sharedir
46 - name: CONFD_PORT
47 valueFrom:
48 configMapKeyRef:
49 name: zlgconfigmap
50 key: confd-port
51 - name: CONFD_NAMESPACE
52 valueFrom:
53 configMapKeyRef:
54 name: zlgconfigmap
55 key: confd-namespace
56 - name: CONFD_TOKEN
57 valueFrom:
58 configMapKeyRef:
59 name: zlgconfigmap
60 key: confd-token
61 - name: DEBUG
62 valueFrom:
63 configMapKeyRef:
64 name: zlgconfigmap
65 key: debug
66 ports:
67 - containerPort: 27017
68 volumeMounts:
69 - mountPath: /data/auth/keyfile.key
70 name: keyfile
71 subPath: keyfile.key
72 readOnly: true
73 command:
74 - "mongos"
75 - "--keyFile"
76 - "/data/auth/keyfile.key"
77 - "--configdb"
78 - "config/zlgmongo-config-0.zlgmongo-config.zlg-zws.svc.cluster.local:27019"
79 - "--bind_ip_all"
80 volumes:
81 - name: keyfile
82 secret:
83 secretName: zlgmongo-keyfile
84 defaultMode: 0600
85 items:
86 - key: keyfile.key
87 path: keyfile.key
88---
nodeselector89apiVersion: v1
90kind: Service
91metadata:
92 name: zlgmongo
93 namespace: zlg-zws
94spec:
95 selector:
96 app: zlgmongo
97 ports:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论