將儲存體資源池中的磁碟新增至 VM


您可以在 Hyperdisk 儲存空間集區中建立磁碟,然後將磁碟連接至虛擬機器 (VM) 執行個體,也可以在建立 VM 時在儲存空間集區中建立磁碟。

事前準備

  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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. After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    2. Set a default region and zone.

    Go

    To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

    1. Install the Google Cloud CLI.
    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. 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.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    For more information, see Set up authentication for a local development environment.

    Java

    To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

    1. Install the Google Cloud CLI.
    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. 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.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    For more information, see Set up authentication for a local development environment.

    Node.js

    To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

    1. Install the Google Cloud CLI.
    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. 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.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    For more information, see Set up authentication for a local development environment.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

必要角色和權限

如要取得在儲存空間資源池中建立 Hyperdisk 平衡或 Hyperdisk 吞吐量磁碟所需的權限,請要求管理員授予您專案的下列 IAM 角色:

  • Compute 執行個體管理員 (v1) (roles/compute.instanceAdmin.v1)
  • 如要連線至可當做服務帳戶執行的 VM 執行個體,請按照下列步驟操作: 服務帳戶使用者 (v1) (roles/iam.serviceAccountUser 角色)

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

這些預先定義的角色包含在儲存空間集區中建立 Hyperdisk 平衡或 Hyperdisk 輸送量磁碟所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:

所需權限

如要在儲存空間集區中建立 Hyperdisk Balanced 或 Hyperdisk Throughput 磁碟,必須具備下列權限:

  • 如要在儲存體池中建立磁碟,並將磁碟連接至 VM 執行個體,請按照下列步驟操作:
    • compute.disks.create 專案
    • compute.instances.attachDisk 在 VM 上
    • compute.disks.use 在要連結至 VM 的磁碟區上
    • compute.storagePools.use 在您要建立磁碟的儲存空間集區中
  • 如要格式化及掛接已附加的磁碟區,請按照下列步驟操作: compute.instances.setMetadata 在 VM 上

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

如要瞭解建立執行個體所需的權限,請參閱「必要權限」。

限制

請查看下列限制,瞭解如何在 Hyperdisk 儲存空間集區中建立磁碟:

  • 您只能在 Hyperdisk Balanced 儲存空間集區中建立 Hyperdisk Balanced 磁碟,且只能在 Hyperdisk Throughput 儲存空間集區中建立 Hyperdisk Throughput 磁碟。
  • 儲存空間集區中只能建立相同專案和區域的新磁碟。
  • 如要在儲存空間集區中建立開機磁碟,您必須使用 Hyperdisk 平衡儲存空間集區。
  • 您無法將磁碟移入或移出儲存空間集區。如要將磁碟移入或移出儲存體資源池,您必須從快照重新建立磁碟。詳情請參閱「變更磁碟類型」。
  • 儲存體系中最多可建立 1,000 個磁碟。
  • 儲存空間集區不支援區域性磁碟

佈建選項

視 Hyperdisk 儲存空間集區的佈建類型而定,您可以選擇如何佈建儲存空間集區中每個磁碟的容量和效能。

佈建磁碟容量

如果您建立進階容量儲存空間集區,可以使用精簡配置。您可以在儲存空間集區中建立磁碟,其累積大小超過集區的已佈建容量。儲存空間集區的已用容量取決於使用中的資料總量,而非您已佈建的磁碟空間量。您可以佈建磁碟,匯總容量可達進階容量儲存空間集區的已佈建容量的 500%。

如果您要在標準容量儲存空間集區中建立磁碟,請在儲存空間集區中建立磁碟,直到儲存空間集區中所有磁碟的總大小達到儲存空間集區的已佈建容量為止。儲存空間集區中具有標準容量的磁碟,其行為與非集區磁碟相似,也就是在建立磁碟時會消耗容量。

佈建效能

如果您建立進階效能儲存空間資源池,可以使用精簡配置。您可以在儲存體池中建立磁碟,其累積的 IOPS 和總處理量超過池的已配置效能。儲存空間集區的使用效能是由磁碟使用的總效能定義,而非由為每個磁碟配置的效能量定義。您可以佈建磁碟,其總效能可達進階效能儲存空間佈建效能的 500%。

如果您要在標準效能儲存空間集區中建立磁碟,為磁碟佈建的 IOPS 或總處理量,必須低於 Hyperdisk 儲存空間集區的可用 IOPS 或總處理量。可用的 IOPS 或處理量,是儲存空間集區的已佈建數量,減去儲存空間集區中所有磁碟的已使用數量。

如果前一段落中的任何條件皆不成立,則在儲存空間資源池中建立磁碟的請求會失敗,且不會建立磁碟。

示例

假設您有一個 Hyperdisk 平衡儲存空間集區,其中有 100,000 個已佈建 IOPS。

採用標準效能佈建時:

  • 在儲存空間集區中建立 Hyperdisk Balanced 磁碟時,最多可以佈建 100,000 個匯總 IOPS。
  • 系統會根據 Hyperdisk 平衡儲存空間集區的 100,000 IOPS 佈建效能收費。
  • 與儲存空間集區外建立的磁碟一樣,標準效能儲存空間集區中的 Hyperdisk Balanced 磁碟會自動佈建,最多可達 3,000 個基準 IOPS 和 140 MiB/s 的基準處理量。這個基準效能不會計入儲存空間集區的已配置效能。只有在您將磁碟新增至儲存空間集區,且已佈建效能高於基準值時,才會計入儲存空間集區的已佈建效能,例如:

    • 已佈建 3,000 IOPS 的磁碟使用 0 個集區 IOPS,且集區仍有 100,000 個已佈建 IOPS 可供其他磁碟使用。
    • 已佈建 13,000 IOPS 的磁碟會使用 10,000 個集區 IOPS,而集區還有 90,000 個已佈建 IOPS 可用於儲存空間集區中的其他磁碟。

使用進階效能佈建時:

  • 在儲存空間集區中建立磁碟時,您最多可以佈建 500,000 IOPS 的 Hyperdisk 總效能。
  • 您必須為儲存空間集區佈建的 100,000 IOPS 付費。
  • 如果您在儲存空間集區中建立單一磁碟 (Disk1),且該磁碟的 IOPS 為 5,000,則您不會使用儲存空間集區已佈建 IOPS 的任何 IOPS。不過,您現在可以為儲存空間集區中建立的新磁碟佈建的 IOPS 數量為 495,000。
  • 如果 Disk1 開始讀取及寫入資料,且在特定分鐘內使用最多 5,000 IOPS,則會從儲存空間集區的已佈建 IOPS 中消耗 5,000 IOPS。您在同一個儲存空間資源池中建立的任何其他磁碟,可以在同一分鐘內使用總計 95,000 個 IOPS 的匯總值,而不會發生競爭。

在儲存空間集區中建立磁碟

您可以使用 Google Cloud 控制台、Google Cloud CLI 或 REST 在儲存空間資源池中建立磁碟。

主控台

您可以使用 Google Cloud 控制台,透過「儲存空間資源池」頁面或「磁碟」頁面,在儲存空間資源池中建立新的磁碟。

在「儲存空間集區」頁面中:

  1. 前往 Google Cloud 控制台中的「Storage pools」(儲存空間資源池) 頁面。

    前往「Storage pools」(儲存空間集區) 頁面

  2. 按一下要建立磁碟的儲存空間集區名稱。

  3. 在「管理儲存空間集區」頁面中,按一下「+ 建立新磁碟」

  4. 在「Add new disk」面板中,輸入磁碟的「名稱」

  5. 指定或變更不想使用預設值的任何值。

  6. 指定磁碟屬性完成後,請按一下「儲存」

  7. 在「管理儲存空間集區」頁面中,您應該會在「儲存空間集區磁碟」部分看到新磁碟。

在「Create Disk」(建立磁碟) 頁面中:

  1. 在 Google Cloud 控制台中,依序前往「Disks」>「Create a disk」頁面。

    前往「Create a disk」(建立磁碟) 頁面

  2. 輸入磁碟的「Name」(名稱)

  3. 選取包含要建立磁碟的儲存空間集區。

  4. 在「磁碟類型」中,選擇符合 Hyperdisk 儲存空間集區的磁碟類型,也就是 Hyperdisk Throughput 或 Hyperdisk Balanced。

  5. 視需要修改「大小」、「已配置 IOPS」和「已配置的傳輸量」欄位的值。

  6. 在「儲存空間集區」專區中,選取「啟用儲存空間集區」,然後選擇要建立磁碟的儲存空間集區名稱。清單中只會顯示所選可用區中的儲存空間集區。

  7. 指定磁碟資訊後,按一下「建立」

gcloud

如要在儲存空間資源池中建立一或多個磁碟,請使用 gcloud compute disks create 指令

gcloud compute disks create DISK_NAME \
    --zone=ZONE \
    --storage-pool=STORAGE_POOL_NAME \
    --size=SIZE \
    --type=DISK_TYPE \
    --provisioned-iops=PROVISIONED_IOPS \
    --provisioned-throughput=PROVISIONED_THROUGHPUT

更改下列內容:

  • DISK_NAME:磁碟的專屬名稱。您可以提供以空格分隔的磁碟名稱清單,建立多個具有相同屬性的磁碟。
  • ZONE:儲存空間集區建立的區域。請使用地區-區域格式指定這個值,例如 us-central1-a
  • STORAGE_POOL_NAME:要建立磁碟的儲存空間集區名稱
  • SIZE:選用:新磁碟的已佈建容量。值必須是整數,後面接著大小單位,例如 GB 代表千兆位元組,TB 代表兆位元組。如果未指定大小,系統會使用 100 GB 做為預設值。
  • DISK_TYPE:要建立的磁碟類型。這必須與 Hyperdisk 儲存空間集區的類型相符,也就是 hyperdisk-balancedhyperdisk-throughput
  • PROVISIONED_IOPS:選用:為磁碟佈建的 IOPS。這個標記只能與 Hyperdisk Balanced 磁碟搭配使用。
  • PROVISIONED_THROUGHPUT:選用:為磁碟配置的每秒位元組 (MB) 處理量。

REST

如要在儲存空間資源池中建立一或多個磁碟,請使用 disks.insert 方法建構 POST。請加入 namesizeGbtypestoragePoolprovisionedIopsprovisionedThroughput 屬性。如要將這個磁碟建立為空白且未格式化的非開機磁碟,請勿指定來源映像檔或來源快照。

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks

{
    "name": "DISK_NAME",
    "description": "DESCRIPTION",
    "type": "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/DISK_TYPE",
    "sizeGb": "DISK_SIZE",
    "storagePool": "STORAGE_POOL_NAME",
    "provisionedIops": "IOPS_LIMIT",
    "provisionedThroughput": "THROUGHPUT_LIMIT",
}

更改下列內容:

  • PROJECT_ID:專案 ID
  • ZONE:儲存空間資源池所在的可用區,例如 us-central1-a。這是要建立磁碟的區域。
  • DISK_NAME:磁碟的專屬名稱。
  • DESCRIPTION:選用:描述磁碟的文字字串。
  • DISK_TYPE:磁碟類型,必須與儲存空間集區類型相符。使用 hyperdisk-throughputhyperdisk-balanced
  • DISK_SIZE:選用:新磁碟的大小。這個值必須是整數,後面加上大小單位,例如 GB 代表千兆位元組,TB 代表兆位元組。如果未指定大小,系統會使用 100 GB 做為預設值。
  • STORAGE_POOL_NAME:要建立磁碟的儲存空間集區名稱。
  • IOPS_LIMIT:選用:為磁碟佈建的 IOPS。這個標記只能與 Hyperdisk Balanced 磁碟搭配使用。
  • THROUGHPUT_LIMIT:選用:為磁碟配置的每秒處理量 (以 MiB 為單位)。

Go


// createDiskInStoragePool creates a new Hyperdisk in the specified storage pool.
func createDiskInStoragePool(w io.Writer, projectId, zone, diskName, storagePoolName, diskType string) error {
	// Example usage:
	//   projectID := "your_project_id"
	//   zone := "europe-central2-b"
	//   diskName := "your_disk_name"
	//   storagePoolName := "https://www.googleapis.com/compute/v1/projects/your_project_id/zones/europe-central2-b/storagePools/your_storage_pool"
	//   diskType := "zones/europe-central2-b/diskTypes/hyperdisk-balanced"

	ctx := context.Background()
	client, err := compute.NewDisksRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewDisksRESTClient: %v", err)
	}
	defer client.Close()

	// Create the disk resource
	disk := &computepb.Disk{
		Name:                  proto.String(diskName),
		Type:                  proto.String(diskType),
		SizeGb:                proto.Int64(50),
		Zone:                  proto.String(zone),
		StoragePool:           proto.String(storagePoolName),
		ProvisionedIops:       proto.Int64(10000),
		ProvisionedThroughput: proto.Int64(1024),
	}

	// Create the insert disk request
	req := &computepb.InsertDiskRequest{
		Project:      projectId,
		Zone:         zone,
		DiskResource: disk,
	}

	// Send the insert disk request
	op, err := client.Insert(ctx, req)
	if err != nil {
		return fmt.Errorf("Insert disk request failed: %v", err)
	}

	// Wait for the insert disk operation to complete
	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Disk created in storage pool: %v\n", disk.Name)
	return nil
}

Java


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.InsertDiskRequest;
import com.google.cloud.compute.v1.Operation;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateDiskInStoragePool {
  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 disk.
    String zone = "europe-central2-b";
    // Name of the disk you want to create.
    String diskName = "YOUR_DISK_NAME";
    // Link to the storagePool you want to use. Use format :
    // https://www.googleapis.com/compute/v1/projects/%s/zones/%s/storagePools/%s"
    String storagePoolName = "YOUR_STORAGE_POOL_LINK";
    // The type of disk you want to create. This value uses the following format:
    // "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-throughput)".
    // For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
    String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", zone);
    // Size of the new disk in gigabytes.
    long diskSizeGb = 10;
    // Optional: the IOPS to provision for the disk.
    // You can use this flag only with Hyperdisk Balanced disks.
    long provisionedIops = 3000;
    // Optional: the throughput in mebibyte (MB) per second to provision for the disk.
    long provisionedThroughput = 140;

    createDiskInStoragePool(projectId, zone, diskName, storagePoolName, diskType,
            diskSizeGb, provisionedIops, provisionedThroughput);
  }

  // Creates a hyperdisk in the storage pool
  public static Disk createDiskInStoragePool(String projectId, String zone, String diskName,
                                             String storagePoolName, String diskType,
                                             long diskSizeGb, long iops, long throughput)
          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 (DisksClient client = DisksClient.create()) {
      // Create a disk.
      Disk disk = Disk.newBuilder()
              .setZone(zone)
              .setName(diskName)
              .setType(diskType)
              .setSizeGb(diskSizeGb)
              .setStoragePool(storagePoolName)
              .setProvisionedIops(iops)
              .setProvisionedThroughput(throughput)
              .build();

      InsertDiskRequest request = InsertDiskRequest.newBuilder()
              .setProject(projectId)
              .setZone(zone)
              .setDiskResource(disk)
              .build();

      // Wait for the insert disk operation to complete.
      Operation operation = client.insertAsync(request).get(1, TimeUnit.MINUTES);

      if (operation.hasError()) {
        System.out.println("Disk creation failed!");
        throw new Error(operation.getError().toString());
      }

      // Wait for server update
      TimeUnit.SECONDS.sleep(10);

      Disk hyperdisk = client.get(projectId, zone, diskName);

      System.out.printf("Hyperdisk '%s' has been created successfully", hyperdisk.getName());

      return hyperdisk;
    }
  }
}

Node.js

// Import the Compute library
const computeLib = require('@google-cloud/compute');
const compute = computeLib.protos.google.cloud.compute.v1;

// Instantiate a diskClient
const disksClient = new computeLib.DisksClient();
// 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 disksClient.getProjectId();

// The zone where your VM and new disk are located.
// zone = 'us-central1-a';

// The name of the new disk
// diskName = 'disk-from-pool-name';

// The name of the storage pool
// storagePoolName = 'storage-pool-name';

// Link to the storagePool you want to use. Use format:
// https://www.googleapis.com/compute/v1/projects/{projectId}/zones/{zone}/storagePools/{storagePoolName}
const storagePool = `https://www.googleapis.com/compute/v1/projects/${projectId}/zones/${zone}/storagePools/${storagePoolName}`;
// The type of disk. This value uses the following format:
// "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
// For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
const diskType = `zones/${zone}/diskTypes/hyperdisk-balanced`;
// Size of the new disk in gigabytes.
const diskSizeGb = 10;
// Optional: For Hyperdisk Balanced or Hyperdisk Extreme disks,
// this is the number of I/O operations per second (IOPS) that the disk can handle.
const provisionedIops = 3000;
// Optional: For Hyperdisk Balanced or Hyperdisk Throughput volumes,
// this is an integer that represents the throughput,
// measured in MiB per second, that the disk can handle.
const provisionedThroughput = 140;

async function callCreateComputeHyperdiskFromPool() {
  // Create a disk
  const disk = new compute.Disk({
    sizeGb: diskSizeGb,
    name: diskName,
    type: diskType,
    zone,
    storagePool,
    provisionedIops,
    provisionedThroughput,
  });

  const [response] = await disksClient.insert({
    project: projectId,
    zone,
    diskResource: disk,
  });

  let operation = response.latestResponse;

  // Wait for the create disk operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await zoneOperationsClient.wait({
      operation: operation.name,
      project: projectId,
      zone: operation.zone.split('/').pop(),
    });
  }

  console.log(`Disk: ${diskName} created.`);
}

await callCreateComputeHyperdiskFromPool();

建立磁碟後,您可以將磁碟連結至 VM

建立使用儲存體資源池中磁碟的 VM

建立 VM 時,您會設定開機磁碟,並可視需要建立其他資料 (非開機) 磁碟,這些磁碟會自動連接至 VM。以下各節將說明如何在儲存空間資源池中建立各類型磁碟,做為 VM 建立程序的一部分。

在儲存空間集區中為 VM 建立開機磁碟

如要建立在儲存空間集區中使用開機磁碟的 VM,您必須先建立 Hyperdisk 平衡儲存空間集區。接著,您可以使用支援 Hyperdisk Balanced 磁碟的機器類型建立 VM。所選可用區必須提供機器類型、磁碟類型和儲存空間集區。

主控台

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. 點選「建立執行個體」

  3. 輸入執行個體的名稱。

  4. 將區域設為儲存空間集區所在的區域。

  5. 選擇支援 Hyperdisk Balanced 的機器類型,例如 H3。

  6. 在「Boot disk」(開機磁碟) 區段,按一下 [Change] (變更)

  7. 在「Boot disk」面板中,將「Boot disk type」設為「Hyperdisk Balanced」。

  8. 設定磁碟的屬性。

  9. 展開「顯示進階設定」

  10. 在「儲存空間集區」標題下方,選取「啟用儲存空間集區」

  11. 從清單中選擇要建立磁碟的儲存空間集區。

  12. 完成磁碟設定後,請按一下「選取」

  13. 完成 VM 屬性設定。

  14. 按一下 [建立]。

    主控台會在指定的可用區中建立 VM,並在所選儲存空間集區中建立啟動磁碟。

gcloud

您可以使用 gcloud compute instances create 指令,並加入開機磁碟的 storage-pool 屬性,為儲存體資源池中的新 VM 建立開機磁碟。

gcloud compute instances create VM_NAME \
    --zone=ZONE \
    --machine-type=MACHINE_TYPE \
    --create-disk=boot=yes,type=hyperdisk-balanced,size=DISK_SIZE,provisioned-throughput=THROUGHPUT, \
    provisioned-iops=IOPS,image=projects/IMAGE_PROJECT/global/images/IMAGE, \
    storage-pool=STORAGE_POOL_NAME

更改下列內容:

  • VM_NAME:VM 名稱。
  • ZONE:使用 us-central1-a 格式,指定要建立 VM 的地區和區域。
  • MACHINE_TYPE:VM 的機器類型,例如 m3-ultramem-32
  • DISK_SIZE:開機磁碟的大小 (以 GiB 為單位)
  • THROUGHPUT:為磁碟佈建的處理量
  • IOPS:為磁碟佈建的 IOPS
  • IMAGE_PROJECT:包含圖片的專案
  • IMAGE:指定下列任一值:
    • 特定 OS 映像檔版本,例如 debian-12-bookworm-v20240213
    • 映像檔系列,其格式必須為 family/IMAGE_FAMILY。這麼做會使用最新的非淘汰作業系統映像檔建立執行個體。舉例來說,如果您指定 family/debian-12,Compute Engine 會使用 debian-12 映像檔系列中的最新版 OS 映像檔建立 VM。如要進一步瞭解如何使用映像檔系列,請參閱「映像檔系列最佳做法」。
  • STORAGE_POOL_NAME:建立新磁碟的儲存空間集區名稱。

REST

您可以為儲存體資源池中的新 VM 建立開機磁碟,方法是為 instances.insert 方法建構 POST 要求,並納入開機磁碟的 storagePool 屬性。

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances

{
   "name": "VM_NAME",
   "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
   "disks": [
      {
         "deviceName": "BOOT_DISK_DEVICE_NAME",
         "initializeParams": {
            "diskSizeGb": "DISK_SIZE",
            "diskType": "DISK_TYPE",
            "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
            "boot": true,
            "provisionedIops": "IOPS_LIMIT",
            "provisionedThroughput": "THROUGHPUT_LIMIT",
            "storagePool": "POOL_URL"
         }
      }
   ]
}

更改下列內容:

  • PROJECT_ID:專案 ID
  • ZONE:儲存空間資源池所在的可用區,例如 us-central1-a。這是建立 VM 和開機磁碟的區域。
  • VM_NAME:VM 名稱。
  • MACHINE_TYPE:VM 的機器類型,例如 m3-ultramem-32
  • BOOT_DISK_DEVICE_NAME:開機磁碟的裝置名稱
  • DISK_SIZE:開機磁碟的大小 (以 GiB 為單位)
  • DISK_TYPE:磁碟類型,以 URI 指定
  • IMAGE_PROJECT:包含圖片的專案
  • IMAGE:指定下列任一值:
    • 特定 OS 映像檔版本,例如 debian-12-bookworm-v20240213
    • 映像檔系列,其格式必須為 family/IMAGE_FAMILY。這麼做會使用最新的非淘汰作業系統映像檔建立執行個體。舉例來說,如果您指定 family/debian-12,Compute Engine 會使用 debian-12 映像檔系列中的最新版 OS 映像檔建立 VM。如要進一步瞭解如何使用映像檔系列,請參閱「映像檔系列最佳做法」。
  • IOPS_LIMIT:為磁碟佈建的 IOPS
  • THROUGHPUT_LIMIT:為磁碟佈建的處理量
  • POOL_URL:建立新磁碟的儲存空間集區。您可以提供資源的部分或完整網址。例如,以下為有效值:
    • https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • zones/ZONE/storagePools/STORAGE_POOL_NAME

在建立 VM 時在儲存體資源池中建立其他磁碟

在建立 VM 時,如果要在儲存體資源池中建立磁碟,則機器類型、磁碟類型和儲存體資源池必須在您選擇的區域中提供。

主控台

請按照下列步驟,使用主控台建立含有額外非開機磁碟的新 VM:

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. 點選「建立執行個體」

  3. 輸入 VM 的名稱。

  4. 將區域設為儲存空間集區所在的區域。

  5. 請選擇支援儲存空間集區所用磁碟類型的機器類型。

  6. 展開「Advanced options」(進階選項) 區段。

  7. 展開「磁碟」

  8. 按一下 「新增磁碟」

  9. 在「Add new disk」面板中,輸入磁碟的相關資訊。將「磁碟類型」設為儲存空間集區類型。

  10. 在「Storage Pool」專區中,選取「Enable storage pool」

  11. 在「Select a storage pool」欄位中,選取要建立磁碟的儲存空間集區。

  12. 完成磁碟設定後,按一下「儲存」

  13. 完成 VM 屬性設定。

  14. 按一下 [建立]。

    主控台會在指定的可用區中建立 VM,並在所選儲存空間集區中建立非啟動磁碟。

gcloud

您可以在建立 VM 的過程中,使用 gcloud compute instances create 指令並加入磁碟的 storage-pool 屬性,在儲存體資源池中建立新的磁碟。

gcloud compute instances create VM_NAME \
    --zone=ZONE \
    --machine-type=MACHINE_TYPE \
    --create-disk=auto-delete=yes,boot=yes,device-name=BOOT_DISK_DEVICE_NAME,image=IMAGE_NAME, \
    size=BOOT_DISK_SIZE,type=BOOT_DISK_TYPE
    --create-disk=auto-delete=yes,boot=no,device-name=DATA_DISK_DEVICE_NAME,size=DATA_DISK_SIZE, \
    type=DATA_DISK_TYPE,provisioned-iops=IOPS,provisioned-throughput=THROUGHPUT, \
    storage_pool=STORAGE_POOL_NAME

更改下列內容:

  • VM_NAME:VM 名稱。
  • ZONE:建立 VM 的地區和可用區,格式為 us-central1-a
  • MACHINE_TYPE:VM 的機器類型
  • BOOT_DISK_DEVICE_NAME:開機磁碟的裝置名稱
  • IMAGE_NAME:要在開機磁碟上安裝的作業系統映像檔名稱,例如 debian-12-bookworm-v20240213
  • BOOT_DISK_SIZE:開機磁碟的大小 (以 GiB 為單位)
  • BOOT_DISK_TYPE:磁碟類型
  • DATA_DISK_DEVICE_NAME:資料磁碟的磁碟裝置名稱
  • DATA_DISK_SIZE:資料磁碟大小 (以 GiB 為單位)
  • DATA_DISK_TYPE:資料磁碟類型,為 hyperdisk-balancedhyperdisk-throughput
  • IOPS:為磁碟佈建的 IOPS
  • THROUGHPUT:為磁碟佈建的處理量
  • STORAGE_POOL_NAME:您要建立磁碟的儲存空間資源池專屬名稱。

REST

您可以在建立 VM 的過程中,在儲存體資源池中建立新磁碟,方法是為 instances.insert 方法建構 POST 要求,並納入額外磁碟的 storagePool 屬性。

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances

{
   "name": "VM_NAME",
   "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
   "disks": [
      {
        "initializeParams":{
            "sourceImage":"projects/IMAGE_PROJECT/global/images/IMAGE"
        },
        "boot":true
      },
      {
        "deviceName": "DEVICE_NAME",
        "boot":false,
        "initializeParams": {
           "diskSizeGb": "DISK_SIZE",
           "diskType": "DISK_TYPE",
           "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
           "provisionedIops": "IOPS_LIMIT",
           "provisionedThroughput": "THROUGHPUT_LIMIT",
           "storagePool": "POOL_URL"
        }
      }
   ]
}

更改下列內容:

  • PROJECT_ID:專案 ID
  • ZONE:儲存空間資源池所在的可用區,例如 us-central1-a。這是建立 VM 和開機磁碟的區域。
  • VM_NAME:VM 名稱。
  • MACHINE_TYPE:VM 的機器類型,例如 m3-ultramem-32
  • IMAGE_PROJECT:包含圖片的專案
  • IMAGE:指定下列任一值:
    • 特定 OS 映像檔版本,例如 debian-12-bookworm-v20240213
    • 映像檔系列,其格式必須為 family/IMAGE_FAMILY。這麼做會使用最新的非淘汰作業系統映像檔建立執行個體。舉例來說,如果您指定 family/debian-12,Compute Engine 會使用 debian-12 映像檔系列中的最新版 OS 映像檔建立 VM。如要進一步瞭解如何使用映像檔系列,請參閱「映像檔系列最佳做法」。
  • DEVICE_NAME:資料磁碟的裝置名稱
  • DISK_SIZE:資料磁碟的大小 (以 GiB 為單位)
  • DISK_TYPE:磁碟類型,以 URI 指定
  • IOPS_LIMIT:為磁碟佈建的 IOPS
  • THROUGHPUT_LIMIT:為磁碟佈建的處理量
  • POOL_URL:建立新磁碟的儲存空間集區。您可以提供資源的部分或完整網址。例如,以下為有效值:
    • https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • zones/ZONE/storagePools/STORAGE_POOL_NAME

在執行個體範本中使用儲存空間集區

用於建立代管執行個體群組 (MIG) 的執行個體範本,可能會包含儲存空間資源池資訊。使用執行個體範本建立的磁碟會放置在指定的儲存空間集區。

主控台

  1. 前往 Google Cloud 控制台的「Instance templates」(執行個體範本) 頁面。

    前往「Instance templates」(執行個體範本) 頁面

  2. 按一下「建立執行個體範本」

  3. 輸入執行個體範本的名稱。

  4. 在「位置」部分,選擇「區域」,然後在「區域」欄位中,選擇儲存空間集區所在的區域。

  5. 選擇支援 Hyperdisk Balanced 的機器類型,例如 C3。

  6. 在「Boot disk」(開機磁碟) 區段,按一下 [Change] (變更)

  7. 在「Boot disk」面板中,將「Boot disk type」設為「Hyperdisk Balanced」。

  8. 設定磁碟的屬性。

  9. 展開「顯示進階設定」

  10. 在「儲存空間集區」標題下方,選取「啟用儲存空間集區」

  11. 從清單中選擇要建立磁碟的儲存空間集區。

  12. 完成磁碟設定後,請按一下「選取」

  13. 完成 VM 屬性設定。

  14. 按一下 [建立]。

    範本會在指定的可用區中建立 VM,並在所選儲存空間集區中建立啟動磁碟。

gcloud

您可以在執行個體範本中使用 gcloud compute instance-templates create 指令並加入開機磁碟的 storage-pool 屬性,指定在儲存空間資源池中建立預訂磁碟。

gcloud compute instance-templates create TEMPLATE_NAME \
    --instance-template-region=REGION \
    --machine-type=MACHINE_TYPE \
    --create-disk=boot=yes,type=hyperdisk-balanced,size=DISK_SIZE,provisioned-throughput=THROUGHPUT, \
    provisioned-iops=IOPS,image=projects/IMAGE_PROJECT/global/images/IMAGE, \
    storage-pool=STORAGE_POOL_NAME

更改下列內容:

  • TEMPLATE_NAME:執行個體範本的名稱。
  • REGION:您要建立區域執行個體範本的區域。區域必須包含儲存集區所在的可用區。
  • MACHINE_TYPE:建立 VM 時要使用的機器類型,例如 h3-standard-88
  • DISK_SIZE:磁碟大小 (以 GiB 為單位)
  • THROUGHPUT:為磁碟佈建的處理量
  • IOPS:為磁碟佈建的 IOPS
  • IMAGE_PROJECT:包含圖片的專案
  • IMAGE:指定下列任一值:
    • 特定 OS 映像檔版本,例如 debian-12-bookworm-v20240213
    • 映像檔系列,其格式必須為 family/IMAGE_FAMILY。這麼做會使用最新的非淘汰作業系統映像檔建立執行個體。舉例來說,如果您指定 family/debian-12,Compute Engine 會使用 debian-12 映像檔系列中的最新版 OS 映像檔建立 VM。如要進一步瞭解如何使用映像檔系列,請參閱「映像檔系列最佳做法」。
  • STORAGE_POOL_NAME:建立新磁碟的儲存空間集區名稱。

REST

您可以為儲存體資源池中的新 VM 建立開機磁碟,方法是為 instances.insert 方法建構 POST 要求,並納入開機磁碟的 storagePool 屬性。

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates
{
   "name": "VM_NAME",
   "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
   "disks": [
      {
         "deviceName": "BOOT_DISK_DEVICE_NAME",
         "initializeParams": {
            "diskSizeGb": "DISK_SIZE",
            "diskType": "DISK_TYPE",
            "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
            "boot": true,
            "provisionedIops": "IOPS_LIMIT",
            "provisionedThroughput": "THROUGHPUT_LIMIT",
            "storagePool": "POOL_URL"
         }
      }
   ]
}

更改下列內容:

  • PROJECT_ID:專案 ID
  • VM_NAME:VM 名稱。
  • ZONE:儲存空間資源池所在的可用區,例如 us-central1-a。這是建立 VM 和開機磁碟的區域。
  • MACHINE_TYPE:VM 的機器類型,例如 m3-ultramem-32
  • BOOT_DISK_DEVICE_NAME:開機磁碟的裝置名稱
  • DISK_SIZE:開機磁碟的大小 (以 GiB 為單位)
  • DISK_TYPE:磁碟類型,以 URI 指定
  • IMAGE_PROJECT:包含圖片的專案
  • IMAGE:指定下列任一值:
    • 特定 OS 映像檔版本,例如 debian-12-bookworm-v20240213
    • 映像檔系列,其格式必須為 family/IMAGE_FAMILY。這麼做會使用最新的非淘汰作業系統映像檔建立執行個體。舉例來說,如果您指定 family/debian-12,Compute Engine 會使用 debian-12 映像檔系列中的最新 OS 映像檔版本建立執行個體。如要進一步瞭解如何使用映像檔系列,請參閱「映像檔系列最佳做法」。
  • IOPS_LIMIT:為磁碟佈建的 IOPS
  • THROUGHPUT_LIMIT:為磁碟佈建的處理量
  • POOL_URL:建立新磁碟的儲存空間集區。您可以提供資源的部分或完整網址。例如,以下為有效值:
    • https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • projects/PROJECT_ID/zones/ZONE/storagePools/STORAGE_POOL_NAME
    • zones/ZONE/storagePools/STORAGE_POOL_NAME