Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit f646ed1

Browse files
(DOCSP-16408): Expose connection string for deployments for easy of use (#559)
1 parent 254d071 commit f646ed1

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

docs/deploy-configure.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,58 @@ To deploy your first replica set:
2424
```
2525
kubectl get mongodbcommunity --namespace <my-namespace>
2626
```
27-
4. Connect clients to the MongoDB replica set:
27+
28+
4. The Community Kubernetes Operator creates secrets that contains users' connection strings and credentials.
29+
30+
The secrets follow this naming convention: `<metadata.name>-<auth-db>-<username>`, where:
31+
32+
| Variable | Description | Value in Sample |
33+
|----|----|----|
34+
| `<metadata.name>` | Name of the MongoDB database resource. | `example-mongodb` |
35+
| `<auth-db>` | [Authentication database](https://docs.mongodb.com/manual/core/security-users/#std-label-user-authentication-database) where you defined the database user. | `admin` |
36+
| `<username>` | Username of the database user. | `my-user` |
37+
38+
Update the variables in the following command, then run it to retrieve a user's connection strings to the replica set from the secret:
39+
40+
**NOTE**: The following command requires [jq](https://stedolan.github.io/jq/) version 1.6 or higher.</br></br>
41+
42+
```sh
43+
kubectl get secret <metadata.name>-<auth-db>-<username> -n mongodb -o json | \
44+
jq -r '.data | with_entries(.value |= @base64d)'
45+
```
46+
47+
The command returns the replica set's standard and DNS seed list [connection strings](https://docs.mongodb.com/manual/reference/connection-string/#connection-string-formats) in addition to the user's name and password:
48+
49+
```json
50+
{
51+
"connectionString.standard": "mongodb://<username>:<password>@example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local:27017,example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017,example-mongodb-2.example-mongodb-svc.mongodb.svc.cluster.local:27017/admin?ssl=true",
52+
"connectionString.standardSrv": "mongodb+srv://<username>:<password>@example-mongodb-svc.mongodb.svc.cluster.local/admin?ssl=true",
53+
"password": "<password>",
54+
"username": "<username>"
55+
}
56+
```
57+
58+
**NOTE**: The Community Kubernetes Operator sets the [`ssl` connection option](https://docs.mongodb.com/manual/reference/connection-string/#connection-options) to `true` if you [Secure MongoDB Resource Connections using TLS](secure.md#secure-mongodb-resource-connections-using-tls).</br></br>
59+
60+
You can use the connection strings in this secret in your application:
61+
62+
```yaml
63+
containers:
64+
- name: test-app
65+
env:
66+
- name: "CONNECTION_STRING"
67+
valueFrom:
68+
secretKeyRef:
69+
name: <metadata.name>-<auth-db>-<username>
70+
key: connectionString.standardSrv
71+
72+
5. Use one of the connection strings returned in the previous step to connect to the replica set:
2873
```
29-
mongo "mongodb://<service-object-name>.<namespace>.svc.cluster.local:27017/?replicaSet=<replica-set-name>"
74+
mongo "mongodb+srv://<username>:<password>@example-mongodb-svc.mongodb.svc.cluster.local/admin?ssl=true"
3075
```
31-
**NOTE**: You can access each `mongod` process in the replica set only from within a pod
32-
running in the cluster.
76+
77+
**NOTE**: You can access each `mongod` process in the replica set only from within a pod running in the cluster.
78+
3379

3480
## Scale a Replica Set
3581

0 commit comments

Comments
 (0)