Skip to content

Commit 96b010a

Browse files
committed
Updated snippets
1 parent 638ba6b commit 96b010a

File tree

3 files changed

+85
-117
lines changed

3 files changed

+85
-117
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: 71 additions & 112 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,18 @@ 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-
export MDB_SEARCH_SYNC_USER_PASSWORD="search-user-password-CHANGE-ME"
38+
# regular user performing restore and search queries on sample mflix database
39+
export MDB_USER_PASSWORD="mdb-user-password-CHANGE-ME"
40+
# user for MongoDB Search to connect to the replica set to synchronise data from
41+
export MDB_SEARCH_SYNC_USER_PASSWORD="search-sync-user-password-CHANGE-ME"
3942

4043
export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes"
4144
# comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operator
@@ -67,59 +70,7 @@ helm upgrade --install --debug --kube-context "${K8S_CLUSTER_0_CONTEXT_NAME}" \
6770
--set "${OPERATOR_ADDITIONAL_HELM_VALUES:-"dummy=value"}" \
6871
"${OPERATOR_HELM_CHART}"
6972
```
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`.
73+
This command installs the operator in the `mongodb` namespace (creating it if it doesn't exist).
12374

12475
## Creating a MongoDB Community Search Deployment
12576

@@ -132,18 +83,26 @@ MongoDB requires authentication for secure access. This step creates two Kuberne
13283
[code_snippets/0305_create_mongodb_community_user_secrets.sh](code_snippets/0305_create_mongodb_community_user_secrets.sh)
13384
```shell copy
13485
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
135-
create secret generic admin-user-password \
86+
create secret generic mdb-admin-user-password \
13687
--from-literal=password="${MDB_ADMIN_USER_PASSWORD}"
13788

13889
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
139-
create secret generic search-user-password \
90+
create secret generic mdbc-rs-search-sync-source-password \
14091
--from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}"
92+
93+
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" --namespace "${MDB_NAMESPACE}" \
94+
create secret generic mdb-user-password \
95+
--from-literal=password="${MDB_USER_PASSWORD}"
96+
14197
```
14298
Ensure these secrets are created in the same namespace where you plan to deploy MongoDB.
14399

144100
### 7. Create MongoDB Community Resource
145101

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.
102+
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:
103+
* `mdb-user` - a regular user used to that will perform restore of `sample_mflix` database and execute search queries.
104+
* `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.
105+
* `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.
147106

148107
[code_snippets/0310_create_mongodb_community_resource.sh](code_snippets/0310_create_mongodb_community_resource.sh)
149108
```yaml copy
@@ -153,7 +112,7 @@ kind: MongoDBCommunity
153112
metadata:
154113
name: mdbc-rs
155114
spec:
156-
version: 8.0.6
115+
version: ${MDB_VERSION}
157116
type: ReplicaSet
158117
members: 3
159118
security:
@@ -162,7 +121,7 @@ spec:
162121
modes:
163122
- SCRAM
164123
agent:
165-
logLevel: INFO
124+
logLevel: DEBUG
166125
statefulSet:
167126
spec:
168127
template:
@@ -171,36 +130,51 @@ spec:
171130
- name: mongod
172131
resources:
173132
limits:
174-
cpu: "3"
175-
memory: 5Gi
176-
requests:
177133
cpu: "2"
178-
memory: 5Gi
134+
memory: 2Gi
135+
requests:
136+
cpu: "1"
137+
memory: 1Gi
179138
- name: mongodb-agent
180139
resources:
181140
limits:
182-
cpu: "2"
183-
memory: 5Gi
184-
requests:
185141
cpu: "1"
186-
memory: 5Gi
142+
memory: 2Gi
143+
requests:
144+
cpu: "0.5"
145+
memory: 1Gi
187146
users:
188-
- name: admin-user
189-
passwordSecretRef:
190-
name: admin-user-password
147+
# admin user with root role
148+
- name: mdb-admin
149+
db: admin
150+
passwordSecretRef: # a reference to the secret containing user password
151+
name: mdb-admin-user-password
152+
scramCredentialsSecretName: mdb-admin-user
153+
roles:
154+
- name: root
155+
db: admin
156+
# user performing search queries
157+
- name: mdb-user
158+
db: admin
159+
passwordSecretRef: # a reference to the secret containing user password
160+
name: mdb-user-password
161+
scramCredentialsSecretName: mdb-user-scram
191162
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
163+
- name: restore
164+
db: sample_mflix
165+
- name: readWrite
166+
db: sample_mflix
167+
# user used by MongoDB Search to connect to MongoDB database to synchronize data from
168+
# For MongoDB <8.2, the operator will be creating the searchCoordinator custom role automatically
169+
# From MongoDB 8.2, searchCoordinator role will be a built-in role.
170+
- name: search-sync-source
171+
db: admin
172+
passwordSecretRef: # a reference to the secret that will be used to generate the user's password
173+
name: mdbc-rs-search-sync-source-password
174+
scramCredentialsSecretName: mdbc-rs-search-sync-source
200175
roles:
201-
- db: sample_mflix
202-
name: dbOwner
203-
scramCredentialsSecretName: search-user
176+
- name: searchCoordinator
177+
db: admin
204178
EOF
205179
```
206180

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

223197
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.
224198

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)
199+
Note: Public Preview of MongoDB Community Search comes with some limitations, and it is not suitable for production use:
200+
* Only one instance of the search node is supported (load balancing is not supported)
228201

229202
[code_snippets/0320_create_mongodb_search_resource.sh](code_snippets/0320_create_mongodb_search_resource.sh)
230203
```shell copy
@@ -314,7 +287,7 @@ metadata:
314287
spec:
315288
containers:
316289
- name: mongodb-tools
317-
image: mongodb/mongodb-community-server:8.0.6-ubi9
290+
image: mongodb/mongodb-community-server:${MDB_VERSION}-ubi8
318291
command: ["/bin/bash", "-c"]
319292
args: ["sleep infinity"]
320293
restartPolicy: Never
@@ -336,7 +309,8 @@ kubectl exec -n "${MDB_NAMESPACE}" --context "${K8S_CLUSTER_0_CONTEXT_NAME}" mon
336309
echo "Downloading sample database archive..."
337310
curl https://atlas-education.s3.amazonaws.com/sample_mflix.archive -o /tmp/sample_mflix.archive
338311
echo "Restoring sample database"
339-
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"
312+
mongorestore --archive=/tmp/sample_mflix.archive --verbose=1 --drop --nsInclude 'sample_mflix.*' \
313+
--uri="mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs"
340314
EOF
341315
)"
342316
```
@@ -351,7 +325,7 @@ Before performing search queries, create a search index. This step uses `kubectl
351325
#!/bin/bash
352326
353327
kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- \
354-
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" \
328+
mongosh --quiet "mongodb://mdb-user:${MDB_USER_PASSWORD}@mdbc-rs-0.mdbc-rs-svc.${MDB_NAMESPACE}.svc.cluster.local:27017/?replicaSet=mdbc-rs" \
355329
--eval "use sample_mflix" \
356330
--eval 'db.movies.createSearchIndex("default", { mappings: { dynamic: true } });'
357331
```
@@ -364,24 +338,9 @@ Creating a search index is an asynchronous operation. This script polls periodic
364338
```shell copy
365339
#!/bin/bash
366340
367-
for _ in $(seq 0 10); do
368-
search_index_status=$(kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- \
369-
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" \
370-
--eval "use sample_mflix" \
371-
--eval 'db.movies.getSearchIndexes("default")[0]["status"]')
372-
373-
if [[ "${search_index_status}" == "READY" ]]; then
374-
echo "Search index is ready."
375-
break
376-
fi
377-
echo "Search index is not ready yet: status=${search_index_status}"
378-
sleep 2
379-
done
380-
381-
if [[ "${search_index_status}" != "READY" ]]; then
382-
echo "Error waiting for the search index to be ready"
383-
return 1
384-
fi
341+
# Currently it's not possible to check the status of search indexes, we need to just wait
342+
echo "Sleeping to wait for search indexes to be created"
343+
sleep 60
385344
```
386345

387346
### 17. Execute a Search Query
@@ -434,7 +393,7 @@ EOF
434393
435394
kubectl exec --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
436395
echo '${mdb_script}' > /tmp/mdb_script.js
437-
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
396+
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
438397
EOF
439398
)"
440-
```
399+
```

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)