注意
此功能不适用于以下任何部署:
M0集群Flex 集群
Atlas Kubernetes Operator 支持管理以下平台上的专用集群的私有端点:
AWS 使用 AWS PrivateLink 功能。
使用 Azure Private Link 功能的 Azure 。
使用 Private Service Connect 功能的 Google Cloud。
开始之前,请参阅托管私有端点。
步骤
要使客户端能够使用私有端点连接到 Atlas 专用集群,请执行以下操作:
指定 spec.privateEndpoints 参数。
Specify the spec.privateEndpoints parameter for the AtlasProject Custom Resource. In the spec.privateEndpoints.provider field, specify AWS. Replace the placeholder {aws-region} with the AWS region information for your private endpoints and run the following command:
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资源。这可能需要几分钟才能完成。
查找私有端点的服务名称。
运行以下命令:
kubectl get atlasproject my-project -o yaml 请注意
AtlasProject自定义资源的status.privateEndpoints.serviceName字段中每个私有端点的服务名称字符串。
使用 Amazon Web Services CLI 配置每个私有端点。
To create your application VPC interface endpoint:
复制以下命令:
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} 将以下占位符替换为有关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使用的子网的唯一字符串。用空格分隔每个子网。在您的 AWS 账户的 Subnet仪表盘上查找这些值。
IMPORTANT: You must specify at least one subnet. If you don't, AWS won't provision a interface endpoint in your VPC. An interface endpoint is required for clients in your VPC to send traffic to the private endpoint.
使用Amazon Web Services CLI运行命令。
请注意输出中的
VpcEndpointId值。例子
"VpcEndpoint": { "VpcEndpointId": "vpce-XXXXXX", "VpcEndpointType": "Interface", "VpcId": "vpc-XXXXX", "ServiceName": "com.amazonaws.vpce.{aws-region}.vpce-svc-XXXX", "State": "pendingAcceptance",
更新 spec.privateEndpoints 参数。
Update the spec.privateEndpoints parameter for the AtlasProject Custom Resource. Specify the AWS region and replace vpce-id with the VpcEndpointId values for your private endpoints and run the following command:
注意
您可以在 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
检索 Atlas Kubernetes Operator 创建的用于连接到集群的密钥。
复制以下命令:
重要
以下命令需要
jq1.6 或更高版本。kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)'; 对于自定义资源,用详细信息替换以下占位符:
my-project指定
AtlasProject自定义资源的metadata字段的值。my-atlas-cluster指定
AtlasDeployment自定义资源的metadata字段的值。my-database-user指定
AtlasDatabaseUser自定义资源的metadata字段的值。运行命令。
注意
您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如
connectionStringPrivate1、connectionStringPrivate2等)的connectionStringPrivate和connectionStringPrivateSvr字段。{ "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
指定 spec.privateEndpoints 参数。
Specify the spec.privateEndpoints parameter for the AtlasProject Custom Resource. In the spec.privateEndpoints.provider field, specify AZURE. Replace the placeholder {azure-region} with the Azure region information for your private endpoints and run the following command:
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 资源。 这可能需要几分钟才能完成。
禁用私有端点网络策略。
Atlas 不支持私有端点的网络策略。
复制以下命令:
az network vnet subnet update --resource-group {resource-group-name} --vnet-name {vnet-name} --name {subnet-name} --disable-private-endpoint-network-policies true 将以下占位符替换为有关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 页面上找到此值。
使用Azure CLI。运行命令。
要了解更多,请参阅 Azure 文档中的 管理私有端点的网络策略 。
查找私有端点的服务 ID 和名称。
运行以下命令:
kubectl get atlasproject my-project -o yaml 请注意
AtlasProject自定义资源的status.privateEndpoints.serviceResourceId和status.privateEndpoints.serviceName字段中每个私有端点的服务资源ID和服务名称。
使用Azure CLI配置每个私有端点。
要创建私有端点,请执行以下操作:
复制以下命令:
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 将以下占位符替换为有关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字段中找到此值。使用Azure CLI。运行命令。
更新 spec.privateEndpoints 参数。
Update the spec.privateEndpoints parameter for the AtlasProject Custom Resource. Specify the the Azure region, Resource ID, and IP address information for your private endpoints and run the following command:
注意
您的 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
检索 Atlas Kubernetes Operator 创建的用于连接到集群的密钥。
复制以下命令:
重要
以下命令需要
jq1.6 或更高版本。kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)'; 对于自定义资源,用详细信息替换以下占位符:
my-project指定
AtlasProject自定义资源的metadata字段的值。my-atlas-cluster指定
AtlasDeployment自定义资源的metadata字段的值。my-database-user指定
AtlasDatabaseUser自定义资源的metadata字段的值。运行命令。
注意
您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如
connectionStringPrivate1、connectionStringPrivate2等)的connectionStringPrivate和connectionStringPrivateSvr字段。{ "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
指定 spec.privateEndpoints 参数。
为 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资源。这可能需要几分钟才能完成。
找到您的私有端点的 {unique-ID}。
运行以下命令:
kubectl get atlasproject my-project -o yaml 请注意每个服务附件名称中
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" ]
配置您的私有端点。
To edit the private endpoints and generate the necessary script with the Atlas UI, see Configure Private Endpoints.
要手动配置私有端点,请执行以下操作:
复制以下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 将以下占位符替换为有关Google Cloud Platform VPC的详细信息:
google-cloud-project-idID用于标识您的Google Cloud Platform 项目的唯一 。在Google Cloud Platform的 Dashboard 页面上查找此值。
private-service-connect-endpoint-prefix人类可读标签,为创建的所有端点添加前缀,并标识端点群组。
gcp-regionLabel that identifies the Google Cloud Platform region of the private endpoint.
subnet-name人类可读标签,用于标识您的 Google Cloud Platform VPC 中的子网。在 Google Cloud 仪表盘的 VPC Networks 页面上查找此值。
vpc-name人可读标签,用于标识您希望用于连接 Atlas 的 VPC。在 Google Cloud 仪表盘的 VPC Networks 页面上查找此值。
unique-id您在返回项目状态时记录的唯一string 。
org-idUnique 24-digit hexadecimal string that identifies the Atlas organization.
将shell文件另存为
setup_psc.sh,并使用以下命令从保存文件的目录运行脚本:sh setup_psc.sh 该脚本会创建一个
atlasEndpoints-{endpoint-name}.json输出文件,其中包含IP地址和转发规则名称的列表。运行以下命令以格式化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
更新 spec.privateEndpoints 参数。
Update the spec.privateEndpoints parameter for the AtlasProject Custom Resource. Specify the Google Cloud Platform region, Google Cloud Project ID, Private Service Endpoint Prefix, your output information, and run the following command:
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
检索 Atlas Kubernetes Operator 创建的用于连接到集群的密钥。
复制以下命令:
重要
以下命令需要
jq1.6 或更高版本。kubectl get secret {my-project}-{my-atlas-cluster}-{my-database-user} -o json | jq -r '.data | with_entries(.value |= @base64d)'; 对于自定义资源,用详细信息替换以下占位符:
my-project指定
AtlasProject自定义资源的metadata字段的值。my-atlas-cluster指定
AtlasDeployment自定义资源的metadata字段的值。my-database-user指定
AtlasDatabaseUser自定义资源的metadata字段的值。运行命令。
注意
您的连接字符串将与以下示例不同。 如果您有多个私有端点,则密钥包含多个带有相应数字后缀(例如
connectionStringPrivate1、connectionStringPrivate2等)的connectionStringPrivate和connectionStringPrivateSvr字段。{ "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