-
A running Kubernetes cluster
-
Atlas CLI installed locally (v1.7 or higher) and setup with your Atlas account
(There are alternative ways to install the Atlas Kubernetes Operator - via Helm or Kubectl)
- Install the operator via the Atlas cli
atlas kubernetes operator install
- Verify installation and setup
kubectl get pods
kubectl get secrets
- Create an AtlasProject Custom Resource
kubectl apply -f dbaas/atlas-project.yaml
- Create an AtlasCluster Custom Resource
kubectl apply -f dbaas/atlas-mongodb-cluster.yaml
- Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
- Create the Argo Application
Edit the source in gitops/argo-application.yaml
to the repository, revision, and directory to be watched for dbaas file changes
source:
repoURL: https://github.com/giohan/dotlocaldemo.git
targetRevision: HEAD
path: ./dbaas/
Deploy the Application Custom Resource
kubectl apply -f gitops/argo-application.yaml
- Create Atlas resources through the git IaC repository (these steps can be performed without cluster access)
git add dbaas/atlas-project.yaml
git commit -m 'gitops project'
git push -u origin main
git add dbaas/atlas-mongodb-cluster.yaml
git commit -m 'dev mongodb cluster'
git push -u origin main
- Create a secret with a password to log into the Atlas cluster
kubectl create secret generic the-user-password --from-literal="password=P@@sword%" # change this to your password
kubectl label secret the-user-password atlas.mongodb.com/type=credentials
- Create the user through the git IaC repository
git add dbaas/dbuser.yaml
git commit -m 'database user'
git push -u origin main
- Retrieve the secret that Atlas Kubernetes Operator created to connect to the cluster.
The secret is created with a name pattern
{project}-{cluster}-{database-user}
kubectl get secret atlas-project-first-cluster-dbuser -o json | jq -r '.data | with_entries(.value |= @base64d)';
- Use the secret as an environment variable for your deployments. Example:
sample-app/hello-atlas.yaml
env:
- name: "MDB_CONNECTION_STRING"
valueFrom:
secretKeyRef:
name: atlas-project-first-cluster-dbuser
key: connectionStringStandardSrv