You can use Atlas Kubernetes Operator to manage resources in an Atlas project without using Atlas Kubernetes Operator to manage the project itself. In this independent custom resource definition ("independent CRD") model, you associate resources such as AtlasDeployment Custom Resource and AtlasDatabaseUser Custom Resource with an Atlas project directly by its Atlas ID.
独立的 CRD 允许您为项目使用不同的编程基础架构管理系统,而您可以使用Atlas Kubernetes Operator来管理更频繁更改的资源,例如数据库用户或单个部署。
通过将Atlas项目的管理与用户和部署等子资源的管理分开,独立的 CRD 允许您根据需要将这些职责分配给组织内的不同人员或不同团队。
Considerations
当您使用Atlas Kubernetes Operator管理项目时,您可以使用 资源的 参数配置Atlas Administrationspec.connectionSecretRef.name atlasProjectAPI身份验证,或者将此参数保留为未设置以默认为全局Atlas凭证。使用独立的 CRD 时,您可以为每个资源指定 spec.connectionSecret.name。此参数(如已设立)优先于 spec.connectionSecretRef.name 或全局Atlas凭证。
Setting this parameter is required for any resource whose parent resource is referenced using an Atlas project ID, and optional otherwise.
例子
您可以定义一个通过Atlas ID而不是 atlasProject spec.name 参数引用其父项目的 atlasDeployment CRD。您必须为 atlasDeployment资源定义一个 spec.connectSecret.name,如下所示:
apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: test-cluster-name namespace: mongodb-atlas-system spec: externalProjectRef: id: 671998971c8520583f24f411 connectionSecret: name: my-atlas-key deploymentSpec: clusterType: REPLICASET name: service-name tags: - key: "environment" value: "production" backupEnabled: true replicationSpecs: - zoneName: US-Zone numShards: 3 regionConfigs: - regionName: CENTRAL_US providerName: GCP backingProviderName: GCP priority: 7 electableSpecs: instanceSize: M10 nodeCount: 3
迁移到独立 CRD
要将现有 CRD 从 atlasProject 级管理迁移到独立管理:
禁用项目协调并编辑子资源引用
将
mongodb.com/atlas-reconciliation-policy: "skip"注解添加到父资源的metadata中。这可以防止Atlas Kubernetes Operator尝试协调父资源及其子资源。 请考虑以下事项:apiVersion: atlas.mongodb.com/v1 kind: AtlasProject metadata: name: my-project annotations: mongodb.com/atlas-reconciliation-policy: "skip" spec: name: Test project connectionSecretRef: name: my-atlas-key projectIpAccessList: - cidrBlock: "203.0.113.0/24" comment: "CIDR block for Application Server B - D" 警告
如果您不应用此注解, Atlas Kubernetes Operator将在您修改其他资源时继续尝试协调。 对于在Atlas Kubernetes OperatorAtlas Kubernetes Operator2.0 中禁用“新默认值:删除保护”的用户,这可能会导致Atlas KubernetesAtlas Kubernetes Operator AtlasOperator在您删除
atlasProject资源时删除Atlas项目,或者在尝试删除具有活动子资源的项目时进入阻止状态例如数据库用户或部署。Modify the project reference to point to an Atlas project ID instead of an
atlasProjectname.示例,要解耦
atlasDatabaseUser资源:apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: roles: - roleName: readWriteAnyDatabase databaseName: admin externalProjectRef: id: 671998971c8520583f24f411 username: theuser passwordSecretRef: name: the-user-password