建立 VMware Engine 私人雲端

私有雲是指由 ESXi 主機、vCenter、vSAN、NSX-T 和 HCX 組成的隔離 VMware 堆疊。您可以透過Google Cloud 主控台管理私有雲。建立私有雲時,您會取得單一 vSphere 叢集,以及在該叢集中建立的所有管理 VM。

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 控制台的「Private clouds」頁面。

    前往 Private Cloud

  2. 按一下「選取專案」,然後選取要建立私有雲端的機構、資料夾或專案。

  3. 按一下 [建立]。

  4. 輸入私有雲的名稱。

  5. 在私有雲類型中選取「標準私有雲」

  6. 選取要部署私有雲的位置。

  7. 輸入主要叢集的名稱。

  8. 選取主要叢集的節點類型。

  9. 選取私有雲的節點數量。如要建立實際工作環境工作負載的私有雲,請至少建立 3 個節點。VMware Engine 會在 60 天後刪除僅包含 1 個節點的私有雲。

  10. 選用:如要減少管理叢集中每個節點的可用核心數,請按一下「Customize Cores」切換鈕。詳情請參閱「自訂核心數量」。

  11. 請輸入 VMware 管理網路的 CIDR 範圍,如要瞭解這個範圍的限制,請參閱「事前準備」一節。

  12. 按一下「查看並建立」

  13. 查看設定。如要變更任何設定,請按一下「返回」

  14. 按一下「Create」,開始佈建私有雲。

以下清單將詳細說明建立私有雲時的各個欄位:

  • 名稱:私有雲的永久專屬 ID。
  • 說明:私有雲詳細資料頁面上顯示的其他資訊。
  • 區域: VMware Engine 代管私有雲端的區域。
  • 可用區:區域的子集,與同區域內其他可用區實體隔離。區域是區域內的單一故障網域。
  • 主要叢集名稱:私有雲端中初始 vSphere 叢集的名稱。私有雲的 VMware 管理設備會在這個叢集中執行。
  • 節點類型:主要叢集中節點的硬體設定。
  • 節點:主要叢集中的節點數量。

  • 管理 IP 位址範圍:用於 vCenter Server、NSX Manager、ESXi 主機和私有雲基礎架構的其他部分的 IP 位址範圍。這個範圍不適用於工作負載 VM,且不得與 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=NODE_TYPE,count=NODE_COUNT \
      --management-range=`IP_ADDRESS` \
      --vmware-engine-network=NETWORK_NAME
    

    更改下列內容:

    • PRIVATE_CLOUD_ID:私有雲的名稱。
    • ZONE:私有雲的區域。
    • CLUSTER_ID:這個私有雲端中的新叢集名稱。
    • NODE_TYPE:節點類型。詳情請參閱「節點類型」。
    • NODE_COUNT:節點數。指定三個或以上的值。
    • IP_ADDRESS:此要求的 IP 位址,例如 192.168.0.0/24
    • NETWORK_NAME:此雲端的網路名稱。

    要求會傳回作業 ID,您可以使用這組 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,您可以使用這組 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:節點數。指定三個或以上的值。

    要求會傳回作業 ID,您可以使用這組 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 小時。佈建完成後,您會收到電子郵件。

後續步驟