Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you run the open-source, MongoDB-compatible DocumentDB database on a local Kind Kubernetes cluster. You connect the cluster to Azure Arc, install the DocumentDB operator through an Arc extension, and use mongosh to insert and query a document.
Important
This capability is in preview. Microsoft provides no support for this DocumentDB capability during preview. Don't use it for production workloads. This restriction doesn't change the support terms for the underlying Azure Arc or infrastructure services.
This evaluation uses a dedicated, disposable cluster and test data. It doesn't establish compatibility with Kubernetes hosts on Azure Local or provide the fully managed Azure DocumentDB service.
Prerequisites
- An Azure subscription and region with access to the DocumentDB Arc preview extension. Selecting the
previewrelease train doesn't grant access or establish availability for your subscription or region. - The permissions, resource provider registrations, and outbound network access described in Connect an existing Kubernetes cluster to Azure Arc. Complete that article's prerequisites, but use the cluster creation and connection steps in this quickstart.
- A local Bash terminal on Linux, macOS, or Windows Subsystem for Linux (WSL), with access to a running Docker engine. Run the commands locally, not in Azure Cloud Shell.
- Docker 20.10 or later, Kind 0.31 or later, and
kubectlcompatible with Kubernetes 1.35. This quickstart uses thekindest/node:v1.35.0image. - A current Azure CLI and MongoDB Shell (
mongosh). - Local capacity for the cluster and database, including a 10-GiB persistent volume, and access to the container registries used by the extensions.
Use the same Bash terminal throughout, except where a second terminal is specified. Stop and resolve any failed command before proceeding.
On Windows, use Bash inside WSL with Docker Desktop's WSL integration enabled for that distribution. Install the Linux versions of Azure CLI, Kind, kubectl, and mongosh in that WSL environment, and run az login there. Don't substitute PowerShell or Git Bash with native Windows executables for these instructions; the Bash syntax and /dev/stdin input require a compatible environment.
Before installing extensions or creating resources, verify that your terminal can reach the Docker engine:
docker info
Confirm that the command succeeds and displays server information for Linux containers. If it reports a connection error, resolve Docker startup or WSL integration before continuing. An open Docker Desktop window alone doesn't confirm that the engine is ready.
Install or update the Azure CLI extensions:
az extension add --name connectedk8s --upgrade
az extension add --name k8s-extension --upgrade
Set evaluation variables
Replace the subscription and region placeholders with values eligible for your preview access. Use new resource names that aren't already in use. Don't reuse a cluster or resource group that contains other workloads.
export SUBSCRIPTION_ID="<your-subscription-id>"
export LOCATION="<your-preview-region>"
export RESOURCE_GROUP="documentdb-arc-kind-eval-rg"
export ARC_CLUSTER="documentdb-arc-kind-eval"
export KIND_CLUSTER="documentdb-arc-kind-eval"
Sign in and select the subscription:
az login
az account set --subscription "$SUBSCRIPTION_ID"
az account show --query "{subscription:name,id:id}" --output table
Check that the selected subscription is the one you intend to use.
Create and connect the Kind cluster
Create a new cluster with Kubernetes 1.35:
kind create cluster --name "$KIND_CLUSTER" --image kindest/node:v1.35.0
kubectl --context "kind-$KIND_CLUSTER" cluster-info
kubectl --context "kind-$KIND_CLUSTER" get nodes
Wait for the node to report Ready. Kind sets the current Kubernetes context to the new cluster. The following commands also specify its context explicitly to avoid targeting another cluster.
Create the dedicated resource group and connect the cluster to Azure Arc:
az group create --name "$RESOURCE_GROUP" --location "$LOCATION"
az connectedk8s connect \
--resource-group "$RESOURCE_GROUP" \
--name "$ARC_CLUSTER" \
--location "$LOCATION" \
--kube-context "kind-$KIND_CLUSTER"
az connectedk8s show \
--resource-group "$RESOURCE_GROUP" \
--name "$ARC_CLUSTER" \
--query connectivityStatus --output tsv
Wait for the connectivity status to report Connected. Check that the Arc agent pods are running and their containers are ready:
kubectl --context "kind-$KIND_CLUSTER" get pods --namespace azure-arc
Install cert-manager
DocumentDB requires cert-manager for TLS. On this new, dedicated cluster, install cert-manager as an Arc extension. Don't install a second copy into a cluster that already has cert-manager.
az k8s-extension create \
--cluster-type connectedClusters \
--cluster-name "$ARC_CLUSTER" \
--resource-group "$RESOURCE_GROUP" \
--name cert-manager \
--extension-type microsoft.certmanagement \
--scope cluster \
--release-train Stable
Check that the cert-manager, cainjector, and webhook pods are running and their containers are ready before proceeding:
kubectl --context "kind-$KIND_CLUSTER" get pods --namespace cert-manager
Install the DocumentDB extension
Install the operator from the preview release train. This command omits --version to request the train's default version rather than pin a release.
az k8s-extension create \
--cluster-type connectedClusters \
--cluster-name "$ARC_CLUSTER" \
--resource-group "$RESOURCE_GROUP" \
--name documentdb-operator \
--extension-type microsoft.documentdb.operator \
--release-train preview \
--scope cluster
az k8s-extension show \
--cluster-type connectedClusters \
--cluster-name "$ARC_CLUSTER" \
--resource-group "$RESOURCE_GROUP" \
--name documentdb-operator \
--query "{version:currentVersion,state:provisioningState}" --output json
Wait for provisioningState to report Succeeded. Then check the operator deployment and pods:
kubectl --context "kind-$KIND_CLUSTER" get deployments --namespace documentdb-operator
kubectl --context "kind-$KIND_CLUSTER" get pods --namespace documentdb-operator
The deployment should have its desired replicas available, and the operator pods should be running with ready containers. Extension provisioning success doesn't mean that a database exists or is ready. Create and check the database next.
Create a database
Create a namespace for the evaluation:
kubectl --context "kind-$KIND_CLUSTER" create namespace documentdb-ns
Create a Kubernetes Secret with username and password keys. The following Bash subshell prompts for a password without displaying it. It passes the password over standard input, not a command-line argument or a YAML string. Use a unique evaluation password and keep it available for the later mongosh prompt. Don't enable shell tracing or record the terminal while entering credentials.
(
set +x
set -euo pipefail
trap 'unset DOCUMENTDB_PASSWORD' EXIT
DOCUMENTDB_PASSWORD=""
while [[ -z "$DOCUMENTDB_PASSWORD" ]]; do
IFS= read -r -s -p "Enter a nonempty evaluation password: " DOCUMENTDB_PASSWORD
printf '\n'
done
printf '%s' "$DOCUMENTDB_PASSWORD" |
kubectl --context "kind-$KIND_CLUSTER" create secret generic documentdb-credentials \
--namespace documentdb-ns \
--from-literal=username=evaluation_user \
--from-file=password=/dev/stdin
)
Kubernetes Secrets aren't a substitute for securing access to your cluster. Don't export this Secret into source control.
Apply the following manifest. The quoted heredoc delimiter prevents shell expansion of the YAML. The resource uses one node, one instance per node, a 10-GiB volume, and a ClusterIP service.
kubectl --context "kind-$KIND_CLUSTER" apply -f - <<'EOF'
apiVersion: documentdb.io/preview
kind: DocumentDB
metadata:
name: my-documentdb
namespace: documentdb-ns
spec:
nodeCount: 1
instancesPerNode: 1
documentDbCredentialSecret: documentdb-credentials
resource:
storage:
pvcSize: 10Gi
exposeViaService:
serviceType: ClusterIP
EOF
Watch the database status:
kubectl --context "kind-$KIND_CLUSTER" get documentdb my-documentdb \
--namespace documentdb-ns --watch
Wait for Cluster in healthy state, and then press Ctrl+C to stop watching. Check the database pods:
kubectl --context "kind-$KIND_CLUSTER" get pods --namespace documentdb-ns
For this single-instance manifest, expect the my-documentdb-1 pod to be Running with both containers ready (2/2). If the database isn't healthy or the pod isn't ready, inspect its status and events before connecting.
Insert and query a document
In your existing terminal (terminal A), forward the gateway port to the IPv4 loopback address only. Leave this command running:
kubectl --context "kind-$KIND_CLUSTER" port-forward \
--address 127.0.0.1 \
--namespace documentdb-ns pod/my-documentdb-1 10260:10260
In a second local Bash terminal (terminal B), connect with mongosh. Enter the password you created earlier when prompted.
The following connection uses TLS but bypasses server certificate validation with --tlsAllowInvalidCertificates. It doesn't verify the server's identity. Use this bypass only for this disposable Kind evaluation over the localhost-only port forward. Never copy it into remote or production connections.
mongosh "mongodb://127.0.0.1:10260/?directConnection=true&tls=true" \
--tlsAllowInvalidCertificates \
--username evaluation_user \
--authenticationMechanism SCRAM-SHA-256 \
--password
At the mongosh prompt, insert and read a test document:
use evaluation
db.items.insertOne({ name: "kind-evaluation", message: "Hello from DocumentDB" })
db.items.find({ name: "kind-evaluation" })
Check that the insert is acknowledged and that the query returns the document. These checks exercise the database connection, authentication, and a first write and read, separately from extension provisioning.
Troubleshoot the evaluation
If a step fails, inspect the failing layer rather than treating extension success as database readiness:
- Arc connectivity: Repeat
az connectedk8s showand inspect the pods inazure-arc. Review the network and permission requirements in the Arc connection quickstart. - Extension provisioning: Repeat
az k8s-extension showwithout--queryto inspect its status. Confirm that your subscription and region have preview access. Don't switch DocumentDB to another release train to work around an installation failure. - Operator or database readiness: Inspect the operator pods, database resource, persistent volume claims, and namespace events with the following commands. Use the reported conditions and events to investigate the failing component.
kubectl --context "kind-$KIND_CLUSTER" get pods --namespace documentdb-operator
kubectl --context "kind-$KIND_CLUSTER" get events \
--namespace documentdb-operator --sort-by=.metadata.creationTimestamp
kubectl --context "kind-$KIND_CLUSTER" describe documentdb my-documentdb \
--namespace documentdb-ns
kubectl --context "kind-$KIND_CLUSTER" describe pod my-documentdb-1 \
--namespace documentdb-ns
kubectl --context "kind-$KIND_CLUSTER" get pvc --namespace documentdb-ns
kubectl --context "kind-$KIND_CLUSTER" get events \
--namespace documentdb-ns --sort-by=.metadata.creationTimestamp
For a connection failure, check that terminal A still shows an active port forward and that the database pod remains ready. Don't expose the gateway on a public interface to troubleshoot a local connection.
Clean up resources
Warning
Deleting the Kind cluster destroys its local database data. Run these steps only against the dedicated disposable cluster created in this quickstart, after you no longer need its test data.
Exit mongosh in terminal B. Press Ctrl+C in terminal A to stop forwarding, and run cleanup in terminal A, where your variables are still set. Confirm the resource names before deleting anything:
printf 'Kind cluster: %s\nArc cluster: %s\nResource group: %s\n' \
"$KIND_CLUSTER" "$ARC_CLUSTER" "$RESOURCE_GROUP"
kubectl --context "kind-$KIND_CLUSTER" delete documentdb my-documentdb \
--namespace documentdb-ns
kubectl --context "kind-$KIND_CLUSTER" delete namespace documentdb-ns
Remove only the extensions installed by this quickstart, and then disconnect this cluster from Azure Arc. Don't remove cert-manager from a shared cluster.
az k8s-extension delete \
--cluster-type connectedClusters \
--cluster-name "$ARC_CLUSTER" \
--resource-group "$RESOURCE_GROUP" \
--name documentdb-operator --yes
az k8s-extension delete \
--cluster-type connectedClusters \
--cluster-name "$ARC_CLUSTER" \
--resource-group "$RESOURCE_GROUP" \
--name cert-manager --yes
az connectedk8s delete \
--resource-group "$RESOURCE_GROUP" \
--name "$ARC_CLUSTER" \
--kube-context "kind-$KIND_CLUSTER" \
--yes
Delete the local cluster:
kind delete cluster --name "$KIND_CLUSTER"
Don't rely on custom-resource or extension deletion to retain database storage. This evaluation ends by deleting the entire local cluster. The cleanup leaves the Azure resource group in place; delete it separately only after confirming that it's the group you created here and contains no resources you need.