管理私有云资源和活动

创建私有云后,您可以查看其相关详细信息、管理其资源和活动以及访问其 VMwae 管理设备。每个私有云包含一个或多个集群,每个集群包含与 ESXi 主机对应的节点。

为私有云中的集群定义的自动扩缩政策会监控资源用量,并自动在集群中添加或移除节点。您还可以通过在私有云的集群中添加或移除节点来手动扩展或缩小私有云。例如,您可以根据当前需求创建私有云,然后在消耗增加时通过添加节点来扩展私有云。

如需查看私有云列表,请先访问其资源摘要页面:

  1. 访问 Google Cloud VMware Engine 门户
  2. 从主导航栏中,转到资源
  3. 从私有云列表中选择要管理的私有云。

gcloud 和 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
    
    Output:
    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 上的代码示例

验证 IP 地址布局版本

2022 年 11 月之后创建的私有云遵循 IP 地址布局(IP 方案)2.0 版子网分配。2022 年 11 月之前创建的几乎所有私有云都遵循 IP 方案 1.0 版子网分配。

如需了解您的私有云遵守的版本,请完成以下步骤:

  1. 访问 Google Cloud VMware Engine 门户
  2. 资源页面上,点击摘要

版本号显示在 IP 方案版本中。

查看私有云摘要

该摘要提供有关您的私有云的信息,包括其名称、vSphere 集群的数量、节点数、位置、操作状态等。该摘要页面还包含部署在私有云上的 DNS 服务器。

在私有云摘要页面上,您可以执行以下操作:

向私有云添加节点

私有云由一个或多个 vSphere 集群组成,每个集群包含多个节点。向私有云添加节点时,可将节点添加到现有集群或创建新集群。私有云可以多次扩展,前提是不超过总体节点限制。每次扩展私有云时,您都会向现有集群添加节点或创建新集群。

在新集群配置中,Google 会配置 VMware 基础架构。设置包括 vSAN 磁盘组、VMware 高可用性和分布式资源调度器 (DRS) 的存储设置。

如需向私有云添加节点,请执行以下操作:

控制台

  1. 在私有云摘要页面上,点击添加节点
  2. 选择是向现有集群添加节点,还是创建新的 vSphere 集群。当您做出更改时,页面上的摘要信息将会更新。
  3. 如需向现有集群添加节点,请选择向现有集群添加节点。选择要扩展的集群,然后输入要添加的节点数量。
  4. 如需添加新集群,请选择新建。然后,提供以下详细信息:
    1. 输入集群的名称。
    2. 选择现有 vSphere 数据中心或输入名称创建新的数据中心。
    3. 选择节点数。每个新集群必须至少有三个节点。
    4. 可选:如果要减少管理集群中每个节点的可用核心数,请点击自定义核心数切换开关。如需了解详情,请参阅自定义核心数
  5. 点击提交

gcloud

您可以使用更新命令来更改集群的总节点数。此命令需要集群和私有云的名称。

  1. 列出集群。

    gcloud vmware private-clouds clusters list \
     --private-cloud=PC_NAME \
     --location=ZONE
  2. 更新集群。例如,以下命令将节点数更改为 4。

    gcloud vmware private-clouds clusters update CLUSTER_NAME \
    --location=ZONE \
    --private-cloud=PC_NAME --node-type-config=type=standard-72,count=4

    替换以下内容:

    • CLUSTER_NAME:此私有云中要更新的集群的名称
    • ZONE:私有云的可用区
    • PC_NAME:私有云的名称
    • PROJECT_ID:此请求的项目 ID

API

您可以使用更新 API 来更改集群的总节点数。此命令需要集群和私有云的名称。

  1. 列出集群。

    curl -L -X GET -H "Authorization: Bearer TOKEN" "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/clusters"
    
  2. 更新集群。例如,以下命令将集群更新为 standard-72 并将节点数更改为 4。

    curl -L -X PATCH -H "Authorization: Bearer TOKEN" \
    -H "Content-Type: application/json" \
    "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/clusters/CLUSTER_NAME?updateMask=node_type_configs.*.node_count" \
    -d '{
    "nodeTypeConfigs": {
      "standard-72" : {
        "nodeCount": 4
      }
    }
    }'

    替换以下内容:

    • PROJECT_ID:此请求的项目 ID
    • ZONE:私有云的可用区
    • PC_NAME:私有云的名称
    • CLUSTER_NAME:此私有云中要更新的集群的名称

Python

通过集群更新方法,您可以更改集群的总节点数。此方法需要集群和私有云的名称。

  1. 列出集群。
from typing import Iterable

from google.cloud import vmwareengine_v1

def list_clusters(
    project_id: str, zone: str, private_cloud_name: str
) -> Iterable[vmwareengine_v1.Cluster]:
    """
    Retrieves a list of clusters in private cloud.

    Args:
        project_id: name of the project hosting the private cloud.
        zone: zone in which the private cloud is located.
        private_cloud_name: name of the cloud of which you want to list cluster.

    Returns:
        An iterable collection of Cluster objects.
    """
    client = vmwareengine_v1.VmwareEngineClient()
    return client.list_clusters(
        parent=f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
    )

  1. 更新集群。以下方法允许您修改集群中的 standard-72 节点数量。
from google.api_core import operation
from google.cloud import vmwareengine_v1

def update_cluster_node_count(
    project_id: str,
    zone: str,
    private_cloud_name: str,
    cluster_name: str,
    node_count: int,
) -> operation.Operation:
    """
    Modify the number of nodes in a cluster in a private cloud.

    Modifying a cluster is a long-running operation and it may take over an hour.

    Args:
        project_id: name of the project you want to use.
        zone: zone in which your private cloud is located.
        private_cloud_name: name of the private cloud hosting the cluster.
        cluster_name: name of the cluster.
        node_count: desired number of nodes in the cluster.

    Returns:
        An Operation object related to cluster modification operation.
    """
    if node_count < 3:
        raise RuntimeError("Cluster needs to have at least 3 nodes")
    client = vmwareengine_v1.VmwareEngineClient()
    request = vmwareengine_v1.UpdateClusterRequest()
    request.cluster = vmwareengine_v1.Cluster()
    request.cluster.name = (
        f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
        f"/clusters/{cluster_name}"
    )
    request.cluster.node_type_configs = {
        "standard-72": vmwareengine_v1.NodeTypeConfig()
    }
    request.cluster.node_type_configs["standard-72"].node_count = node_count
    request.update_mask = "nodeTypeConfigs.*.nodeCount"
    return client.update_cluster(request)

向私有云添加新集群

如需向现有私有云添加新集群,请执行以下操作:

gcloud

添加新集群并为其命名。例如:

gcloud vmware private-clouds clusters create CLUSTER_NAME \
   --location=ZONE --private-cloud=PC_NAME \
   --node-type-config=type=standard-72,count=4

API

添加新集群并为其命名。例如:

curl -L -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" \
"https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/clusters?clusterId=CLUSTER_NAME" \
-d '{
  "nodeTypeConfigs": {
    "standard-72": {
      "nodeCount": 4
      }
  }
}'

Python

添加新集群并为其命名。

from google.api_core import operation
from google.cloud import vmwareengine_v1

def create_cluster(
    project_id: str,
    zone: str,
    private_cloud_name: str,
    cluster_name: str,
    node_count: int = 4,
) -> operation.Operation:
    """
    Create a new cluster in a private cloud.

    Creation of a new cluster is a long-running operation and it may take over an hour.

    Args:
        project_id: name of the project you want to use.
        zone: region in which your private cloud is located.
        private_cloud_name: name of the private cloud hosting the new cluster.
        cluster_name: name of the new cluster.
        node_count: number of nodes in the new cluster. (Must be >= 3)

    Returns:
        An Operation object related to started cluster creation operation.

    Raises:
        ValueError in case an incorrect number of nodes is provided.
    """
    if node_count < 3:
        raise ValueError("Cluster needs to have at least 3 nodes")

    request = vmwareengine_v1.CreateClusterRequest()
    request.parent = (
        f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
    )

    request.cluster = vmwareengine_v1.Cluster()
    request.cluster.name = cluster_name

    # Currently standard-72 is the only supported node type.
    request.cluster.node_type_configs = {
        "standard-72": vmwareengine_v1.NodeTypeConfig()
    }
    request.cluster.node_type_configs["standard-72"].node_count = node_count

    client = vmwareengine_v1.VmwareEngineClient()
    return client.create_cluster(request)

创建具有自定义核心数配置的新集群

如需创建具有自定义核心数配置的新集群,请执行以下操作:

gcloud

添加新集群并指定核心数配置。例如,以下命令会创建 standard-72 节点类型的新集群,其中包含 3 个节点且自定义核心数为 28。

gcloud vmware private-clouds clusters create CLUSTER_NAME \
    --location=ZONE \
    --private-cloud=PC_NAME \
    --node-type-config=type=standard-72,count=4,custom-core-count=28

API

添加新集群并指定核心数配置。例如,以下命令会创建 standard-72 节点类型的新集群,其中包含 4 个节点且自定义核心数为 28。

curl -L -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" \
"https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PROJECT_ID/clusters?clusterId=CLUSTER_NAME" \
-d '{
      "nodeTypeConfigs": {
      "standard-72": {
        "nodeCount": 4,
        "customCoreCount": 28
        }
    }
}'

Python

添加新集群并指定核心数配置。例如,以下命令会创建 standard-72 节点类型的新集群,其中包含可配置的节点数和核心数。

from google.api_core import operation
from google.cloud import vmwareengine_v1

def create_custom_cluster(
    project_id: str,
    zone: str,
    private_cloud_name: str,
    cluster_name: str,
    node_count: int = 4,
    core_count: int = 28,
) -> operation.Operation:
    """
    Create a new cluster with custom number of cores in its nodes
    in a private cloud.

    Creation of a new cluster is a long-running operation and it may take over an hour.

    Args:
        project_id: name of the project you want to use.
        zone: region in which your private cloud is located.
        private_cloud_name: name of the private cloud hosting the new cluster.
        cluster_name: name of the new cluster.
        node_count: number of nodes in the new cluster.
        core_count: number of CPU cores in the new cluster nodes.

    Returns:
        An Operation object related to started cluster creation operation.

    Raises:
        ValueError in case an incorrect number of nodes is provided.
    """
    if node_count < 3:
        raise ValueError("Cluster needs to have at least 3 nodes")

    request = vmwareengine_v1.CreateClusterRequest()
    request.parent = (
        f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
    )

    request.cluster = vmwareengine_v1.Cluster()
    request.cluster.name = cluster_name

    # Currently standard-72 is the only supported node type.
    request.cluster.node_type_configs = {
        "standard-72": vmwareengine_v1.NodeTypeConfig()
    }
    request.cluster.node_type_configs["standard-72"].node_count = node_count
    request.cluster.node_type_configs["standard-72"].custom_core_count = core_count

    client = vmwareengine_v1.VmwareEngineClient()
    return client.create_cluster(request)

移除节点或删除集群

从私有云中移除节点时,可以从现有集群中移除节点或删除整个集群。

如需从私有云中移除节点,请使用少量节点更新集群。

控制台

  1. 在私有云摘要页面上,点击移除节点
  2. 选择要收缩或删除的集群。
  3. 选择移除一个节点
  4. 验证集群容量。
  5. 点击提交以开始移除节点。

如需监控进度,请选择活动>任务。此过程需要在 vSAN 中重新同步,此过程可能需要数小时,具体取决于数据。

gcloud

gcloud vmware private-clouds clusters update CLUSTER_NAME \
  --location=ZONE \
  --private-cloud=PC_NAME --node-type-config=type=standard-72,count=3

API

curl -L -X PATCH -H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
"https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/clusters/CLUSTER_NAME?update_mask=node_type_configs.*.node_count" \
-d '{
  "nodeTypeConfigs": {
    "standard-72" : {
      "nodeCount": 3
    }
  }
}'

Python

from google.api_core import operation
from google.cloud import vmwareengine_v1

def update_cluster_node_count(
    project_id: str,
    zone: str,
    private_cloud_name: str,
    cluster_name: str,
    node_count: int,
) -> operation.Operation:
    """
    Modify the number of nodes in a cluster in a private cloud.

    Modifying a cluster is a long-running operation and it may take over an hour.

    Args:
        project_id: name of the project you want to use.
        zone: zone in which your private cloud is located.
        private_cloud_name: name of the private cloud hosting the cluster.
        cluster_name: name of the cluster.
        node_count: desired number of nodes in the cluster.

    Returns:
        An Operation object related to cluster modification operation.
    """
    if node_count < 3:
        raise RuntimeError("Cluster needs to have at least 3 nodes")
    client = vmwareengine_v1.VmwareEngineClient()
    request = vmwareengine_v1.UpdateClusterRequest()
    request.cluster = vmwareengine_v1.Cluster()
    request.cluster.name = (
        f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
        f"/clusters/{cluster_name}"
    )
    request.cluster.node_type_configs = {
        "standard-72": vmwareengine_v1.NodeTypeConfig()
    }
    request.cluster.node_type_configs["standard-72"].node_count = node_count
    request.update_mask = "nodeTypeConfigs.*.nodeCount"
    return client.update_cluster(request)

如需删除整个集群,请执行以下操作:

控制台

  1. 在私有云摘要页面上,点击移除节点
  2. 选择要收缩或删除的集群。
  3. 选择删除整个集群
  4. 验证集群容量。
  5. 点击提交以开始移除节点。

gcloud

gcloud vmware private-clouds clusters delete CLUSTER_NAME \
  --location=ZONE \
  --private-cloud=PC_NAME

API

curl -L -X DELETE -H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
"https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/clusters/CLUSTER_NAME"

Python

from google.api_core import operation
from google.cloud import vmwareengine_v1

def delete_cluster(
    project_id: str, zone: str, private_cloud_name: str, cluster_name: str
) -> operation.Operation:
    """
    Delete a cluster from private cloud.

    Deleting a cluster is a long-running operation and it may take over an hour..

    Args:
        project_id: name of the project you want to use.
        zone: region in which your private cloud is located.
        private_cloud_name: name of the private cloud hosting the new cluster.
        cluster_name: name of the new cluster.

    Returns:
        An Operation object related to started cluster deletion operation.
    """
    client = vmwareengine_v1.VmwareEngineClient()
    request = vmwareengine_v1.DeleteClusterRequest()
    request.name = (
        f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
        f"/clusters/{cluster_name}"
    )
    return client.delete_cluster(request)

限制

从私有云中移除节点的过程具有以下限制:

  • vSphere 集群必须至少有三个节点。如果集群只有三个或更少的节点,您无法从集群中移除节点。
  • 从集群中移除节点后,使用的总存储空间不能超过总容量。
  • 您无法删除创建私有云时创建的第一个集群。
  • 如果将 vSphere DRS 规则(亲和性和反亲和性)应用于集群的所有节点,则无法从集群中移除节点。您可以删除这些规则,然后重试节点移除操作。

查看子网

如需查看专用云定义的管理子网列表,请选择子网标签页。该列表包含创建私有云时创建的 HCX 子网。子网列表还包含每个子网的关联防火墙表

查看活动信息

如需查看私有云的活动信息,请选择活动标签页。显示的信息是私有云的所有活动的过滤列表。此页面最多可显示 25 个近期活动。如需查看活动和相关操作的完整列表,请参阅监控 VMware Engine 活动

查看 vSphere 管理网络

如需查看您的私有云上当前配置的 VMware 管理资源和虚拟机列表,请选择 vSphere 管理网络标签页。信息包括软件版本、完全限定域名 (FQDN) 以及资源的 IP 地址。