Skip to content

Commit 855aaf3

Browse files
Julien-Benjwilliams-mongo
authored andcommitted
Add Multi Cluster Sharded Cluster examples files - shard overrides (#2047)
1 parent e8b685f commit 855aaf3

File tree

5 files changed

+423
-0
lines changed

5 files changed

+423
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
apiVersion: mongodb.com/v1
2+
kind: MongoDB
3+
metadata:
4+
name: sc
5+
spec:
6+
topology: MultiCluster
7+
type: ShardedCluster
8+
# this deployment will have 3 shards
9+
shardCount: 3
10+
# you cannot specify mongodsPerShardCount, configServerCount and mongosCount in MultiCluster topology
11+
version: 8.0.3
12+
opsManager:
13+
configMapRef:
14+
name: my-project
15+
credentials: my-credentials
16+
persistent: true
17+
18+
shardPodSpec: # applies to all shards on all clusters
19+
persistence:
20+
single:
21+
storage: 10G # all pods for all shards on all clusters will use that storage size in their PersistentVolumeClaim unless overridden in spec.shard.clusterSpecList or spec.shardOverrides.
22+
23+
configSrvPodSpec: # applies to all config server nodes in all clusters
24+
persistence:
25+
multiple:
26+
data:
27+
storage: 2G
28+
journal:
29+
storage: 1G
30+
logs:
31+
storage: 1G
32+
33+
shard: # consider this section as a default configuration for ALL shards
34+
clusterSpecList:
35+
- clusterName: kind-e2e-cluster-1
36+
members: 1 # each shard will have only one mongod process deployed in this cluster
37+
memberConfig:
38+
- votes: 1
39+
priority: "20" # we increase the priority to have primary in this cluster
40+
- clusterName: kind-e2e-cluster-2
41+
members: 1 # one member in this cluster, no votes and priority defined means it'll get the default values votes=1, priority="1"
42+
- clusterName: kind-e2e-cluster-3
43+
members: 1 # one member in this cluster
44+
45+
shardOverrides: # here you specify customizations for specific shards
46+
- shardNames: # here you specify to which shard names the following configuration will apply
47+
- sc-0
48+
clusterSpecList:
49+
- clusterName: kind-e2e-cluster-1
50+
# all fields here are optional
51+
members: 2 # shard "sc-0" will have two members instead of one, which was defined as the default for all shards in spec.shard.clusterSpecList[0].members
52+
memberConfig:
53+
- votes: 1
54+
priority: "1" # shard "sc-0" should not have primary in this cluster like every other shard
55+
- votes: 1
56+
priority: "1"
57+
- clusterName: kind-e2e-cluster-2
58+
members: 2 # shard "sc-0" will have two members instead of one
59+
memberConfig:
60+
- votes: 1
61+
priority: "20" # both processes of shard "sc-0" in this cluster will have the same likelihood to become a primary member
62+
- votes: 1
63+
priority: "20"
64+
- clusterName: kind-e2e-cluster-3 # We need to specify the list of all clusters on which this shard will be deployed.
65+
# If the clusterName element is omitted here, it will be considered as an override for this shard, so that the operator shouldn't deploy any member to it.
66+
# No fields are mandatory in here, though. In case a field is not set, it's not overridden and the default value is taken from a top level spec.shard settings.
67+
68+
configSrv:
69+
clusterSpecList: # the same configuration fields are available as in spec.shard.clusterSpecList.
70+
- clusterName: kind-e2e-cluster-1
71+
members: 1
72+
- clusterName: kind-e2e-cluster-2
73+
members: 1
74+
- clusterName: kind-e2e-cluster-3
75+
members: 1
76+
77+
mongos:
78+
clusterSpecList: # the same configuration fields are available as in spec.shard.clusterSpecList apart from storage and replica-set related fields.
79+
- clusterName: kind-e2e-cluster-1
80+
members: 1
81+
- clusterName: kind-e2e-cluster-2
82+
members: 1
83+
- clusterName: kind-e2e-cluster-3
84+
members: 1
85+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This file is a minimal example of how to define global custom pod templates and persistence settings
2+
# and how to override them in clusterSpecList for Config Servers
3+
# It is similar to how we define them for shards, except that there is no shardOverrides
4+
# Note that mongos settings work in the same way
5+
apiVersion: mongodb.com/v1
6+
kind: MongoDB
7+
metadata:
8+
name: pod-template-config-servers
9+
namespace: mongodb-test
10+
spec:
11+
shardCount: 3
12+
topology: MultiCluster
13+
type: ShardedCluster
14+
version: 8.0.3
15+
opsManager:
16+
configMapRef:
17+
name: my-project
18+
credentials: my-credentials
19+
persistent: true
20+
21+
configSrvPodSpec: # applicable to all members in all clusters
22+
persistence:
23+
single:
24+
storage: "5G"
25+
podTemplate:
26+
spec:
27+
containers:
28+
- name: mongodb-enterprise-database
29+
resources:
30+
requests:
31+
cpu: 0.5
32+
memory: 1.0G
33+
limits:
34+
cpu: 1.0
35+
memory: 2.0G
36+
configSrv:
37+
clusterSpecList:
38+
- clusterName: kind-e2e-cluster-1
39+
members: 2
40+
# The below statefulset override is applicable only to pods in kind-e2e-cluster-1
41+
# Specs will be merged, the "request" field defined above will still be applied to containers in this cluster
42+
# However, limits will be replaced with below values, because clusterSpecList.statefulSet.spec.template has a
43+
# higher priority than configSrvPodSpec.podTemplate
44+
statefulSet:
45+
spec:
46+
template:
47+
spec:
48+
containers:
49+
- name: mongodb-enterprise-database
50+
resources:
51+
limits:
52+
cpu: 1.0
53+
memory: 2.5G
54+
# In clusterSpecList.podSpec, only persistence field must be used, the podTemplate field is ignored.
55+
podSpec: # In kind-e2e-cluster-1, we replace the persistence settings defined in configSrvPodSpec
56+
persistence:
57+
multiple:
58+
journal:
59+
storage: "6G"
60+
data:
61+
storage: "7G"
62+
logs:
63+
storage: "6G"
64+
- clusterName: kind-e2e-cluster-2
65+
members: 1
66+
67+
mongos:
68+
clusterSpecList:
69+
- clusterName: kind-e2e-cluster-1
70+
members: 2
71+
- clusterName: kind-e2e-cluster-2
72+
members: 1
73+
74+
shard:
75+
clusterSpecList:
76+
- clusterName: kind-e2e-cluster-1
77+
members: 2
78+
- clusterName: kind-e2e-cluster-2
79+
members: 1
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This file is a minimal example of how to define global custom pod templates and persistence settings
2+
# and how to override them in clusterSpecList
3+
apiVersion: mongodb.com/v1
4+
kind: MongoDB
5+
metadata:
6+
name: pod-template-shards-0
7+
namespace: mongodb-test
8+
spec:
9+
shardCount: 3
10+
topology: MultiCluster
11+
type: ShardedCluster
12+
version: 8.0.3
13+
opsManager:
14+
configMapRef:
15+
name: my-project
16+
credentials: my-credentials
17+
persistent: true
18+
mongos:
19+
clusterSpecList:
20+
- clusterName: kind-e2e-cluster-1
21+
members: 2
22+
- clusterName: kind-e2e-cluster-2
23+
members: 1
24+
configSrv:
25+
clusterSpecList:
26+
- clusterName: kind-e2e-cluster-1
27+
members: 2
28+
- clusterName: kind-e2e-cluster-2
29+
members: 1
30+
31+
shardPodSpec: # applicable to all shards in all clusters
32+
persistence:
33+
single:
34+
storage: "5G"
35+
podTemplate:
36+
spec:
37+
containers:
38+
- name: mongodb-enterprise-database
39+
resources:
40+
requests:
41+
cpu: 0.5
42+
memory: 1.0G
43+
limits:
44+
cpu: 1.0
45+
memory: 2.0G
46+
shard:
47+
clusterSpecList:
48+
- clusterName: kind-e2e-cluster-1
49+
members: 2
50+
# The below statefulset override is applicable only to pods in kind-e2e-cluster-1
51+
# Specs will be merged, the "request" field defined above will still be applied to containers in this cluster
52+
# However, limits will be replaced with below values, because clusterSpecList.statefulSet.spec.template has a
53+
# higher priority than shardPodSpec.podTemplate
54+
statefulSet:
55+
spec:
56+
template:
57+
spec:
58+
containers:
59+
- name: mongodb-enterprise-database
60+
resources:
61+
limits:
62+
cpu: 1.0
63+
memory: 2.5G
64+
# In clusterSpecList.podSpec, only persistence field must be used, the podTemplate field is ignored.
65+
podSpec: # In kind-e2e-cluster-1, we replace the persistence settings defined in shardPodSpec
66+
persistence:
67+
multiple:
68+
journal:
69+
storage: "6G"
70+
data:
71+
storage: "7G"
72+
logs:
73+
storage: "6G"
74+
- clusterName: kind-e2e-cluster-2
75+
members: 1
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# This file is a minimal example of how to define custom pod templates and persistence settings
2+
# at the cluster level, and in shard overrides.
3+
apiVersion: mongodb.com/v1
4+
kind: MongoDB
5+
metadata:
6+
name: pod-template-shards-1
7+
namespace: mongodb-test
8+
spec:
9+
shardCount: 3
10+
topology: MultiCluster
11+
type: ShardedCluster
12+
version: 8.0.3
13+
opsManager:
14+
configMapRef:
15+
name: my-project
16+
credentials: my-credentials
17+
persistent: true
18+
mongos:
19+
clusterSpecList:
20+
- clusterName: kind-e2e-cluster-1
21+
members: 2
22+
- clusterName: kind-e2e-cluster-2
23+
members: 1
24+
configSrv:
25+
clusterSpecList:
26+
- clusterName: kind-e2e-cluster-1
27+
members: 2
28+
- clusterName: kind-e2e-cluster-2
29+
members: 1
30+
31+
shard:
32+
clusterSpecList:
33+
- clusterName: kind-e2e-cluster-1
34+
members: 2
35+
# Statefulset and PodSPec settings below apply to members of all shards in kind-e2e-cluster-1
36+
statefulSet:
37+
spec:
38+
template:
39+
spec:
40+
containers:
41+
- name: mongodb-enterprise-database
42+
resources:
43+
limits:
44+
cpu: 1.0
45+
memory: 2.0G
46+
# In clusterSpecList.podSpec, only persistence field must be used, the podTemplate field is ignored.
47+
podSpec: # In kind-e2e-cluster-1, we define custom persistence settings
48+
persistence:
49+
multiple:
50+
journal:
51+
storage: "5G"
52+
data:
53+
storage: "5G"
54+
logs:
55+
storage: "5G"
56+
- clusterName: kind-e2e-cluster-2
57+
members: 1
58+
59+
shardOverrides:
60+
- shardNames: [ "pod-template-shards-1-2" ] # this override will apply to shard of index 2
61+
# Statefulset settings defined at this level (shardOverrides.statefulSet) apply to members
62+
# of shard 2 in ALL clusters
63+
# This field has higher priority than shard.clusterSpecList.statefulSet, but lower than
64+
# shardOverrides.clusterSpecList.statefulSet
65+
# It has a merge policy, which means that the limits defined above for the mongodb-enterprise-database container
66+
# field still apply to all members in that shard, except if overriden.
67+
statefulSet:
68+
spec:
69+
template:
70+
spec:
71+
containers:
72+
- name: sidecar-shard-2
73+
image: busybox
74+
command: [ "sleep" ]
75+
args: [ "infinity" ]
76+
clusterSpecList:
77+
- clusterName: kind-e2e-cluster-1
78+
members: 2
79+
- clusterName: kind-e2e-cluster-2
80+
members: 1
81+
# The below statefulset override is applicable only to members of shard 2, in cluster 1
82+
# Specs will be merged, the "limits" field defined above will still be applied to containers in this cluster,
83+
# together with the requests field below.
84+
statefulSet:
85+
spec:
86+
template:
87+
spec:
88+
containers:
89+
- name: mongodb-enterprise-database
90+
resources:
91+
requests: # We add a requests field in shard 2, cluster 1
92+
cpu: 0.5
93+
memory: 1.0G
94+
95+
podSpec:
96+
# In shardOverrides.clusterSpecList.podSpec, only persistence field must be used, the podTemplate field is ignored.
97+
persistence: # we assign additional disk resources in shard 2, cluster 1
98+
multiple:
99+
journal:
100+
storage: "6G"
101+
data:
102+
storage: "6G"
103+
logs:
104+
storage: "6G"

0 commit comments

Comments
 (0)