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

Commit 643db47

Browse files
(DOCSP-10035): Add architecture docs (#53)
* (DOCSP-10035): Add architecture docs * Cleanup * Tech review * Copy review
1 parent 4184c5a commit 643db47

File tree

2 files changed

+87
-14
lines changed

2 files changed

+87
-14
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ If you are a MongoDB Enterprise customer, or need Enterprise features such as Ba
2121
- [Contribute](#contribute)
2222
- [License](#license)
2323

24-
2524
## Install the Operator
2625

2726
### Prerequisites
@@ -64,7 +63,6 @@ To install the MongoDB Community Kubernetes Operator:
6463
kubectl get pods --namespace <my-namespace>
6564
```
6665
67-
6866
## Upgrade the Operator
6967
7068
To upgrade the MongoDB Community Kubernetes Operator:
@@ -75,10 +73,9 @@ To upgrade the MongoDB Community Kubernetes Operator:
7573
kubectl apply -f deploy/crds/mongodb.com_mongodb_crd.yaml
7674
```
7775
78-
7976
## Deploy and Configure a MongoDB Resource
8077
81-
The `/deploy/crds` directory contains example MongoDB resources that you can modify and deploy.
78+
The [`/deploy/crds`](deploy/crds) directory contains example MongoDB resources that you can modify and deploy.
8279
8380
### Deploy a Replica Set
8481
@@ -163,14 +160,15 @@ The MongoDB Community Kubernetes Operator supports the following features:
163160

164161
## Contribute
165162

166-
Please get familiar with the architecture.md document and then go ahead and read
167-
the [contributing guide](contributing.md).
163+
Before you contribute to the MongoDB Community Kubernetes Operator, please read:
164+
165+
- [MongoDB Community Kubernetes Operator Architecture](architecture.md)
166+
- [Contributing to MongoDB Community Kubernetes Operator](contributing.md)
168167

169168
Please file issues before filing PRs. For PRs to be accepted, contributors must sign our [CLA](https://www.mongodb.com/legal/contributor-agreement).
170169

171170
Reviewers, please ensure that the CLA has been signed by referring to [the contributors tool](https://contributors.corp.mongodb.com/) (internal link).
172171

173-
174172
## License
175173

176174
The source code of this Operator is available under the Apache v2 license.

architecture.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,86 @@
1-
# MongoDB Community Operator Architecture
1+
# MongoDB Community Kubernetes Operator Architecture
22

3-
**Work in Progress**
3+
The MongoDB Community Kubernetes Operator is a [Custom Resource Definition](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) and a [Controller](https://kubernetes.io/docs/concepts/architecture/controller/).
44

5-
## Topics
5+
## Table of Contents
66

7-
* Automation Agent
8-
* Cluster Configuration and ConfigMap
9-
* MongoDB Docker Images
10-
* Example case: MongoDB version upgrade
7+
- [Cluster Configuration](#cluster-configuration)
8+
- [Example: MongoDB Version Upgrade](#example-mongodb-version-upgrade)
9+
- [MongoDB Docker Images](#mongodb-docker-images)
1110

11+
## Cluster Configuration
12+
13+
You create and update MongoDB resources by defining a MongoDB resource definition. When you apply the MongoDB resource definition to your Kubernetes environment, the Operator:
14+
15+
1. Creates a [StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) that contains one [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/) for each [replica set](https://docs.mongodb.com/manual/replication/) member.
16+
1. Creates two [containers](https://kubernetes.io/docs/concepts/containers/overview/) in each pod:
17+
18+
- A container for the [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/index.html) process binary. </br>
19+
`mongod` is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.
20+
21+
- A container for the MongoDB Agent. </br>
22+
The Automation function of the MongoDB Agent handles configuring, stopping, and restarting the `mongod` process. The MongoDB Agent periodically polls the `mongod` to determine status and can deploy changes as needed.
23+
1. Writes the Automation configuration as a [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) and mounts it to each pod.
24+
1. Initiates the MongoDB Agent, which in turn creates the database configuration and launches the `mongod` process according to your [MongoDB resource definition](deploy/crds/mongodb.com_v1_mongodb_cr.yaml).
25+
26+
<!--
27+
<img src="" alt="Architecure diagram of the MongoDB Community Kubernetes Operator">
28+
-->
29+
30+
This architecture maximizes use of the MongoDB Agent while integrating naturally with Kubernetes to produce a number of benefits.
31+
32+
- The database container is not tied to the lifecycle of the Agent container or to the Operator, so you can:
33+
- Use your preferred Linux distribution inside the container.
34+
- Update operating system packages on your own schedule.
35+
- Upgrade the Operator or Agent without affecting the database image or uptime of the MongoDB servers.
36+
- Containers are immutable and have a single responsibility or process, so you can:
37+
- Describe and understand each container.
38+
- Configure resources independently for easier debugging and triage.
39+
- Inspect resources independently, including tailing the logs.
40+
- Expose the state of each container.
41+
- Pods are defined as StatefulSets so they benefit from stable identities.
42+
- You can upgrade the Operator without restarting either the database or the MongoDB Agent containers.
43+
- You can set up a MongoDB Kubernetes cluster offline once you download the Docker containers for the database and MongoDB Agent.
44+
45+
## Example: MongoDB Version Upgrade
46+
47+
The MongoDB Community Kubernetes Operator uses the Automation function of the MongoDB Agent to efficiently handle rolling upgrades. The Operator configures the StatefulSet to block Kubernetes from performing native rolling upgrades because the native process can trigger multiple re-elections in your MongoDB cluster.
48+
49+
When you update the MongoDB version in your resource definition and reapply it to your Kubernetes environment, the Operator initiates a rolling upgrade:
50+
51+
1. The Operator changes the StatefulSet [update strategy](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies) from `RollingUpdate` to `OnDelete`.
52+
53+
1. The Operator updates the [image](https://kubernetes.io/docs/concepts/containers/images/) specification to the new version of MongoDB and writes a new Automation configuration ConfigMap to each pod.
54+
55+
1. The MongoDB Agent chooses the first pod to upgrade and stops the `mongod` process using a local connection and [`db.shutdownServer`](https://docs.mongodb.com/manual/reference/method/db.shutdownServer/#db.shutdownServer).
56+
57+
1. A pre-stop hook on the database container checks the state of the MongoDB Agent. If the MongoDB Agent expects the `mongod` process to start with a new version, the hook uses a Kubernetes API call to delete the pod.
58+
59+
1. The Kubernetes Controller downloads the target version of MongoDB from its default docker registry and restarts the pod with the target version of `mongod` in the database container.
60+
61+
1. The MongoDB Agent starts. It checks the target version of the new `mongod`, then generates the configuration file for the `mongod` process.
62+
63+
1. The `mongod` process receives the configuration file from the MongoDB Agent and starts.
64+
65+
1. The MongoDB Agent reaches goal state.
66+
67+
1. The MongoDB Agent chooses the next pod to upgrade and repeats the process until all pods are upgraded.
68+
69+
1. The Operator changes the StatefulSet update strategy from `OnDelete` back to `RollingUpdate`.
70+
71+
<!--
72+
<img src="" alt="Rolling upgrade flow diagram for the MongoDB Community Kubernetes Operator">
73+
-->
74+
75+
This upgrade process allows the MongoDB Agent to:
76+
77+
- Perform pre-conditions.
78+
- Upgrade the secondaries first.
79+
- Wait for the secondaries' oplogs to catch up before triggering an election.
80+
- Upgrade quickly for large replica sets.
81+
- Consider voting nodes.
82+
- Ensure a replica set is always available throughout the entire upgrade process.
83+
84+
## MongoDB Docker Images
85+
86+
MongoDB images are available on [Docker Hub](https://hub.docker.com/_/mongo?tab=tags&page=1&ordering=last_updated).

0 commit comments

Comments
 (0)