@@ -27,14 +27,14 @@ Download or copy the content of `env_variables.sh`:
27
27
[ env_variables.sh] ( env_variables.sh )
28
28
``` shell copy
29
29
# set it to the context name of the k8s cluster
30
- export K8S_CTX =" <local cluster context>"
30
+ export K8S_CLUSTER_0_CONTEXT_NAME =" <local cluster context>"
31
31
32
32
# At the private preview stage the community search image is accessible only from a private repository.
33
33
# Please contact MongoDB Support to get access.
34
34
export PRIVATE_PREVIEW_IMAGE_PULLSECRET=" <.dockerconfigjson>"
35
35
36
36
# the following namespace will be created if not exists
37
- export MDB_NS =" mongodb"
37
+ export MDB_NAMESPACE =" mongodb"
38
38
39
39
export MDB_ADMIN_USER_PASSWORD=" admin-user-password-CHANGE-ME"
40
40
export MDB_SEARCH_USER_PASSWORD=" search-user-password-CHANGE-ME"
@@ -62,9 +62,9 @@ Next, install the MongoDB Kubernetes Operator from the Helm repository you just
62
62
63
63
[ code_snippets/0100_install_operator.sh] ( code_snippets/0100_install_operator.sh )
64
64
``` shell copy
65
- helm upgrade --install --debug --kube-context " ${K8S_CTX } " \
65
+ helm upgrade --install --debug --kube-context " ${K8S_CLUSTER_0_CONTEXT_NAME } " \
66
66
--create-namespace \
67
- --namespace=" ${MDB_NS } " \
67
+ --namespace=" ${MDB_NAMESPACE } " \
68
68
mongodb-kubernetes \
69
69
--set " ${OPERATOR_ADDITIONAL_HELM_VALUES:- " dummy=value" } " \
70
70
" ${OPERATOR_HELM_CHART} "
@@ -133,28 +133,13 @@ MongoDB requires authentication for secure access. This step creates two Kuberne
133
133
134
134
[ code_snippets/0305_create_mongodb_community_user_secrets.sh] ( code_snippets/0305_create_mongodb_community_user_secrets.sh )
135
135
``` shell copy
136
- <<< <<< << HEAD:docs/community-search/quick-start/README.md
137
136
kubectl --context " ${K8S_CLUSTER_0_CONTEXT_NAME} " --namespace " ${MDB_NAMESPACE} " \
138
137
create secret generic admin-user-password \
139
138
--from-literal=password=" ${MDB_ADMIN_USER_PASSWORD} "
140
139
141
140
kubectl --context " ${K8S_CLUSTER_0_CONTEXT_NAME} " --namespace " ${MDB_NAMESPACE} " \
142
141
create secret generic search-user-password \
143
142
--from-literal=password=" ${MDB_SEARCH_USER_PASSWORD} "
144
- ========
145
- kubectl --context " ${K8S_CTX} " --namespace " ${MDB_NS} " \
146
- create secret generic mdb-admin-user-password \
147
- --from-literal=password=" ${MDB_ADMIN_USER_PASSWORD} "
148
-
149
- kubectl --context " ${K8S_CTX} " --namespace " ${MDB_NS} " \
150
- create secret generic mdbc-rs-search-sync-source-password \
151
- --from-literal=password=" ${MDB_SEARCH_SYNC_USER_PASSWORD} "
152
-
153
- kubectl --context " ${K8S_CTX} " --namespace " ${MDB_NS} " \
154
- create secret generic mdb-user-password \
155
- --from-literal=password=" ${MDB_USER_PASSWORD} "
156
-
157
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
158
143
```
159
144
Ensure these secrets are created in the same namespace where you plan to deploy MongoDB.
160
145
@@ -164,7 +149,7 @@ Now, deploy MongoDB Community by creating a `MongoDBCommunity` custom resource n
164
149
165
150
[ code_snippets/0310_create_mongodb_community_resource.sh] ( code_snippets/0310_create_mongodb_community_resource.sh )
166
151
``` yaml copy
167
- kubectl apply --context "${K8S_CTX }" -n "${MDB_NS }" -f - <<EOF
152
+ kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME }" -n "${MDB_NAMESPACE }" -f - <<EOF
168
153
apiVersion : mongodbcommunity.mongodb.com/v1
169
154
kind : MongoDBCommunity
170
155
metadata :
@@ -202,7 +187,6 @@ spec:
202
187
cpu : " 1"
203
188
memory : 5Gi
204
189
users :
205
- <<<<<<<< HEAD:docs/community-search/quick-start/README.md
206
190
- name : admin-user
207
191
passwordSecretRef :
208
192
name : admin-user-password
@@ -219,45 +203,6 @@ spec:
219
203
- db : sample_mflix
220
204
name : dbOwner
221
205
scramCredentialsSecretName : search-user
222
- ========
223
- # admin user with root role
224
- - name : mdb-admin
225
- db : admin
226
- # a reference to the secret containing user password
227
- passwordSecretRef :
228
- name : mdb-admin-user-password
229
- scramCredentialsSecretName : mdb-admin-user
230
- roles :
231
- - name : root
232
- db : admin
233
- # user performing search queries
234
- - name : mdb-user
235
- db : admin
236
- # a reference to the secret containing user password
237
- passwordSecretRef :
238
- name : mdb-user-password
239
- scramCredentialsSecretName : mdb-user-scram
240
- roles :
241
- - name : restore
242
- db : sample_mflix
243
- - name : readWrite
244
- db : sample_mflix
245
- # user used by MongoDB Search to connect to MongoDB database to
246
- # synchronize data from.
247
- # For MongoDB <8.2, the operator will be creating the
248
- # searchCoordinator custom role automatically.
249
- # From MongoDB 8.2, searchCoordinator role will be a
250
- # built-in role.
251
- - name : search-sync-source
252
- db : admin
253
- # a reference to the secret that will be used to generate the user's password
254
- passwordSecretRef :
255
- name : mdbc-rs-search-sync-source-password
256
- scramCredentialsSecretName : mdbc-rs-search-sync-source
257
- roles :
258
- - name : searchCoordinator
259
- db : admin
260
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
261
206
EOF
262
207
```
263
208
@@ -268,12 +213,11 @@ After applying the `MongoDBCommunity` custom resource, the operator begins deplo
268
213
[ code_snippets/0315_wait_for_community_resource.sh] ( code_snippets/0315_wait_for_community_resource.sh )
269
214
``` shell copy
270
215
echo " Waiting for MongoDBCommunity resource to reach Running phase..."
271
- kubectl --context " ${K8S_CTX} " -n " ${MDB_NS} " wait \
272
- --for=jsonpath=' {.status.phase}' =Running mdbc/mdbc-rs --timeout=400s
216
+ kubectl --context " ${K8S_CLUSTER_0_CONTEXT_NAME} " -n " ${MDB_NAMESPACE} " wait --for=jsonpath=' {.status.phase}' =Running mdbc/mdbc-rs --timeout=400s
273
217
echo ; echo " MongoDBCommunity resource"
274
- kubectl --context " ${K8S_CTX } " -n " ${MDB_NS } " get mdbc/mdbc-rs
275
- echo ; echo " Pods running in cluster ${K8S_CTX } "
276
- kubectl --context " ${K8S_CTX } " -n " ${MDB_NS } " get pods
218
+ kubectl --context " ${K8S_CLUSTER_0_CONTEXT_NAME } " -n " ${MDB_NAMESPACE } " get mdbc/mdbc-rs
219
+ echo ; echo " Pods running in cluster ${K8S_CLUSTER_0_CONTEXT_NAME } "
220
+ kubectl --context " ${K8S_CLUSTER_0_CONTEXT_NAME } " -n " ${MDB_NAMESPACE } " get pods
277
221
```
278
222
279
223
### 9. Create MongoDB Search Resource
@@ -286,7 +230,7 @@ Note: Private preview of MongoDB Community Search comes with some limitations, a
286
230
287
231
[ code_snippets/0320_create_mongodb_search_resource.sh] ( code_snippets/0320_create_mongodb_search_resource.sh )
288
232
``` shell copy
289
- kubectl apply --context " ${K8S_CTX } " -n " ${MDB_NS } " -f - << EOF
233
+ kubectl apply --context " ${K8S_CLUSTER_0_CONTEXT_NAME } " -n " ${MDB_NAMESPACE } " -f - << EOF
290
234
apiVersion: mongodb.com/v1
291
235
kind: MongoDBSearch
292
236
metadata:
@@ -321,8 +265,7 @@ Similar to the MongoDB deployment, the Search deployment needs time to initializ
321
265
[code_snippets/0325_wait_for_search_resource.sh](code_snippets/0325_wait_for_search_resource.sh)
322
266
` ` ` shell copy
323
267
echo "Waiting for MongoDBSearch resource to reach Running phase..."
324
- kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait \
325
- --for=jsonpath='{.status.phase}'=Running mdbs/mdbc-rs --timeout=300s
268
+ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" wait --for=jsonpath='{.status.phase}'=Running mdbs/mdbc-rs --timeout=300s
326
269
` ` `
327
270
This command polls the status of the `MongoDBSearch` resource `mdbc-rs`.
328
271
@@ -333,8 +276,7 @@ Double-check the status of your `MongoDBCommunity` resource to ensure it remains
333
276
[code_snippets/0330_wait_for_community_resource.sh](code_snippets/0330_wait_for_community_resource.sh)
334
277
` ` ` shell copy
335
278
echo "Waiting for MongoDBCommunity resource to reach Running phase..."
336
- kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait \
337
- --for=jsonpath='{.status.phase}'=Running mdbc/mdbc-rs --timeout=400s
279
+ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" wait --for=jsonpath='{.status.phase}'=Running mdbc/mdbc-rs --timeout=400s
338
280
` ` `
339
281
This provides a final confirmation that the core database is operational.
340
282
@@ -345,11 +287,11 @@ View all the running pods in your namespace. You should see pods for the MongoDB
345
287
[code_snippets/0335_show_running_pods.sh](code_snippets/0335_show_running_pods.sh)
346
288
` ` ` shell copy
347
289
echo; echo "MongoDBCommunity resource"
348
- kubectl --context "${K8S_CTX }" -n "${MDB_NS }" get mdbc/mdbc-rs
290
+ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME }" -n "${MDB_NAMESPACE }" get mdbc/mdbc-rs
349
291
echo; echo "MongoDBSearch resource"
350
- kubectl --context "${K8S_CTX }" -n "${MDB_NS }" get mdbs/mdbc-rs
351
- echo; echo "Pods running in cluster ${K8S_CTX }"
352
- kubectl --context "${K8S_CTX }" -n "${MDB_NS }" get pods
292
+ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME }" -n "${MDB_NAMESPACE }" get mdbs/mdbc-rs
293
+ echo; echo "Pods running in cluster ${K8S_CLUSTER_0_CONTEXT_NAME }"
294
+ kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME }" -n "${MDB_NAMESPACE }" get pods
353
295
` ` `
354
296
355
297
# # Using MongoDB Search
@@ -362,7 +304,9 @@ To interact with your MongoDB deployment, this step deploys a utility pod named
362
304
363
305
[code_snippets/0410_run_mongodb_tools_pod.sh](code_snippets/0410_run_mongodb_tools_pod.sh)
364
306
` ` ` shell copy
365
- kubectl apply -n "${MDB_NS}" --context "${K8S_CTX}" -f - <<EOF
307
+ #!/bin/bash
308
+
309
+ kubectl apply -n "${MDB_NAMESPACE}" --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -f - <<EOF
366
310
apiVersion: v1
367
311
kind: Pod
368
312
metadata:
@@ -379,8 +323,7 @@ spec:
379
323
EOF
380
324
381
325
echo "Waiting for the mongodb-tools to be ready..."
382
- kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait \
383
- --for=condition=Ready pod/mongodb-tools-pod --timeout=60s
326
+ kubectl wait --for=condition=Ready pod/mongodb-tools-pod -n "${MDB_NAMESPACE}" --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --timeout=60s
384
327
` ` `
385
328
386
329
# ## 14. Import Sample Data
@@ -389,22 +332,13 @@ To test the search functionality, this step imports the `sample_mflix.movies` co
389
332
390
333
[code_snippets/0420_import_movies_mflix_database.sh](code_snippets/0420_import_movies_mflix_database.sh)
391
334
` ` ` shell copy
392
- kubectl exec -n "${MDB_NS}" --context "${K8S_CTX}" \
393
- mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
335
+ #!/bin/bash
336
+
337
+ kubectl exec -n "${MDB_NAMESPACE}" --context "${K8S_CLUSTER_0_CONTEXT_NAME}" mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
394
338
echo "Downloading sample database archive..."
395
- curl https://atlas-education.s3.amazonaws.com/sample_mflix.archive \
396
- -o /tmp/sample_mflix.archive
339
+ curl https://atlas-education.s3.amazonaws.com/sample_mflix.archive -o /tmp/sample_mflix.archive
397
340
echo "Restoring sample database"
398
- <<<<<<<< HEAD:docs/community-search/quick-start/README.md
399
341
mongorestore --archive=/tmp/sample_mflix.archive --verbose=1 --drop --nsInclude 'sample_mflix.*' --uri="mongodb://search-user:${MDB_SEARCH_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs"
400
- ========
401
- mongorestore \
402
- --archive=/tmp/sample_mflix.archive \
403
- --verbose=1 \
404
- --drop \
405
- --nsInclude 'sample_mflix.*' \
406
- --uri="mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=mdbc-rs"
407
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
408
342
EOF
409
343
)"
410
344
` ` `
@@ -416,16 +350,10 @@ Before performing search queries, create a search index. This step uses `kubectl
416
350
417
351
[code_snippets/0430_create_search_index.sh](code_snippets/0430_create_search_index.sh)
418
352
` ` ` shell copy
419
- <<<<<<<< HEAD:docs/community-search/quick-start/README.md
420
353
#!/bin/bash
421
354
422
355
kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- \
423
356
mongosh --quiet "mongodb://search-user:${MDB_SEARCH_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
424
- ========
425
- kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
426
- mongosh --quiet \
427
- "mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
428
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
429
357
--eval "use sample_mflix" \
430
358
--eval 'db.movies.createSearchIndex("default", { mappings: { dynamic: true } });'
431
359
` ` `
@@ -436,7 +364,6 @@ Creating a search index is an asynchronous operation. This script polls periodic
436
364
437
365
[code_snippets/0440_wait_for_search_index_ready.sh](code_snippets/0440_wait_for_search_index_ready.sh)
438
366
` ` ` shell copy
439
- <<<<<<<< HEAD:docs/community-search/quick-start/README.md
440
367
#!/bin/bash
441
368
442
369
for _ in $(seq 0 10); do
@@ -457,11 +384,6 @@ if [[ "${search_index_status}" != "READY" ]]; then
457
384
echo "Error waiting for the search index to be ready"
458
385
return 1
459
386
fi
460
- ========
461
- # Currently it's not possible to check the status of search indexes, we need to just wait
462
- echo "Sleeping to wait for search indexes to be created"
463
- sleep 60
464
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
465
387
` ` `
466
388
467
389
# ## 17. Execute a Search Query
@@ -470,6 +392,8 @@ Once the search index is ready, execute search queries using the `$search` aggre
470
392
471
393
[code_snippets/0450_execute_search_query.sh](code_snippets/0450_execute_search_query.sh)
472
394
` ` ` shell copy
395
+ #!/bin/bash
396
+
473
397
mdb_script=$(cat <<'EOF'
474
398
use sample_mflix;
475
399
db.movies.aggregate([
@@ -510,14 +434,9 @@ db.movies.aggregate([
510
434
EOF
511
435
)
512
436
513
- kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" \
514
- mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
437
+ kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
515
438
echo '${mdb_script}' > /tmp/mdb_script.js
516
- <<<<<<<< HEAD:docs/community-search/quick-start/README.md
517
439
mongosh --quiet "mongodb://search-user:${MDB_SEARCH_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" < /tmp/mdb_script.js
518
- ========
519
- mongosh --quiet "mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=mdbc-rs" < /tmp/mdb_script.js
520
- >>>>>>>> 6309cff6f (Refactor of existing snippets on master):docs/search/01-search-community-deploy/README.md
521
440
EOF
522
441
)"
523
442
` ` `
0 commit comments