Docs 菜单
Docs 主页
/ /
MongoDB Atlas Kubernetes Operator
/ /

管理专用集群的私有端点

在此页面上

  • 步骤

注意

此功能不适用于 M0免费集群、 M2M5集群。 要详细了解哪些功能不可用,请参阅 Atlas M 0 (自由集群)、M 2和 M 5限制。

Atlas Kubernetes Operator 支持管理以下平台上的专用集群的私有端点:

开始之前,请参阅管理私有端点。

要使客户端能够使用私有端点连接到 Atlas 专用集群,请执行以下操作:

1

spec.privateEndpointsAtlasProject自定义资源 指定 参数。在spec.privateEndpoints.provider字段,指定AWS 。 将占位符 {aws-region} 替换为私有端点的Amazon Web Services地区信息,然后运行以下命令:

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "AWS"
region: "{aws-region}"
EOF

Atlas在您选择的地区中创建VPC资源。 这可能需要几分钟才能完成。

2
  1. 运行以下命令:

    kubectl get atlasproject my-project -o yaml
  2. 请注意AtlasProject自定义资源status.privateEndpoints.serviceName字段中每个私有端点的服务名称字符串。

3

要创建应用程序VPC接口端点,请执行以下操作:

  1. 复制以下命令:

    aws ec2 create-vpc-endpoint --vpc-id {your-application-vpc-id} --region {aws-region} --service-name {service-name-string} --vpc-endpoint-type Interface --subnet-ids {your-application-subnet-ids}
  2. 将以下占位符替换为有关Amazon Web Services VPC的详细信息:

    your-application-vpc-id
    标识对等 AWS VPC 的唯一字符串。在您的 AWS 帐户的 VPC 仪表盘上找到此值。
    aws-region
    用于标识私有端点的Amazon Web Services区域的标签。
    service-name-string
    标识私有端点服务名称的唯一字符串。 在AtlasProject自定义资源status.privateEndpoints.serviceName字段中找到此值。
    your-application-subnet-ids

    标识AWS VPC使用的子网的唯一字符串。 用空格分隔每个子网。 在您的Amazon Web Services帐户的 Subnet仪表盘上找到这些值。

    重要提示:您必须至少指定一个子网。 否则,Amazon Web Services 将不会在您的 中预配VPC 接口端点 。VPC中的客户端需要接口端点才能向私有端点发送流量。

  3. 使用Amazon Web ServicesCLI 运行命令。

  4. 请注意输出中的VpcEndpointId值。

    例子

    "VpcEndpoint": {
    "VpcEndpointId": "vpce-XXXXXX",
    "VpcEndpointType": "Interface",
    "VpcId": "vpc-XXXXX",
    "ServiceName": "com.amazonaws.vpce.{aws-region}.vpce-svc-XXXX",
    "State": "pendingAcceptance",

要了解更多信息,请参阅 创建接口端点Amazon Web Services 文档中。

4

更新spec.privateEndpoints AtlasProject自定义资源 的 参数。指定Amazon Web Services地区并将 vpce-id 替换为私有端点的 VpcEndpointId 值,然后运行以下命令:

注意

您可以在 Amazon Web Services 账户的 VPC 仪表盘上找到对等互连 Amazon Web Services VPC 的唯一标识符。

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "AWS"
region: "{aws-region}"
id: "{vpce-id}"
EOF
5

运行以下命令:

kubectl get atlasproject my-project -o yaml
6
  1. 复制以下命令:

    重要

    以下命令需要 jq 1.6 或更高版本。

    kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)';
  2. 对于自定义资源,用详细信息替换以下占位符:

    my-project
    指定AtlasProject自定义资源metadata字段的值。
    my-atlas-cluster
    指定AtlasDeployment自定义资源metadata字段的值。
    my-database-user
    指定AtlasDatabaseUser自定义资源metadata字段的值。
  3. 运行命令。

    注意

    您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如connectionStringPrivate1connectionStringPrivate2等)的connectionStringPrivateconnectionStringPrivateSvr字段。

    {
    "connectionStringPrivate": "mongodb://pl-0-eastus2.uzgh6.mongodb.net:1024,pl-0-eastus2.uzgh6.mongodb.net:1025,pl-0-eastus2.uzgh6.mongodb.net:1026/?ssl=truereplicaSet=atlas-18bndf-shard-0",
    "connectionStringPrivateSrv": "mongodb+srv://cluster0-pl-0.uzgh6.mongodb.net",
    "password": "P@@sword%",
    "username": "theuser"
    }

    您可以使用此 密钥 在您的应用程序中:

    containers:
    - name: test-app
    env:
    - name: "CONNECTION_STRING"
    valueFrom:
    secretKeyRef:
    name: my-project-my-atlas-cluster-my-database-user
    key: connectionStringPrivate
1

spec.privateEndpointsAtlasProject自定义资源 指定 参数。在spec.privateEndpoints.provider字段,指定AZURE 。 将占位符{azure-region}替换为私有端点的Azure地区信息,然后运行以下命令:

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "AZURE"
region: "{azure-region}"
EOF

Atlas在所选地区中创建 VNET 资源。 这可能需要几分钟才能完成。

2

Atlas 不支持私有端点的网络策略。

  1. 复制以下命令:

    az network vnet subnet update --resource-group {resource-group-name} --vnet-name {vnet-name} --name {subnet-name} --disable-private-endpoint-network-policies true
  2. 将以下占位符替换为有关Azure VNet 的详细信息:

    resource-group-name
    资源群组的人类可读标签,其中包含要用于连接到Atlas的 VNet。 在Azure仪表盘的Resource Group Properties页面上查找此值。
    vnet-name
    人类可读标签,用于标识要用于连接到Atlas的 VNet。 在Azure仪表盘的Virtual Network页面上查找此值。
    subnet-name
    人类可读标签,用于标识Azure VNet 中的子网。 在Azure仪表盘的Virtual Network Subnets页面上查找此值。
  3. 使用 Azure CLI运行命令。

要学习;了解详情,请参阅 管理私有端点的网络策略 Azure 文档中。

3
  1. 运行以下命令:

    kubectl get atlasproject my-project -o yaml
  2. 请注意AtlasProject 自定义资源status.privateEndpoints.serviceResourceIdstatus.privateEndpoints.serviceName字段中每个私有端点的服务资源ID和服务名称。

4

要创建私有端点,请执行以下操作:

  1. 复制以下命令:

    az network private-endpoint create --resource-group {resource-group-name} --name {endpoint-name} --vnet-name {vnet-name} --subnet {subnet-name} --private-connection-resource-id {serviceResourceId} --connection-name {serviceName} --manual-request true
  2. 将以下占位符替换为有关Azure VNet 的详细信息:

    resource-group-name
    资源群组的人类可读标签,其中包含要用于连接到Atlas的 VNet。 在Azure仪表盘的Resource Group Properties页面上查找此值。
    endpoint-name
    用于标识私有端点的人类可读标签。 立即指定。
    vnet-name
    人类可读标签,用于标识要用于连接到Atlas的 VNet。 在Azure仪表盘的Virtual Network页面上查找此值。
    subnet-name
    人类可读标签,用于标识Azure VNet 中的子网。 在Azure仪表盘的Virtual Network Subnets页面上查找此值。
    serviceResourceId
    标识私有端点服务资源的唯一string 。 在AtlasProject自定义资源status.privateEndpoints.serviceResourceId字段中找到此值。
    serviceName
    标识私有端点服务名称的唯一字符串。 在AtlasProject自定义资源status.privateEndpoints.serviceName字段中找到此值。
  3. 使用 Azure CLI运行命令。

5

更新spec.privateEndpoints AtlasProject自定义资源 的 参数。指定私有端点的Azure地区、资源ID和IP解决信息,然后运行以下命令:

注意

Azure仪表盘上的Properties页面显示您在Resource ID字段中创建的私有端点的唯一标识符。

Azure仪表盘上的Overview页面显示您在Private IP字段中创建的私有端点网络接口的私有IP解决。

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "Azure"
region: "{azure-region}"
id: "{resource-id}"
ip: "{private-ip}"
EOF
6

运行以下命令:

kubectl get atlasproject my-project -o yaml
7
  1. 复制以下命令:

    重要

    以下命令需要 jq 1.6 或更高版本。

    kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)';
  2. 对于自定义资源,用详细信息替换以下占位符:

    my-project
    指定AtlasProject自定义资源metadata字段的值。
    my-atlas-cluster
    指定AtlasDeployment自定义资源metadata字段的值。
    my-database-user
    指定AtlasDatabaseUser自定义资源metadata字段的值。
  3. 运行命令。

    注意

    您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如connectionStringPrivate1connectionStringPrivate2等)的connectionStringPrivateconnectionStringPrivateSvr字段。

    {
    "connectionStringPrivate": "mongodb://pl-0-eastus2.uzgh6.mongodb.net:1024,pl-0-eastus2.uzgh6.mongodb.net:1025,pl-0-eastus2.uzgh6.mongodb.net:1026/?ssl=truereplicaSet=atlas-18bndf-shard-0",
    "connectionStringPrivateSrv": "mongodb+srv://cluster0-pl-0.uzgh6.mongodb.net",
    "password": "P@@sword%",
    "username": "theuser"
    }

    您可以使用此 密钥 在您的应用程序中:

    containers:
    - name: test-app
    env:
    - name: "CONNECTION_STRING"
    valueFrom:
    secretKeyRef:
    name: my-project-my-atlas-cluster-my-database-user
    key: connectionStringPrivate
1

spec.privateEndpointsAtlasProject自定义资源 指定 参数。在spec.privateEndpoints.provider字段,指定GCP 。 将占位符{gcp-region}替换为私有端点的Google Cloud Platform地区信息,然后运行以下命令:

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "GCP"
region: "{gcp-region}"
EOF

Atlas在您选择的地区中创建VPC资源。 这可能需要几分钟才能完成。

2
  1. 运行以下命令:

    kubectl get atlasproject my-project -o yaml
  2. 请注意每个服务附件名称中projects/后面的{unique-id} 。 以下示例中的{unique-id}p-ogyvk1plka2anycnzl6znr9p

    例子

    "serviceAttachmentNames": [
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-0",
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-1",
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-2",
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-3",
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-4",
    "projects/p-ogyvk1plka2anycnzl6znr9p/regions/us-east1/serviceAttachments/sa-us-east1-6274f45bcce0e51662a29b05-5"
    ]
3

要使用Atlas用户界面编辑私有端点并生成必要的脚本,请参阅配置私有端点。

要手动配置私有端点,请执行以下操作:

  1. 复制以下shell脚本:

    #!/bin/bash
    gcloud config set project {google-cloud-project-id}
    for i in {0..5}
    do
    gcloud compute addresses create {private-service-connect-endpoint-prefix}-ip-$i --region={gcp-region} --subnet={subnet-name}
    done
    for i in {0..5}
    do
    if [ $(gcloud compute addresses describe {private-service-connect-endpoint-prefix}-ip-$i --region={gcp-region} --format="value(status)") != "RESERVED" ]; then
    echo "{private-service-connect-endpoint-prefix}-ip-$i is not RESERVED";
    exit 1;
    fi
    done
    for i in {0..5}
    do
    gcloud compute forwarding-rules create {private-service-connect-endpoint-prefix}-$i --region={gcp-region} --network={vpc-name} --address={private-service-connect-endpoint-prefix}-ip-$i --target-service-attachment=projects/{unique-ID}/regions/{gcp-region}/serviceAttachments/sa-{gcp-region}-{org-id}-$i
    done
    if [ $(gcloud compute forwarding-rules list --regions={gcp-region} --format="csv[no-heading](name)" --filter="name:{private-service-connect-endpoint-prefix}" | wc -l) -gt 50 ]; then
    echo "Project has too many forwarding rules that match prefix {endpoint-name}. Either delete the competing resources or choose another endpoint prefix."
    exit 2;
    fi
    gcloud compute forwarding-rules list --regions={gcp-region} --format="json(IPAddress,name)" --filter="name:{private-service-connect-endpoint-prefix}" > atlasEndpoints-{endpoint-name}.json
  2. 将以下占位符替换为有关Google Cloud Platform VPC的详细信息:

    google-cloud-project-id
    ID用于标识您的Google Cloud Platform 项目的唯一 。在Google Cloud Platform的 Dashboard 页面上查找此值。
    private-service-connect-endpoint-prefix
    人类可读标签,为创建的所有端点添加前缀,并标识端点群组。
    gcp-region
    用于标识私有端点的Google Cloud Platform地区的标签。
    subnet-name
    人类可读标签,用于标识Google Cloud Platform VPC中的子网。 在Google Cloud Platform仪表盘的 VPC Networks 页面上查找此值。
    vpc-name
    人类可读标签,用于标识要用于连接到Atlas的VPC 。 在Google Cloud Platform仪表盘的 VPC Networks 页面上查找此值。
    unique-id
    您在返回项目状态时记录的唯一string 。
    org-id
    唯一的 24 位十六进制string ,用于标识Atlas组织。
  3. 将shell文件另存为 setup_psc.sh,并使用以下命令从保存文件的目录运行脚本:

    sh setup_psc.sh

    该脚本会创建一个atlasEndpoints-{endpoint-name}.json输出文件,其中包含IP地址和转发规则名称的列表。

  4. 运行以下命令以格式化Atlas Kubernetes Operator的输出:

    yq e -P atlasEndpoints-{endpoint-name}.json > atlasEndpoints-user-private-endpoint.yaml
    awk 'sub("name","endpointName")sub("IPAddress","ipAddress")' atlasEndpoints-user-private-endpoint.yaml

    输出应类似于以下示例:

    - ipAddress: 10.0.0.00
    endpointName: {endpoint-name}-0
    - ipAddress: 10.0.0.01
    endpointName: {endpoint-name}-1
    - ipAddress: 10.0.0.02
    endpointName: {endpoint-name}-2
    - ipAddress: 10.0.0.03
    endpointName: {endpoint-name}-3
    - ipAddress: 10.0.0.04
    endpointName: {endpoint-name}-4
    - ipAddress: 10.0.0.05
    endpointName: {endpoint-name}-5
4

更新spec.privateEndpoints AtlasProject自定义资源 的 参数。指定Google Cloud Platform地区Google Cloud Project IDPrivate Service Endpoint Prefix以及输出信息,然后运行以下命令:

cat <<EOF | kubectl apply -f -
apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: Test Atlas Operator Project
privateEndpoints:
- provider: "GCP"
region: "{gcp-region}"
gcpProjectId: "{project-id}"
endpointGroupName: "{endpoint-name}"
endpoints:
- ipAddress: {ip-address}
endpointName: {endpoint-name}-0
- ipAddress: {ip-address}
endpointName: {endpoint-name}-1
- ipAddress: {ip-address}
endpointName: {endpoint-name}-2
- ipAddress: {ip-address}
endpointName: {endpoint-name}-3
- ipAddress: {ip-address}
endpointName: {endpoint-name}-4
- ipAddress: {ip-address}
endpointName: {endpoint-name}-5
EOF
5

运行以下命令:

kubectl get atlasproject my-project -o yaml
6
  1. 复制以下命令:

    重要

    以下命令需要 jq 1.6 或更高版本。

    kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)';
  2. 对于自定义资源,用详细信息替换以下占位符:

    my-project
    指定AtlasProject自定义资源metadata字段的值。
    my-atlas-cluster
    指定AtlasDeployment自定义资源metadata字段的值。
    my-database-user
    指定AtlasDatabaseUser自定义资源metadata字段的值。
  3. 运行命令。

    注意

    您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如connectionStringPrivate1connectionStringPrivate2等)的connectionStringPrivateconnectionStringPrivateSvr字段。

    {
    "connectionStringPrivate": "mongodb://pl-0-eastus2.uzgh6.mongodb.net:1024,pl-0-eastus2.uzgh6.mongodb.net:1025,pl-0-eastus2.uzgh6.mongodb.net:1026/?ssl=truereplicaSet=atlas-18bndf-shard-0",
    "connectionStringPrivateSrv": "mongodb+srv://cluster0-pl-0.uzgh6.mongodb.net",
    "password": "P@@sword%",
    "username": "theuser"
    }

    您可以使用此 密钥 在您的应用程序中:

    containers:
    - name: test-app
    env:
    - name: "CONNECTION_STRING"
    valueFrom:
    secretKeyRef:
    name: my-project-my-atlas-cluster-my-database-user
    key: connectionStringPrivate

后退

私有端点

在此页面上