Skip to content

Commit 15446f7

Browse files
committed
Updated snippets
1 parent 638ba6b commit 15446f7

File tree

7 files changed

+219
-93
lines changed

7 files changed

+219
-93
lines changed

api/v1/search/mongodbsearch_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
const (
1919
MongotDefaultPort = 27027
2020
MongotDefaultMetricsPort = 9946
21-
MongotDefautHealthCheckPort = 8080
21+
MongotDefautHealthCheckPort = 8080
2222
MongotDefaultSyncSourceUsername = "search-sync-source"
2323
)
2424

@@ -27,16 +27,23 @@ func init() {
2727
}
2828

2929
type MongoDBSearchSpec struct {
30+
// Optional version of MongoDB Search component (mongot). If not set, then the operator will set the most appropriate version of MongoDB Search.
3031
// +optional
3132
Version string `json:"version"`
33+
// MongoDB database connection details from which MongoDB Search will synchronize data to build indexes.
3234
// +optional
3335
Source *MongoDBSource `json:"source"`
36+
// StatefulSetSpec which the operator will apply to the MongoDB Search StatefulSet at the end of the reconcile loop. Use to provide necessary customizations,
37+
// which aren't exposed as fields in the MongoDBSearch.spec.
3438
// +optional
3539
StatefulSetConfiguration *common.StatefulSetConfiguration `json:"statefulSet,omitempty"`
40+
// Configure MongoDB Search's persistent volume. If not defined, the operator will request 10GB of storage.
3641
// +optional
3742
Persistence *common.Persistence `json:"persistence,omitempty"`
43+
// Configure resource requests and limits for the MongoDB Search pods.
3844
// +optional
3945
ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
46+
// Configure security settings of the MongoDB Search server that MongoDB database is connecting to when performing search queries.
4047
// +optional
4148
Security Security `json:"security"`
4249
}

docs/community-search/quick-start/README.md

Lines changed: 89 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This guide provides instructions for deploying MongoDB Community Edition along w
66

77
Before you begin, ensure you have the following tools and configurations in place:
88

9-
- **Kubernetes cluster**: A running Kubernetes cluster (e.g., Minikube, Kind, GKE, EKS, AKS).
9+
- **Kubernetes cluster**: A running Kubernetes cluster (e.g., Minikube, Kind, GKE, EKS, AKS) with kubeconfig available locally.
1010
- **kubectl**: The Kubernetes command-line tool, configured to communicate with your cluster.
1111
- **Helm**: The package manager for Kubernetes, used here to install the MongoDB Kubernetes Operator.
1212
- **Bash 5.1+**: All shell commands in this guide are intended to be run in Bash. Scripts in this guide are automatically tested on Linux with Bash 5.1.
@@ -27,15 +27,22 @@ Download or copy the content of `env_variables.sh`:
2727
# set it to the context name of the k8s cluster
2828
export K8S_CLUSTER_0_CONTEXT_NAME="<local cluster context>"
2929

30-
# At the private preview stage the community search image is accessible only from a private repository.
31-
# Please contact MongoDB Support to get access.
32-
export PRIVATE_PREVIEW_IMAGE_PULLSECRET="<.dockerconfigjson>"
33-
3430
# the following namespace will be created if not exists
3531
export MDB_NAMESPACE="mongodb"
3632

33+
# minimum required MongoDB version for running MongoDB Search is 8.0.10
34+
export MDB_VERSION="8.0.10"
35+
36+
# root admin user for convenience, not used here at all in this guide
3737
export MDB_ADMIN_USER_PASSWORD="admin-user-password-CHANGE-ME"
38+
<<<<<<< Updated upstream
39+
# regular user performing restore and search queries on sample mflix database
40+
export MDB_USER_PASSWORD="mdb-user-password-CHANGE-ME"
41+
# user for MongoDB Search to connect to the replica set to synchronise data from
42+
export MDB_SEARCH_SYNC_USER_PASSWORD="search-sync-user-password-CHANGE-ME"
43+
=======
3844
export MDB_SEARCH_SYNC_USER_PASSWORD="search-user-password-CHANGE-ME"
45+
>>>>>>> Stashed changes
3946

4047
export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes"
4148
# comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operator
@@ -67,59 +74,7 @@ helm upgrade --install --debug --kube-context "${K8S_CLUSTER_0_CONTEXT_NAME}" \
6774
--set "${OPERATOR_ADDITIONAL_HELM_VALUES:-"dummy=value"}" \
6875
"${OPERATOR_HELM_CHART}"
6976
```
70-
This command installs the operator in the `mongodb` namespace (creating it if it doesn't exist) and names the release `community-operator`.
71-
72-
### 4. Configure Pull Secret for MongoDB Community Search
73-
74-
To use MongoDB Search, your Kubernetes cluster needs to pull the necessary container images. This step creates a Kubernetes secret named `community-private-preview-pullsecret`. This secret stores the credentials required to access the image repository for MongoDB Search. The script then patches the `mongodb-kubernetes-database-pods` service account to include this pull secret, allowing pods managed by this service account to pull the required images.
75-
76-
[code_snippets/0200_configure_community_search_pullsecret.sh](code_snippets/0200_configure_community_search_pullsecret.sh)
77-
```shell copy
78-
kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
79-
apiVersion: v1
80-
kind: Secret
81-
metadata:
82-
name: community-private-preview-pullsecret
83-
data:
84-
.dockerconfigjson: "${PRIVATE_PREVIEW_IMAGE_PULLSECRET}"
85-
type: kubernetes.io/dockerconfigjson
86-
EOF
87-
88-
pull_secrets=$(kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" \
89-
get sa mongodb-kubernetes-database-pods -n "${MDB_NAMESPACE}" -o=jsonpath='{.imagePullSecrets[*]}')
90-
91-
if [[ "${pull_secrets}" ]]; then
92-
kubectl patch --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" \
93-
sa mongodb-kubernetes-database-pods \
94-
--type=json -p='[{"op": "add", "path": "/imagePullSecrets/-", "value": {"name": "community-private-preview-pullsecret"}}]'
95-
else
96-
kubectl patch --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" \
97-
sa mongodb-kubernetes-database-pods \
98-
--type=merge -p='{"imagePullSecrets": [{"name": "community-private-preview-pullsecret"}]}'
99-
fi
100-
echo "ServiceAccount mongodb-kubernetes-database-pods has been patched: "
101-
102-
kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -o yaml sa mongodb-kubernetes-database-pods
103-
```
104-
This script creates a `community-private-preview-pullsecret` secret in your Kubernetes namespace and associates it with the service account used for MongoDB pods.
105-
106-
### 5. Verify Pull Secret Configuration
107-
108-
Confirm that the `community-private-preview-pullsecret` has been successfully added to the `mongodb-kubernetes-database-pods` service account. This ensures that Kubernetes can authenticate with the container registry when pulling images for MongoDB Search pods.
109-
110-
[code_snippets/0210_verify_community_search_pullsecret.sh](code_snippets/0210_verify_community_search_pullsecret.sh)
111-
```shell copy
112-
echo "Verifying mongodb-kubernetes-database-pods contains proper pull secret"
113-
if ! kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -o json \
114-
sa mongodb-kubernetes-database-pods -o=jsonpath='{.imagePullSecrets[*]}' | \
115-
grep community-private-preview-pullsecret; then
116-
echo "ERROR: mongodb-kubernetes-database-pods service account doesn't contain necessary pullsecret"
117-
kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -o json \
118-
sa mongodb-kubernetes-database-pods -o=yaml
119-
return 1
120-
fi
121-
```
122-
This command checks the `mongodb-kubernetes-database-pods` service account to confirm the presence of `community-private-preview-pullsecret`.
77+
This command installs the operator in the `mongodb` namespace (creating it if it doesn't exist).
12378

12479
## Creating a MongoDB Community Search Deployment
12580

@@ -132,18 +87,31 @@ MongoDB requires authentication for secure access. This step creates two Kuberne
13287
[code_snippets/0305_create_mongodb_community_user_secrets.sh](code_snippets/0305_create_mongodb_community_user_secrets.sh)
13388
```shell copy
13489
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
135-
create secret generic admin-user-password \
90+
create secret generic mdb-admin-user-password \
13691
--from-literal=password="${MDB_ADMIN_USER_PASSWORD}"
13792

13893
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
94+
<<<<<<< Updated upstream
95+
create secret generic mdbc-rs-search-sync-source-password \
96+
--from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}"
97+
98+
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
99+
create secret generic mdb-user-password \
100+
--from-literal=password="${MDB_USER_PASSWORD}"
101+
102+
=======
139103
create secret generic search-user-password \
140104
--from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}"
105+
>>>>>>> Stashed changes
141106
```
142107
Ensure these secrets are created in the same namespace where you plan to deploy MongoDB.
143108

144109
### 7. Create MongoDB Community Resource
145110

146-
Now, deploy MongoDB Community by creating a `MongoDBCommunity` custom resource named `mdbc-rs`. This resource definition instructs the MongoDB Kubernetes Operator to configure a MongoDB replica set with 3 members, running version 8.0.6. MongoDB Community Search is supported only from MongoDB Community Server version 8.0. It also defines CPU and memory resources for the `mongod` and `mongodb-agent` containers, and sets up two users (`admin-user` and `search-user`) with their respective roles and password secrets. User `search-user` will be used to restore, connect and perform search queries on the `sample_mflix` database.
111+
Now, deploy MongoDB Community by creating a `MongoDBCommunity` custom resource named `mdbc-rs`. This resource definition instructs the MongoDB Kubernetes Operator to configure a MongoDB replica set with 3 members, running version 8.0.10. MongoDB Community Search is supported only from MongoDB Community Server version 8.0.10. It also defines CPU and memory resources for the `mongod` and `mongodb-agent` containers, and sets up three users:
112+
* `mdb-user` - a regular user used to that will perform restore of `sample_mflix` database and execute search queries.
113+
* `search-sync-source` - user that MongoDB Search is using to connect to MongoDB database in order to manage and build indexes. This user uses `searchCoordinator` role, which for MongoDB <8.2 is created automatically by the operator.
114+
* `admin-user` and ``) with their respective roles and password secrets. User `search-user` will be used to restore, connect and perform search queries on the `sample_mflix` database.
147115

148116
[code_snippets/0310_create_mongodb_community_resource.sh](code_snippets/0310_create_mongodb_community_resource.sh)
149117
```yaml copy
@@ -153,7 +121,7 @@ kind: MongoDBCommunity
153121
metadata:
154122
name: mdbc-rs
155123
spec:
156-
version: 8.0.6
124+
version: ${MDB_VERSION}
157125
type: ReplicaSet
158126
members: 3
159127
security:
@@ -162,7 +130,7 @@ spec:
162130
modes:
163131
- SCRAM
164132
agent:
165-
logLevel: INFO
133+
logLevel: DEBUG
166134
statefulSet:
167135
spec:
168136
template:
@@ -171,36 +139,51 @@ spec:
171139
- name: mongod
172140
resources:
173141
limits:
174-
cpu: "3"
175-
memory: 5Gi
176-
requests:
177142
cpu: "2"
178-
memory: 5Gi
143+
memory: 2Gi
144+
requests:
145+
cpu: "1"
146+
memory: 1Gi
179147
- name: mongodb-agent
180148
resources:
181149
limits:
182-
cpu: "2"
183-
memory: 5Gi
184-
requests:
185150
cpu: "1"
186-
memory: 5Gi
151+
memory: 2Gi
152+
requests:
153+
cpu: "0.5"
154+
memory: 1Gi
187155
users:
188-
- name: admin-user
189-
passwordSecretRef:
190-
name: admin-user-password
156+
# admin user with root role
157+
- name: mdb-admin
158+
db: admin
159+
passwordSecretRef: # a reference to the secret containing user password
160+
name: mdb-admin-user-password
161+
scramCredentialsSecretName: mdb-admin-user
162+
roles:
163+
- name: root
164+
db: admin
165+
# user performing search queries
166+
- name: mdb-user
167+
db: admin
168+
passwordSecretRef: # a reference to the secret containing user password
169+
name: mdb-user-password
170+
scramCredentialsSecretName: mdb-user-scram
191171
roles:
192-
- db: admin
193-
name: clusterAdmin
194-
- db: admin
195-
name: userAdminAnyDatabase
196-
scramCredentialsSecretName: admin-user
197-
- name: search-user
198-
passwordSecretRef:
199-
name: search-user-password
172+
- name: restore
173+
db: sample_mflix
174+
- name: readWrite
175+
db: sample_mflix
176+
# user used by MongoDB Search to connect to MongoDB database to synchronize data from
177+
# For MongoDB <8.2, the operator will be creating the searchCoordinator custom role automatically
178+
# From MongoDB 8.2, searchCoordinator role will be a built-in role.
179+
- name: search-sync-source
180+
db: admin
181+
passwordSecretRef: # a reference to the secret that will be used to generate the user's password
182+
name: mdbc-rs-search-sync-source-password
183+
scramCredentialsSecretName: mdbc-rs-search-sync-source
200184
roles:
201-
- db: sample_mflix
202-
name: dbOwner
203-
scramCredentialsSecretName: search-user
185+
- name: searchCoordinator
186+
db: admin
204187
EOF
205188
```
206189

@@ -222,9 +205,8 @@ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
222205

223206
Once your MongoDB deployment is ready, enable Search capabilities by creating a `MongoDBSearch` custom resource, also named `mdbc-rs` to associate it with the MongoDB instance. This resource specifies the CPU and memory resource requirements for the search nodes.
224207

225-
Note: Private preview of MongoDB Community Search comes with some limitations, and it is not suitable for production use:
226-
* TLS cannot be enabled in MongoDB Community deployment (MongoD communicates with MongoT with plain text).
227-
* Only one node of search node is supported (load balancing not supported)
208+
Note: Public Preview of MongoDB Community Search comes with some limitations, and it is not suitable for production use:
209+
* Only one instance of the search node is supported (load balancing is not supported)
228210

229211
[code_snippets/0320_create_mongodb_search_resource.sh](code_snippets/0320_create_mongodb_search_resource.sh)
230212
```shell copy
@@ -314,7 +296,7 @@ metadata:
314296
spec:
315297
containers:
316298
- name: mongodb-tools
317-
image: mongodb/mongodb-community-server:8.0.6-ubi9
299+
image: mongodb/mongodb-community-server:${MDB_VERSION}-ubi8
318300
command: ["/bin/bash", "-c"]
319301
args: ["sleep infinity"]
320302
restartPolicy: Never
@@ -336,7 +318,12 @@ kubectl exec -n "${MDB_NAMESPACE}" --context "${K8S_CLUSTER_0_CONTEXT_NAME}" mon
336318
echo "Downloading sample database archive..."
337319
curl https://atlas-education.s3.amazonaws.com/sample_mflix.archive -o /tmp/sample_mflix.archive
338320
echo "Restoring sample database"
321+
<<<<<<< Updated upstream
322+
mongorestore --archive=/tmp/sample_mflix.archive --verbose=1 --drop --nsInclude 'sample_mflix.*' \
323+
--uri="mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs"
324+
=======
339325
mongorestore --archive=/tmp/sample_mflix.archive --verbose=1 --drop --nsInclude 'sample_mflix.*' --uri="mongodb://search-user:${MDB_SEARCH_SYNC_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs"
326+
>>>>>>> Stashed changes
340327
EOF
341328
)"
342329
```
@@ -351,7 +338,11 @@ Before performing search queries, create a search index. This step uses `kubectl
351338
#!/bin/bash
352339
353340
kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- \
341+
<<<<<<< Updated upstream
342+
mongosh --quiet "mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
343+
=======
354344
mongosh --quiet "mongodb://search-user:${MDB_SEARCH_SYNC_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
345+
>>>>>>> Stashed changes
355346
--eval "use sample_mflix" \
356347
--eval 'db.movies.createSearchIndex("default", { mappings: { dynamic: true } });'
357348
```
@@ -364,6 +355,11 @@ Creating a search index is an asynchronous operation. This script polls periodic
364355
```shell copy
365356
#!/bin/bash
366357
358+
<<<<<<< Updated upstream
359+
# Currently it's not possible to check the status of search indexes, we need to just wait
360+
echo "Sleeping to wait for search indexes to be created"
361+
sleep 60
362+
=======
367363
for _ in $(seq 0 10); do
368364
search_index_status=$(kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- \
369365
mongosh --quiet "mongodb://search-user:${MDB_SEARCH_SYNC_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
@@ -382,6 +378,7 @@ if [[ "${search_index_status}" != "READY" ]]; then
382378
echo "Error waiting for the search index to be ready"
383379
return 1
384380
fi
381+
>>>>>>> Stashed changes
385382
```
386383

387384
### 17. Execute a Search Query
@@ -434,7 +431,11 @@ EOF
434431
435432
kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
436433
echo '${mdb_script}' > /tmp/mdb_script.js
434+
<<<<<<< Updated upstream
435+
mongosh --quiet "mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" < /tmp/mdb_script.js
436+
=======
437437
mongosh --quiet "mongodb://search-user:${MDB_SEARCH_SYNC_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" < /tmp/mdb_script.js
438+
>>>>>>> Stashed changes
438439
EOF
439440
)"
440441
```

docs/community-search/quick-start/README.md.j2

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ Ensure these secrets are created in the same namespace where you plan to deploy
6363

6464
### 7. Create MongoDB Community Resource
6565

66-
Now, deploy MongoDB Community by creating a `MongoDBCommunity` custom resource named `mdbc-rs`. This resource definition instructs the MongoDB Kubernetes Operator to configure a MongoDB replica set with 3 members, running version 8.0.6. MongoDB Community Search is supported only from MongoDB Community Server version 8.0. It also defines CPU and memory resources for the `mongod` and `mongodb-agent` containers, and sets up two users (`admin-user` and `search-user`) with their respective roles and password secrets. User `search-user` will be used to restore, connect and perform search queries on the `sample_mflix` database.
66+
Now, deploy MongoDB Community by creating a `MongoDBCommunity` custom resource named `mdbc-rs`. This resource definition instructs the MongoDB Kubernetes Operator to configure a MongoDB replica set with 3 members, running version 8.0.10. MongoDB Community Search is supported only from MongoDB Community Server version 8.0.10. It also defines CPU and memory resources for the `mongod` and `mongodb-agent` containers, and sets up three users:
67+
* `mdb-user` - a regular user used to that will perform restore of `sample_mflix` database and execute search queries.
68+
* `search-sync-source` - user that MongoDB Search is using to connect to MongoDB database in order to manage and build indexes. This user uses `searchCoordinator` role, which for MongoDB <8.2 is created automatically by the operator.
69+
* `admin-user` and ``) with their respective roles and password secrets. User `search-user` will be used to restore, connect and perform search queries on the `sample_mflix` database.
6770

6871
[code_snippets/0310_create_mongodb_community_resource.sh](code_snippets/0310_create_mongodb_community_resource.sh)
6972
```yaml copy
@@ -83,9 +86,8 @@ After applying the `MongoDBCommunity` custom resource, the operator begins deplo
8386
8487
Once your MongoDB deployment is ready, enable Search capabilities by creating a `MongoDBSearch` custom resource, also named `mdbc-rs` to associate it with the MongoDB instance. This resource specifies the CPU and memory resource requirements for the search nodes.
8588
86-
Note: Private preview of MongoDB Community Search comes with some limitations, and it is not suitable for production use:
87-
* TLS cannot be enabled in MongoDB Community deployment (MongoD communicates with MongoT with plain text).
88-
* Only one node of search node is supported (load balancing not supported)
89+
Note: Public Preview of MongoDB Community Search comes with some limitations, and it is not suitable for production use:
90+
* Only one instance of the search node is supported (load balancing is not supported)
8991
9092
[code_snippets/0320_create_mongodb_search_resource.sh](code_snippets/0320_create_mongodb_search_resource.sh)
9193
```shell copy

0 commit comments

Comments
 (0)