A Kubernetes Operator for MongoDB Atlas with which you can manage your MongoDB Atlas projects and clusters from within Kubernetes such as you do with your containerized applications. It is built using the Operator Framework and Kubernetes Custom Resource Definitions (CRDs).
This project was inspired from the MongoDB Atlas Terraform Provider with the goal to have Kubernetes as the single source for both your (stateless) applications and MongoDB Atlas as the persistence layer. The benefit over using the Terraform provider is that mongodbatlas-operator
ensures via Reconcile loops to have the desired state matching with the actual state and thus following the GitOps approach.
Currently it supports:
- Create/Delete MongoDB Atlas Projects
- Create/Update/Delete MongoDB Atlas Clusters
- Create/Update/Delete MongoDB Atlas Database Users
- Create/Update/Delete MongoDB Atlas Alert Configurations
This example creates a MongoDB Atlas project and a cluster inside this project.
First, create the MongoDB Atlas project CRD and some RBAC:
kubectl create -f deploy/service_account.yaml
kubectl create -f deploy/role.yaml
kubectl create -f deploy/role_binding.yaml
kubectl create -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_crd.yaml
kubectl create -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_crd.yaml
Create a Kubernetes secret containing the Private Key of the MongoDB Atlas Programmatic API Key
kubectl create secret generic example-monogdb-atlas-project \
--from-literal=privateKey=xxxxxxxxx
Adapt the environment variable ATLAS_PUBLIC_KEY
in operator.yaml to your public key.
Deploy the MongoDB Atlas Project Operator:
kubectl apply -f deploy/operator.yaml
Adapt knappek_v1alpha1_mongodbatlasproject_cr.yaml accordingly and deploy your first MongoDB Atlas Project
kubectl apply -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_cr.yaml
Adapt knappek_v1alpha1_mongodbatlascluster_cr.yaml accordingly and deploy your first MongoDB Atlas Cluster
kubectl apply -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_cr.yaml
You can easily list all MongoDB Atlas related resources with
kubectl get mongodbatlas
kubectl delete -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_cr.yaml
kubectl delete -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_cr.yaml
kubectl delete -f deploy/
kubectl delete -f deploy/crds/
You can specify the following environment variables in the Operator's operator.yaml:
Name | Description | Default | Required |
---|---|---|---|
WATCH_NAMESPACE | The namespace which the operator should watch for MongoDBAtlas CRDs. | metadata.namespace |
yes |
POD_NAME | Operator pod name. | metadata.name |
no |
OPERATOR_NAME | Operator name. | n/a | no |
ATLAS_PRIVATE_KEY | The private key of the Atlas API. | n/a | yes |
ATLAS_PUBLIC_KEY | The private key of the Atlas API. | n/a | yes |
RECONCILIATION_TIME | Time in seconds which should be used to periodically reconcile the actual status in MongoDB Atlas with the current status in the corresponding Kubernetes CRD. | "120" |
no |
I am working on this project in my spare time, hence feature development and release cycles could be improved ;). Contributors are welcome!
Read through the Contributing Guidelines and Code of Conduct.
More information how to contribute/develop can be found in the docs.