创建 Hyperdisk 存储池


Hyperdisk 存储池是一种新的块存储资源,可帮助您以汇总方式管理 Hyperdisk 块存储。Hyperdisk 存储池在 Hyperdisk Throughput 存储池和 Hyperdisk Balanced 存储池变体中提供。

创建存储池时,您必须指定以下属性:

  • 可用区
  • 存储池类型
  • 容量预配类型
  • 池预配的容量
  • 性能预配类型
  • 池预配的 IOPS 和吞吐量

您可以将标准容量、高级容量、标准性能或高级性能预配类型与 Hyperdisk 存储池搭配使用:

  • 标准容量:为存储池中创建的每个磁盘预配的容量会从存储池的总预配容量中扣除。
  • 高级容量:存储池受益于精简预配和数据缩减。系统只会从存储池的总预配容量中扣减实际写入的数据量。
  • 标准性能:为存储池中创建的每个磁盘预配的性能会从存储池的总预配性能中扣除。
  • 高级性能:为每个磁盘预配的性能受益于精简预配。只有磁盘使用的性能量才会从存储池的总预配性能中扣减。

    准备工作

    • 如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以选择以下任一选项向 Compute Engine 进行身份验证:

      Select the tab for how you plan to use the samples on this page:

      Console

      When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

      gcloud

      1. Install the Google Cloud CLI, then initialize it by running the following command:

        gcloud init
      2. Set a default region and zone.
      3. Go

        如需在本地开发环境中使用本页面上的 Go 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。

        1. Install the Google Cloud CLI.
        2. To initialize the gcloud CLI, run the following command:

          gcloud init
        3. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

        如需了解详情,请参阅 Set up authentication for a local development environment

        Java

        如需在本地开发环境中使用本页面上的 Java 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。

        1. Install the Google Cloud CLI.
        2. To initialize the gcloud CLI, run the following command:

          gcloud init
        3. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

        如需了解详情,请参阅 Set up authentication for a local development environment

        Node.js

        如需在本地开发环境中使用本页面上的 Node.js 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。

        1. Install the Google Cloud CLI.
        2. To initialize the gcloud CLI, run the following command:

          gcloud init
        3. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

        如需了解详情,请参阅 Set up authentication for a local development environment

        REST

        如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。

          Install the Google Cloud CLI, then initialize it by running the following command:

          gcloud init

        如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证

    所需的角色和权限

    如需获得创建存储池所需的权限,请让管理员向您授予项目的以下 IAM 角色:

    • Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1)
    • 若要连接到能够以服务账号的身份运行的虚拟机实例:Service Account User (v1)(roles/iam.serviceAccountUser 角色)

    如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    这些预定义角色包含创建存储池所需的权限。如需查看所需的确切权限,请展开所需权限部分:

    所需权限

    创建存储池需要以下权限:

    • 针对项目的 compute.storagePools.create 权限
    • 针对项目的 compute.storagePools.setLabels 权限

    您也可以使用自定义角色或其他预定义角色来获取这些权限。

    限制

    创建 Hyperdisk 存储池时,请注意以下限制:

    资源限制

    • 您可以创建预配容量高达 1 PiB 的 Hyperdisk 存储池。
    • 您每小时最多可以创建 5 个存储池。
    • 您每天最多可以创建 10 个存储池。
    • 您最多可以为每个项目创建 10 个存储池。
    • 您无法更改池的预配模型;您无法将标准容量存储池更改为高级容量存储池,也无法将高级性能存储池更改为标准性能存储池。
    • 存储池是可用区级资源。
    • 您最多可以在一个存储池中创建 1,000 个磁盘。
    • 您只能将 Hyperdisk 存储池与 Compute Engine 搭配使用。Cloud SQL 实例无法使用 Hyperdisk 存储池。
    • 在 24 小时内,您最多可以更改两次存储池的预配容量或性能。

    存储池中的磁盘限制

    • 只能在存储池中创建位于同一项目和同一可用区的新磁盘。
    • 不允许将磁盘移入或移出存储池。如需将磁盘移入或移出存储池,您必须通过快照重新创建磁盘。如需了解详情,请参阅更改磁盘类型
    • 如需在存储池中创建启动磁盘,您必须使用 Hyperdisk Balanced 存储池。
    • 存储池不支持区域级磁盘
    • 您无法对存储池中的磁盘进行克隆创建即时快照配置永久性磁盘异步复制等操作。
    • 存储池中的 Hyperdisk Balanced 磁盘无法挂接到多个计算实例。

    容量范围和预配的性能限制

    创建存储池时,预配的容量、IOPS 和吞吐量受到存储池限制中所述的约束。

    创建 Hyperdisk 存储池

    如需创建新的 Hyperdisk 存储池,请使用 Google Cloud 控制台、Google Cloud CLI 或 REST。

    控制台

    1. 转到 Google Cloud 控制台中的创建存储池页面。
      转到“创建存储池”页面
    2. 名称字段中,为存储池输入具有唯一性的名称。
    3. 可选:在说明字段中,输入存储池的说明。
    4. 选择要在其中创建存储池的区域可用区
    5. 存储池类型选择一个值。
    6. 容量类型字段中选择预配类型,然后在存储池容量字段中指定要为存储池预配的容量。您可以指定 10 TiB 到 1 PiB 的大小。

      如需创建容量较大的存储池,您可能需要申请更高的配额

    7. 效果类型字段中选择预配类型。

    8. 对于 Hyperdisk Balanced 存储池,在预配 IOPS 字段中,输入要为存储池预配的 IOPS。

    9. 对于 Hyperdisk Throughput 存储池或 Hyperdisk Balanced 存储池,在预配吞吐量字段中,输入要为存储池预配的吞吐量。

    10. 点击提交以创建存储池。

    gcloud

    如需创建 Hyperdisk 存储池,请使用 gcloud compute storage-pools create 命令

    gcloud compute storage-pools create NAME  \
        --zone=ZONE   \
        --storage-pool-type=STORAGE_POOL_TYPE   \
        --capacity-provisioning-type=CAPACITY_TYPE \
        --provisioned-capacity=POOL_CAPACITY   \
        --performance-provisioning-type=PERFORMANCE_TYPE \
        --provisioned-iops=IOPS   \
        --provisioned-throughput=THROUGHPUT   \
        --description=DESCRIPTION
    

    替换以下内容:

    • NAME:具有唯一性的存储池名称。
    • ZONE:要在其中创建存储池的可用区,例如 us-central1-a
    • STORAGE_POOL_TYPE:要存储在存储池中的磁盘类型。允许的值包括 hyperdisk-throughputhyperdisk-balanced
    • CAPACITY_TYPE:可选:存储池的容量预配类型。允许的值包括 advancedstandard。如果未指定,则系统会使用值 advanced
    • POOL_CAPACITY:要为新存储池预配的总容量,默认以 GiB 为单位。
    • PERFORMANCE_TYPE:可选:存储池的性能预配类型。允许的值包括 advancedstandard。如果未指定,则系统会使用值 advanced
    • IOPS:要为存储池预配的 IOPS。此标志只能用于 Hyperdisk Balanced 存储池。
    • THROUGHPUT:要为存储池预配的吞吐量(以 MBps 为单位)。
    • DESCRIPTION:可选:描述存储池的文本字符串。

    REST

    使用 storagePools.insert 方法构建 POST 请求以创建 Hyperdisk 存储池。

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/storagePools
    
    {
        "name": "NAME",
        "description": "DESCRIPTION",
        "poolProvisionedCapacityGb": "POOL_CAPACITY",
        "storagePoolType": "projects/PROJECT_ID/zones/ZONE/storagePoolTypes/STORAGE_POOL_TYPE",
        "poolProvisionedIops": "IOPS",
        "poolProvisionedThroughput": "THROUGHPUT",
        "capacityProvisioningType": "CAPACITY_TYPE",
        "performanceProvisioningType": "PERFORMANCE_TYPE"
    }
    

    替换以下内容:

    • PROJECT_ID:项目 ID
    • ZONE:要在其中创建存储池的可用区,例如 us-central1-a
    • NAME:存储池具有唯一性的名称。
    • DESCRIPTION:可选:描述存储池的文本字符串。
    • POOL_CAPACITY:要为新存储池预配的总容量,默认以 GiB 为单位。
    • STORAGE_POOL_TYPE:要存储在存储池中的磁盘类型。允许的值包括 hyperdisk-throughputhyperdisk-balanced
    • IOPS:可选:要为存储池预配的 IOPS。此标志只能用于 Hyperdisk Balanced 存储池。
    • THROUGHPUT:可选:要为存储池预配的吞吐量(以 MBps 为单位)。
    • CAPACITY_TYPE:可选:存储池的容量预配类型。允许的值包括 advancedstandard。如果未指定,则系统会使用值 advanced
    • PERFORMANCE_TYPE:可选:存储池的性能预配类型。允许的值包括 advancedstandard。如果未指定,则系统会使用值 advanced

    Go

    
    // createHyperdiskStoragePool creates a new Hyperdisk storage pool in the specified project and zone.
    func createHyperdiskStoragePool(w io.Writer, projectId, zone, storagePoolName, storagePoolType string) error {
    	// projectID := "your_project_id"
    	// zone := "europe-west4-b"
    	// storagePoolName := "your_storage_pool_name"
    	// storagePoolType := "projects/**your_project_id**/zones/europe-west4-b/diskTypes/hyperdisk-balanced"
    
    	ctx := context.Background()
    	client, err := compute.NewStoragePoolsRESTClient(ctx)
    	if err != nil {
    		return fmt.Errorf("NewStoragePoolsRESTClient: %v", err)
    	}
    	defer client.Close()
    
    	// Create the storage pool resource
    	resource := &computepb.StoragePool{
    		Name:                        proto.String(storagePoolName),
    		Zone:                        proto.String(zone),
    		StoragePoolType:             proto.String(storagePoolType),
    		CapacityProvisioningType:    proto.String("advanced"),
    		PerformanceProvisioningType: proto.String("advanced"),
    		PoolProvisionedCapacityGb:   proto.Int64(10240),
    		PoolProvisionedIops:         proto.Int64(10000),
    		PoolProvisionedThroughput:   proto.Int64(1024),
    	}
    
    	// Create the insert storage pool request
    	req := &computepb.InsertStoragePoolRequest{
    		Project:             projectId,
    		Zone:                zone,
    		StoragePoolResource: resource,
    	}
    
    	// Send the insert storage pool request
    	op, err := client.Insert(ctx, req)
    	if err != nil {
    		return fmt.Errorf("Insert storage pool request failed: %v", err)
    	}
    
    	// Wait for the insert storage pool operation to complete
    	if err = op.Wait(ctx); err != nil {
    		return fmt.Errorf("unable to wait for the operation: %w", err)
    	}
    
    	// Retrieve and return the created storage pool
    	storagePool, err := client.Get(ctx, &computepb.GetStoragePoolRequest{
    		Project:     projectId,
    		Zone:        zone,
    		StoragePool: storagePoolName,
    	})
    	if err != nil {
    		return fmt.Errorf("Get storage pool request failed: %v", err)
    	}
    
    	fmt.Fprintf(w, "Hyperdisk Storage Pool created: %v\n", storagePool.GetName())
    	return nil
    }
    

    Java

    import com.google.cloud.compute.v1.InsertStoragePoolRequest;
    import com.google.cloud.compute.v1.Operation;
    import com.google.cloud.compute.v1.StoragePool;
    import com.google.cloud.compute.v1.StoragePoolsClient;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeUnit;
    import java.util.concurrent.TimeoutException;
    
    public class CreateHyperdiskStoragePool {
      public static void main(String[] args)
              throws IOException, ExecutionException, InterruptedException, TimeoutException {
        // TODO(developer): Replace these variables before running the sample.
        // Project ID or project number of the Google Cloud project you want to use.
        String projectId = "YOUR_PROJECT_ID";
        // Name of the zone in which you want to create the storagePool.
        String zone = "us-central1-a";
        // Name of the storagePool you want to create.
        String storagePoolName = "YOUR_STORAGE_POOL_NAME";
        // The type of disk you want to create.
        // Storage types can be "hyperdisk-throughput" or "hyperdisk-balanced"
        String storagePoolType = String.format(
            "projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced", projectId, zone);
        // Optional: the capacity provisioning type of the storage pool.
        // The allowed values are advanced and standard. If not specified, the value advanced is used.
        String capacityProvisioningType = "advanced";
        // The total capacity to provision for the new storage pool, specified in GiB by default.
        long provisionedCapacity = 128;
        // the IOPS to provision for the storage pool.
        // You can use this flag only with Hyperdisk Balanced Storage Pools.
        long provisionedIops = 3000;
        // the throughput in MBps to provision for the storage pool.
        long provisionedThroughput = 140;
        // The allowed values are low-casing strings "advanced" and "standard".
        // If not specified, "advanced" is used.
        String performanceProvisioningType = "advanced";
    
        createHyperdiskStoragePool(projectId, zone, storagePoolName, storagePoolType,
                capacityProvisioningType, provisionedCapacity, provisionedIops,
            provisionedThroughput, performanceProvisioningType);
      }
    
      // Creates a hyperdisk storagePool in a project
      public static StoragePool createHyperdiskStoragePool(String projectId, String zone,
            String storagePoolName, String storagePoolType, String capacityProvisioningType,
            long capacity, long iops, long throughput, String performanceProvisioningType)
              throws IOException, ExecutionException, InterruptedException, TimeoutException {
        // Initialize client that will be used to send requests. This client only needs to be created
        // once, and can be reused for multiple requests.
        try (StoragePoolsClient client = StoragePoolsClient.create()) {
          // Create a storagePool.
          StoragePool resource = StoragePool.newBuilder()
                  .setZone(zone)
                  .setName(storagePoolName)
                  .setStoragePoolType(storagePoolType)
                  .setCapacityProvisioningType(capacityProvisioningType)
                  .setPoolProvisionedCapacityGb(capacity)
                  .setPoolProvisionedIops(iops)
                  .setPoolProvisionedThroughput(throughput)
                  .setPerformanceProvisioningType(performanceProvisioningType)
                  .build();
    
          InsertStoragePoolRequest request = InsertStoragePoolRequest.newBuilder()
                  .setProject(projectId)
                  .setZone(zone)
                  .setStoragePoolResource(resource)
                  .build();
    
          // Wait for the insert disk operation to complete.
          Operation operation = client.insertAsync(request).get(1, TimeUnit.MINUTES);
    
          if (operation.hasError()) {
            System.out.println("StoragePool creation failed!");
            throw new Error(operation.getError().toString());
          }
    
          // Wait for server update
          TimeUnit.SECONDS.sleep(10);
    
          StoragePool storagePool = client.get(projectId, zone, storagePoolName);
    
          System.out.printf("Storage pool '%s' has been created successfully", storagePool.getName());
    
          return storagePool;
        }
      }
    }

    Node.js

    // Import the Compute library
    const computeLib = require('@google-cloud/compute');
    const compute = computeLib.protos.google.cloud.compute.v1;
    
    // Instantiate a storagePoolClient
    const storagePoolClient = new computeLib.StoragePoolsClient();
    // Instantiate a zoneOperationsClient
    const zoneOperationsClient = new computeLib.ZoneOperationsClient();
    
    /**
     * TODO(developer): Update/uncomment these variables before running the sample.
     */
    // Project ID or project number of the Google Cloud project you want to use.
    const projectId = await storagePoolClient.getProjectId();
    // Name of the zone in which you want to create the storagePool.
    const zone = 'us-central1-a';
    // Name of the storagePool you want to create.
    // storagePoolName = 'storage-pool-name';
    // The type of disk you want to create. This value uses the following format:
    // "projects/{projectId}/zones/{zone}/storagePoolTypes/(hyperdisk-throughput|hyperdisk-balanced)"
    const storagePoolType = `projects/${projectId}/zones/${zone}/storagePoolTypes/hyperdisk-balanced`;
    // Optional: The capacity provisioning type of the storage pool.
    // The allowed values are advanced and standard. If not specified, the value advanced is used.
    const capacityProvisioningType = 'advanced';
    // The total capacity to provision for the new storage pool, specified in GiB by default.
    const provisionedCapacity = 10240;
    // The IOPS to provision for the storage pool.
    // You can use this flag only with Hyperdisk Balanced Storage Pools.
    const provisionedIops = 10000;
    // The throughput in MBps to provision for the storage pool.
    const provisionedThroughput = 1024;
    // Optional: The performance provisioning type of the storage pool.
    // The allowed values are advanced and standard. If not specified, the value advanced is used.
    const performanceProvisioningType = 'advanced';
    
    async function callCreateComputeHyperdiskPool() {
      // Create a storagePool.
      const storagePool = new compute.StoragePool({
        name: storagePoolName,
        poolProvisionedCapacityGb: provisionedCapacity,
        poolProvisionedIops: provisionedIops,
        poolProvisionedThroughput: provisionedThroughput,
        storagePoolType,
        performanceProvisioningType,
        capacityProvisioningType,
        zone,
      });
    
      const [response] = await storagePoolClient.insert({
        project: projectId,
        storagePoolResource: storagePool,
        zone,
      });
    
      let operation = response.latestResponse;
    
      // Wait for the create storage pool operation to complete.
      while (operation.status !== 'DONE') {
        [operation] = await zoneOperationsClient.wait({
          operation: operation.name,
          project: projectId,
          zone: operation.zone.split('/').pop(),
        });
      }
    
      console.log(`Storage pool: ${storagePoolName} created.`);
    }
    
    await callCreateComputeHyperdiskPool();

    后续步骤