Helm Charts Quick Start
On this page
- Prerequisites
- Procedure
- Register for an Atlas account or log in.
- Create API keys for your organization.
- Deploy Atlas Kubernetes Operator.
- Deploy the Atlas database deployment.
- Check the status of your database user.
- Retrieve the secret that Atlas Kubernetes Operator created to connect to the database deployment.
You can use Atlas Kubernetes Operator to manage resources in Atlas without leaving Kubernetes. This tutorial demonstrates how to create your first cluster in Atlas from Helm Charts with Atlas Kubernetes Operator.
Note
Would you prefer to start without Helm?
To create your first cluster in Atlas from Kubernetes configuration files with Atlas Kubernetes Operator, see Quick Start.
Prerequisites
This tutorial requires:
A running Kubernetes cluster with nodes running processors with the x86-64, AMD64, or ARM64 architecture.
You can access the Atlas Kubernetes Operator project on GitHub:
Procedure
Important
Custom Resources No Longer Delete Objects by Default
Atlas Kubernetes Operator uses custom resource configuration files to manage your Atlas configuration, but as of Atlas Kubernetes Operator 2.0, custom resources you delete in Kubernetes are no longer (by default) deleted in Atlas. Instead, Atlas Kubernetes Operator simply stops managing those resources in Atlas. For example, if you delete an
AtlasProject
Custom Resource in Kubernetes, by default the Atlas Kubernetes Operator no longer automatically deletes the corresponding project from Atlas. This change in behavior is intended to help prevent accidental or unexpected deletions. To learn more, including how to revert this behavior to the default used prior to Atlas Kubernetes Operator 2.0, see New Default: Deletion Protection in Atlas Kubernetes Operator 2.0.Similarly, Atlas Kubernetes Operator does not delete teams from Atlas if you remove them from an Atlas project in Kubernetes with the Atlas Kubernetes Operator.
Explicitly define your desired configuration details in order to avoid implicitly using default Atlas configuration values. In some cases, inheriting Atlas defaults may result in a reconciliation loop which can prevent your custom resource from achieving a
READY
state. For example, explicitly defining your desired autoscaling behavior in yourAtlasDeployment
custom resource, as shown in the included example, ensures that a static instance size in your custom resource is not being repeatedly applied to an Atlas deployment which has autoscaling enabled.autoScaling: diskGB: enabled: true compute: enabled: true scaleDownEnabled: true minInstanceSize: M30 maxInstanceSize: M40
Register for an Atlas account or log in.
Register a new Atlas Account or Log in to Your Atlas Account.
Create API keys for your organization.
Note
You need the following public API key, private API key, and the organization ID information to configure Atlas Kubernetes Operator access to Atlas.
Grant Programmatic Access to an Organization and configure the API Access List.
You need the following public API key, private API key, and the organization ID information to configure Atlas Kubernetes Operator access to Atlas.
If you want Atlas Kubernetes Operator to create a new Atlas project, Grant Programmatic Access to an Organization. If your organization requires an IP access list for the Atlas Administration API, you must also configure the API access list.
Important
You must assign the API key the Organization Project Creator organization role or higher.
If you want to work with an existing Atlas project, Add Project Access from a Project. If your organization requires an IP access list for the Atlas Administration API, you must also configure the API access list.
Important
You must assign the API key the Project Owner project role.
Deploy Atlas Kubernetes Operator.
Run one of the following sets of commands:
If you want Atlas Kubernetes Operator to watch all namespaces in the Kubernetes cluster, run the following commands:
helm repo add mongodb https://mongodb.github.io/helm-charts helm install atlas-operator --namespace=atlas-operator --create-namespace mongodb/mongodb-atlas-operator If you want Atlas Kubernetes Operator to watch a particular set of namespaces, set the
--watchNamespaces
flag to a comma-separated list of namespaces to be watched. For example, run the following command to watch only the atlas-operator``namespace:helm install atlas-operator --namespace=atlas-operator --set watchNamespaces=atlas-operator --create-namespace mongodb/mongodb-atlas-operator
Deploy the Atlas database deployment.
Customize the Atlas project and its database users.
Note
You can find the following additional example Helm Charts in GitHub:
atlas-basic: A simple Atlas Kubernetes Operator deployment example that includes the creation of an Atlas project, cluster and a database user.
atlas-advanced: An extensible, advanced Atlas Kubernetes Operator example deployment with biolerplate related to multi-region deployments, autoscaling behavior and more.
Create a file named
install-values.yaml
and paste the following example code, which does the following:Sets the project name to
My Project
.Allows all IP addresses (0.0.0.0) to access the project.
Creates a database user named
dbadmin
that has thedbAdmin
role.Creates a database user named
dbuser
that has thereadWrite
role.
project: # Project custom values atlasProjectName: "My Project" projectIpAccessList: - cidrBlock: "0.0.0.0/0" users: # Custom database users - username: dbadmin databaseName: admin roles: - databaseName: admin-role roleName: dbAdmin - username: dbuser databaseName: admin roles: - databaseName: user-role roleName: readWrite Run the following command.
The
--set
and--values
flags in the following command override theValues.yaml
file values and default Helm Charts values with your organization ID, API keys, and Atlas project configuration.Note
mongodb/atlas-deployment
references the name of a chart in the repository.helm install atlas-deployment \ mongodb/atlas-deployment \ --namespace=my-cluster \ --create-namespace \ --set atlas.secret.orgId='<orgid>' \ --set atlas.secret.publicApiKey='<publicKey>' \ --set atlas.secret.privateApiKey='<privateApiKey>' \ --values install-values.yaml To learn more about the available parameters, see
AtlasDeployment
Custom Resource.To create a Serverless instance, see the Serverless instance example.
Check the status of your database user.
Run the following command to wait for the dbadmin
database user to become ready:
kubectl wait --for=condition=ready --timeout=10m -n my-cluster atlasdatabaseusers/atlas-deployment-dbadmin
Note
The AtlasDatabaseUser
Custom Resource waits until the
database deployment is ready. Creating a new
database deployment can take up to 10 minutes.
Retrieve the secret that Atlas Kubernetes Operator created to connect to the database deployment.
Important
The following command requires jq
1.6 or higher.
Run the following command to retrieve the connection string
and password for the dbadmin
database user. Your connection
strings will differ from the example output.
kubectl get secret -n my-cluster my-project-cluster-name-dbadmin -o json | jq -r '.data | with_entries(.value |= @base64d)';
{ "connectionStringStandard": "mongodb://admin-user:%25SomeLong%25password$foradmin@atlas-cluster-shard-00-00.nlrvs.mongodb.net:27017,atlas-cluster-shard-00-01.nlrvs.mongodb.net:27017,atlas-cluster-shard-00-02.nlrvs.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-11q9bn-shard-0", "connectionStringStandardSrv": "mongodb+srv://admin-user:%25SomeLong%25password$foradmin@atlas-cluster.nlrvs.mongodb.net", "password": "%SomeLong%password$foradmin", "username": "dbadmin" }
You can use the following secret in your application:
containers: - name: test-app env: - name: "CONNECTION_STRING" valueFrom: secretKeyRef: name: my-project-cluster-name-dbadmin key: connectionStringStandardSrv