Docs Menu

Atlas Kubernetes 演算子 Dry Run

With the Atlas Kubernetes Operator Dry Run feature, you can see what Atlas Kubernetes Operator is going to change in Atlas, with those custom resources applied to the K8S cluster. The Atlas Kubernetes Operator emits events for every resource that it is going to create/update/delete in Atlas. Events emitted by the Atlas Kubernetes Operator running in Dry Run mode can be filtered by "Dry Run" reason. This feature is particularly useful for upgrading your Atlas Kubernetes Operator resources from v1.9 to v2.x.

In order to use the Atlas Kubernetes Operator Dry Run feature, you need to:

  • Have access to a new Kubernetes or Open Shift cluster.

  • 適用する Atlas Kubernetes Operator custom resources to your new Kubernetes cluster. When you apply your resources, make sure you provide a secret with credentials. You need a new cluster, because upgrading CRDs on your existing Kubernetes cluster might leave Atlas Kubernetes Operator unable to reconcile existing custom resources. Moreover, the CRDs that are applied can be a newer version with potential breaking changes.

    注意

    Only one version of the AKO CRDs can exist in a specific Kubernetes cluster. This means that to test upgrading to a new version of the Atlas Kubernetes Operator, you need to deploy a new Kubernetes cluster (possibly a temporary cluster) to execute the dry run.

  • Install CRDs to your cluster for the version of the Atlas Kubernetes Operator you want to execute dry-run for.

  • Create a mongodb-atlas-operator service account in your Kubernetes cluster.

  • Create a role and rolebinding for your service account with the following permissions related to your Atlas Kubernetes Operator custom resources. You can either create these resources manually or with the Atlas CLI.

    • list

    • get

    • create

    • update

    • delete

The Dry Run process emits either the following message types, each of which can be either of the type Normal or Warning:

  • Would [verb] ([HTTP-Method]) [Atlas resource URL]

    • A description of a given Atlas Kubernetes Operator resource and the Kubernetes required Kubernetes process should the change be applied to your Atlas environment. When in Dry Run mode, Atlas Kubernetes Operator only emits dry-run events for HTTP verbs that would create/update/delete resources in Atlas, such as POST, PATCH, PUT, DELETE.

  • Done

    • No further dry-run events will be reported.

  • Finished

    • The Kubernetes Job running the dry-run process has completed.

1

Save the following example in a file called dry-run-job.yaml and apply it to your cluster by running kubectl apply -f dry-run-job.yaml. This will start Atlas Kubernetes Operator as a Kubernetes Job with the --dry-run parameter. Every reconciliation in the Atlas Kubernetes Operator will run only once, emitting events for each resource if there are changes between the resource spec and its state in Atlas.

You can run this command multiple times without making any changes to your Atlas resources.

1apiVersion: batch/v1
2kind: Job
3metadata:
4 name: ako-dry-run
5 namespace: mongodb-atlas-system
6spec:
7 backoffLimit: 1
8 template:
9 spec:
10 containers:
11 - args:
12 - --atlas-domain=https://cloud.mongodb.com/
13 - --log-level=info
14 - --log-encoder=json
15 - --dry-run
16 command:
17 - /manager
18 env:
19 - name: OPERATOR_POD_NAME
20 value: ako-dry-run
21 - name: OPERATOR_NAMESPACE
22 value: mongodb-atlas-system
23 - name: WATCH_NAMESPACE
24 value: mongodb-atlas-system
25 - name: JOB_NAME
26 value: ako-dry-run
27 image: quay.io/mongodb/mongodb-atlas-kubernetes-operator:2.8.0
28 imagePullPolicy: Always
29 livenessProbe:
30 failureThreshold: 3
31 httpGet:
32 path: /healthz
33 port: 8081
34 scheme: HTTP
35 initialDelaySeconds: 15
36 periodSeconds: 20
37 successThreshold: 1
38 timeoutSeconds: 1
39 name: ako-dry-run
40 restartPolicy: Never
41 serviceAccountName: mongodb-atlas-operator
2

When the Kubernetes Job is finished, you can list the events emitted by running the following command:

kubectl -n mongodb-atlas-system get events --field-selector reason=DryRun

This command will return output similar to the following:

LAST SEEN TYPE REASON OBJECT MESSAGE
103s Normal DryRun atlasproject/my-project Would delete (DELETE) /api/atlas/v1.0/groups/6558f184beba40022cbb2043/integrations/SLACK
101s Warning DryRun atlasproject/my-project finished dry run
1
atlas kubernetes operator install --targetNamespace=mongodb-atlas-system --config-only
2

Run the following Atlas CLI command to start the dry run process. You can run this command multiple times without making any changes to your Atlas resources.

atlas kubernetes dry-run --targetNamespace=mongodb-atlas-system --watch

注意

If the --watch flag is not provided, the Atlas CLI exits after completing the installation.

3

When the Kubernetes Job is finished, you can list the events emitted by running the following command:

kubectl -n mongodb-atlas-system get events --field-selector reason=DryRun

This command will return output similar to the following:

LAST SEEN TYPE REASON OBJECT MESSAGE
103s Normal DryRun atlasproject/my-project Would delete (DELETE) /api/atlas/v1.0/groups/6558f184beba40022cbb2043/integrations/SLACK
101s Warning DryRun atlasproject/my-project finished dry run