创建 VMware Engine 私有云

私有云是一种独立的 VMware 堆栈,由 ESXi 主机、vCenter、vSAN、NSX-T 和 HCX 组成。您可以通过 Google Cloud 控制台管理私有云。创建私有云时,您将获得一个单个 vSphere 集群以及在该集群中创建的所有管理虚拟机。

VMware Engine 会在您为 vSphere/vSAN 子网选择的网络中部署管理组件。在部署期间,网络 IP 地址范围被划分为不同的子网。

准备工作

在执行本页面上的任务之前,请先执行以下前提条件步骤。

vSphere/vSAN 子网地址空间不得与将会与私有云通信的任何网络(例如本地网络和 Google Cloud 虚拟私有云 (VPC) 网络)重叠。如需详细了解 vSphere 或 vSAN 子网,请参阅 VMware Engine 上的 VLAN 和子网

Google Cloud CLI 和 API 要求

如需使用 gcloud 命令行工具或 API 管理 VMware Engine 资源,我们建议您按下文所述配置工具。

gcloud

  1. 设置默认项目 ID:

    gcloud config set project PROJECT_ID
    
  2. 设置默认地区和区域:

    gcloud config set compute/region REGION
    
    gcloud config set compute/zone ZONE
    

如需详细了解 gcloud vmware 工具,请参阅 Cloud SDK 参考文档

API

本文档集中的 API 示例使用 cURL 命令行工具来查询 API。cURL 请求必须包含有效的访问令牌。您可以通过多种方式获取有效的访问令牌;以下步骤使用 gcloud 工具生成访问令牌:

  1. 登录 Google Cloud:

    gcloud auth login
    
  2. 生成访问令牌并导出到 TOKEN:

    export TOKEN=`gcloud auth print-access-token`
    
  3. 验证 TOKEN 设置是否正确:

    echo $TOKEN
    

现在,在对 API 的请求中使用授权令牌。例如:

curl -X GET -H "Authorization: Bearer \"$TOKEN\"" -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations

Python

本文档中的 Python 代码示例使用 VMware Engine 库与 API 进行通信。为了能够使用此方法,需要安装该库并配置应用默认凭据

  1. 下载并安装 Python 库:

    pip install google-cloud-vmwareengine
    
  2. 通过在 shell 中执行以下命令来配置 ADC 信息:

    gcloud auth application-default login
    

    或者,使用服务帐号密钥文件:

    export GOOGLE_APPLICATION_CREDENTIALS="FILE_PATH"
    

如需详细了解该库,请访问参考页面或查看 GitHub 上的代码示例

创建私有云

控制台

如需使用 Google Cloud 控制台创建私有云,请按以下步骤操作:

  1. 访问 Google Cloud 控制台
  2. 在主导航栏中,点击私有云
  3. 点击创建
  4. 选择您要部署私有云的位置。
  5. 为主集群选择节点类型。
  6. 选择私有云的节点数。对于生产工作负载,请创建至少包含 3 个节点的私有云。VMware Engine 会在 60 天后删除仅包含 1 个节点的私有云。
  7. 可选:如果要减少管理集群中每个节点的可用核心数,请点击自定义核心数切换开关。如需了解详情,请参阅自定义核心数
  8. 请输入 VMware 管理网络的 CIDR 范围。如需了解此范围的限制,请参阅准备工作部分。
  9. 输入 HCX 部署网络的 CIDR 范围,用于部署 HCX 组件。确保 CIDR 范围不与您的任何本地或云子网重叠。CIDR 范围必须为 /27 或更高。
  10. 点击检查并创建
  11. 查看设置。若要更改设置,请点击返回
  12. 点击创建以开始配置私有云。

以下列表更详细地介绍了私有云创建期间的每个字段:

  • 名称:私有云的永久性唯一标识符。
  • 说明:私有云详情页面上显示的其他信息。
  • 区域:VMware Engine 托管私有云的地理区域。
  • 可用区:区域的一部分,在物理上与同一区域中的其他可用区隔离。可用区是区域内的单个故障域。
  • 主要集群名称:为私有云中的初始 vSphere 集群指定的名称。您的私有云的 VMware 管理设备在此集群上运行。
  • 节点类型:主集群中节点的硬件配置。
  • 节点数:主集群中的节点数。

  • 管理 IP 地址范围 (Management IP address range):用于 vCenter Server、NSX Manager、ESXi 主机、私有云基础架构的其他部分的 IP 地址范围。此地址范围不用于工作负载虚拟机,并且不能与 VPC 网络或您打算连接到私有云的任何其他网络的任何部分重叠。
  • VMware Engine 网络:根据网络政策处理私有云连接的网络资源。您和连接到此 VMware Engine 网络的资源可以从 Google Cloud 内部访问私有云。

gcloud

如需使用 Google Cloud CLI 创建扩展私有云,请按以下步骤操作:

  1. 可选:通过运行 gcloud vmware locations list 命令列出项目的可用区域和可用区。

    gcloud vmware locations list \
        --project=PROJECT_ID
    

    替换以下内容:

    • PROJECT_ID:此请求的项目 ID
  2. 运行 gcloud vmware networks create 命令,为您的私有云创建网络。

    gcloud vmware networks create NETWORK_NAME \
        --type=LEGACY \
        --location=REGION \
        --description="DESCRIPTION"

    替换以下内容:

    • NETWORK_NAME:私有云的网络名称
    • REGION:私有云的区域
    • DESCRIPTION:私有云的说明

    该请求会返回一个操作 ID。

  3. 通过运行 gcloud vmware operations describe 命令来检查操作的状态。当操作返回 DONE 时,请检查响应以查看操作是否成功:

    gcloud vmware operations describe OPERATION_ID \
        --location REGION

    替换以下内容:

    • OPERATION_ID:上一步的 ID
    • REGION:私有云的区域
  4. 运行 gcloud vmware private-clouds create 命令来创建三节点私有云。

    gcloud vmware private-clouds create PRIVATE_CLOUD_ID \
      --location=ZONE \
      --cluster=CLUSTER_ID \
      --node-type-config=type=standard-72,count=NODE_COUNT \
      --management-range=`IP_ADDRESS` \
      --vmware-engine-network=NETWORK_NAME
    

    替换以下内容:

    • PRIVATE_CLOUD_ID:私有云的名称
    • ZONE:私有云的可用区
    • CLUSTER_ID:此私有云中新集群的名称
    • NODE_COUNT:节点数。请将值指定为 3 或更大。
    • IP_ADDRESS:此请求的 IP 地址,例如 192.168.0.0/24
    • NETWORK_NAME:此私有云的网络名称

    该请求会返回一个操作 ID,可用于检查操作的进度。

  5. 通过运行 gcloud vmware operations describe 命令来检查操作的状态。当操作返回 DONE 时,请检查响应以查看操作是否成功。

    gcloud vmware operations describe OPERATION_ID \
        --location REGION
    

    替换以下内容:

    • OPERATION_ID:上一步的 ID
    • REGION:私有云的区域
  6. 设置专用服务访问通道以将 VMware Engine 网络连接到您的 VPC。

  7. 分别运行 gcloud vmware private-clouds vcenter credentials describegcloud vmware private-clouds nsx credentials describe 命令以检索 vCenter 和 NSX-T 凭据。

    gcloud vmware private-clouds vcenter credentials describe \
        --private-cloud=PRIVATE_CLOUD_ID \
        --location=ZONE
    gcloud vmware private-clouds nsx credentials describe \
        --private-cloud=PRIVATE_CLOUD_ID \
        --location=ZONE

    替换以下内容:

    • PRIVATE_CLOUD_ID:私有云的 ID
    • ZONE:私有云的可用区

API

如需使用 VMware Engine API 创建扩展私有云,请按以下步骤操作:

  1. 通过发出 POST 请求创建旧版网络。

    curl -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/vmwareEngineNetworks?vmwareEngineNetworkId=NETWORK_NAME -d "{"type": "legacy"}"
    

    替换以下内容:

    • TOKEN:此请求的授权令牌
    • PROJECT_ID:此请求的项目
    • REGION:要在其中创建此网络的区域
    • NETWORK_NAME:私有云的网络名称

    该请求会返回一个操作 ID,可用于检查操作的进度。

  2. 请通过发出 GET 请求来检查操作的状态。当操作返回 DONE 时,请检查响应以查看操作是否成功:

    curl -X GET -H "Authorization: Bearer TOKEN"  -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/operations/OPERATION_ID
    

    OPERATION_ID 替换为上一步中的 ID。

  3. 通过发出 POST 请求来创建三节点私有云:

    curl -X POST -H "Authorization: Bearer TOKEN"  -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds?privateCloudId=PRIVATE_CLOUD_ID -d "{
    "networkConfig":{
      "vmwareEngineNetwork":"projects/PROJECT_ID/locations/REGION/vmwareEngineNetworks/NETWORK_NAME",
      "managementCidr":"10.241.0.0/22"
       },
    "managementCluster":{
      "clusterId": "CLUSTER_ID",
      "nodeTypeConfigs": {
      "standard-72": {
        "nodeCount": NODE_COUNT
       }
      }
     }
    }"
    

    替换以下内容:

    • TOKEN:此请求的授权令牌。
    • PROJECT_ID:此请求的项目 ID
    • ZONE:私有云的可用区
    • PRIVATE_CLOUD_ID:私有云的 ID
    • REGION:此私有云的网络区域
    • NETWORK_NAME:私有云的网络名称
    • CLUSTER_ID:此私有云中新集群的 ID
    • NODE_COUNT:节点数。请将值指定为 3 或更大。

    该请求会返回一个操作 ID,可用于检查操作的进度。

  4. 请通过发出 GET 请求来检查操作的状态。当操作返回 DONE 时,请检查响应以查看操作是否成功:

    curl -X GET -H "Authorization: Bearer TOKEN"  -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/operations/OPERATION_ID
    

    替换以下内容:

    • PROJECT_ID:此请求的项目 ID
    • REGION:私有云的区域
    • OPERATION_ID:上一步的 ID
  5. 设置专用服务访问通道以将 VMware Engine 网络连接到您的 VPC。

  6. 通过发出 GET 请求来检索 vCenter 和 NSX-T 凭据:

    curl -X GET -H "Authorization: Bearer \"TOKEN"\"  -H "Content-Type: application/json; charset=utf-8" "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PRIVATE_CLOUD_ID:showVcenterCredentials"
    
    curl -X GET -H "Authorization: Bearer \"TOKEN"\"  -H "Content-Type: application/json; charset=utf-8" "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PRIVATE_CLOUD_ID:showNsxCredentials"
    

    替换以下内容:

    • PROJECT_ID:此请求的项目 ID
    • ZONE:私有云的可用区
    • PRIVATE_CLOUD_ID:私有云的 ID

Python

  1. 创建旧版网络。

    from google.cloud import vmwareengine_v1
    
    TIMEOUT = 1200  # 20 minutes
    
    def create_legacy_network(
        project_id: str, region: str
    ) -> vmwareengine_v1.VmwareEngineNetwork:
        """
        Creates a new legacy network.
    
        Args:
            project_id: name of the project you want to use.
            region: name of the region you want to use. I.e. "us-central1"
    
        Returns:
            The newly created VmwareEngineNetwork object.
        """
        network = vmwareengine_v1.VmwareEngineNetwork()
        network.description = (
            "Legacy network created using vmwareengine_v1.VmwareEngineNetwork"
        )
        network.type_ = vmwareengine_v1.VmwareEngineNetwork.Type.LEGACY
    
        request = vmwareengine_v1.CreateVmwareEngineNetworkRequest()
        request.parent = f"projects/{project_id}/locations/{region}"
        request.vmware_engine_network_id = f"{region}-default"
        request.vmware_engine_network = network
    
        client = vmwareengine_v1.VmwareEngineClient()
        result = client.create_vmware_engine_network(request, timeout=TIMEOUT).result()
    
        return result
    
    
  2. 创建一个三节点私有云。

    from google.api_core import operation
    from google.cloud import vmwareengine_v1
    
    DEFAULT_MANAGEMENT_CIDR = "192.168.0.0/24"
    DEFAULT_NODE_COUNT = 3
    
    def create_private_cloud(
        project_id: str, zone: str, network_name: str, cloud_name: str, cluster_name: str
    ) -> operation.Operation:
        """
        Creates a new Private Cloud using VMWare Engine.
    
        Creating a new Private Cloud is a long-running operation and it may take over an hour.
    
        Args:
            project_id: name of the project you want to use.
            zone: the zone you want to use, i.e. "us-central1-a"
            network_name: name of the VMWareNetwork to use for the new Private Cloud
            cloud_name: name of the new Private Cloud
            cluster_name: name for the new cluster in this Private Cloud
    
        Returns:
            An operation object representing the started operation. You can call its .result() method to wait for it to finish.
        """
        request = vmwareengine_v1.CreatePrivateCloudRequest()
        request.parent = f"projects/{project_id}/locations/{zone}"
        request.private_cloud_id = cloud_name
    
        request.private_cloud = vmwareengine_v1.PrivateCloud()
        request.private_cloud.management_cluster = (
            vmwareengine_v1.PrivateCloud.ManagementCluster()
        )
        request.private_cloud.management_cluster.cluster_id = cluster_name
    
        node_config = vmwareengine_v1.NodeTypeConfig()
        node_config.node_count = DEFAULT_NODE_COUNT
    
        # Currently standard-72 is the only supported node type.
        request.private_cloud.management_cluster.node_type_configs = {
            "standard-72": node_config
        }
    
        request.private_cloud.network_config = vmwareengine_v1.NetworkConfig()
        request.private_cloud.network_config.vmware_engine_network = network_name
        request.private_cloud.network_config.management_cidr = DEFAULT_MANAGEMENT_CIDR
    
        client = vmwareengine_v1.VmwareEngineClient()
        return client.create_private_cloud(request)
    
    

    create_private_cloud 函数会返回一个操作对象,您可以使用该对象检查操作的进度。

  3. 查看操作的状态。提取有关操作的最新信息。

    from google.cloud import vmwareengine_v1
    from google.longrunning.operations_pb2 import GetOperationRequest
    
    def get_operation_by_name(operation_name: str) -> Operation:
        """
        Retrieve detailed information about an operation.
    
        Args:
            operation_name: name identifying an operation you want to check.
                Expected format: projects/{project_id}/locations/{region}/operations/{operation_id}
    
        Returns:
            Operation object with details.
        """
        client = vmwareengine_v1.VmwareEngineClient()
        request = GetOperationRequest()
        request.name = operation_name
        return client.get_operation(request)
    
    def get_operation(project_id: str, region: str, operation_id: str) -> Operation:
        """
        Retrieve detailed information about an operation.
    
        Args:
            project_id: name of the project running the operation.
            region: name of the region in which the operation is running.
            operation_id: identifier of the operation.
    
        Returns:
            Operation object with details.
        """
        return get_operation_by_name(
            f"projects/{project_id}/locations/{region}/operations/{operation_id}"
        )
    
    

    您可以使用操作对象的 .result() 成员方法来等待它完成。

  4. 设置专用服务访问通道以将 VMware Engine 网络连接到您的 VPC。

  5. 检索 vCenter 和 NSX-T 凭据。

    from google.cloud import vmwareengine_v1
    
    def get_vcenter_credentials(
        project_id: str, zone: str, private_cloud_name: str
    ) -> vmwareengine_v1.Credentials:
        """
        Retrieves VCenter credentials for a Private Cloud.
    
        Args:
            project_id: name of the project hosting the private cloud.
            zone: name of the zone hosting the private cloud.
            private_cloud_name: name of the private cloud.
    
        Returns:
            A Credentials object.
        """
        client = vmwareengine_v1.VmwareEngineClient()
        credentials = client.show_vcenter_credentials(
            private_cloud=f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
        )
        return credentials
    
    
    from google.cloud import vmwareengine_v1
    
    def get_nsx_credentials(
        project_id: str, zone: str, private_cloud_name: str
    ) -> vmwareengine_v1.Credentials:
        """
        Retrieves NSX credentials for a Private Cloud.
    
        Args:
            project_id: name of the project hosting the private cloud.
            zone: name of the zone hosting the private cloud.
            private_cloud_name: name of the private cloud.
    
        Returns:
            A Credentials object.
        """
        client = vmwareengine_v1.VmwareEngineClient()
        credentials = client.show_nsx_credentials(
            private_cloud=f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
        )
        return credentials
    
    

在创建新的私有云时,VMware Engine 会部署多个 VMware 组件,并将提供的 IP 地址范围划分为多个子网。创建私有云可能需要 30 分钟到 2 小时。预配完成后,您会收到一封电子邮件。

后续步骤