本頁面說明如何取得、列出及刪除執行個體範本。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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
-
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.
- Set a default region and zone.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
- 前往 Google Cloud 控制台的「Instance Templates」(執行個體範本) 頁面。
- 按一下執行個體範本的名稱,查看範本的詳細資料。
- 前往 Google Cloud 控制台的「Instance Templates」(執行個體範本) 頁面。
- 選取您想刪除的執行個體範本。
- 點選「刪除」。
Go
如要在本機開發環境中使用本頁面上的 Go 範例,請先安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Java
如要在本機開發環境中使用本頁面上的 Java 範例,請先安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Node.js
如要在本機開發環境中使用本頁面上的 Node.js 範例,請先安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Python
如要在本機開發環境中使用本頁面上的 Python 範例,請先安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 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.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證 REST 使用權」。
取得執行個體範本相關資訊
查看現有的執行個體範本時,您可以看到其名稱、專屬 ID、建立時間戳記,以及範本指定的所有執行個體屬性。
主控台
gcloud
如要取得區域或全域執行個體範本的相關資訊,請使用
instance-templates describe command
。如要使用區域執行個體範本,請使用下列指令:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME_OR_ID \ --region=REGION
針對全域執行個體範本,請使用下列指令:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME_OR_ID
Go
Java
Node.js
Python
REST
如要取得區域性執行個體範本的相關資訊,請使用
regionInstanceTemplates.get
方法,如下所示:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME_OR_ID
如要取得全域執行個體範本的相關資訊,請使用
instanceTemplates.get
方法,如下所示:GET https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/instanceTemplates/[INSTANCE_TEMPLATE_NAME_OR_ID]
列出執行個體範本
如要取得您建立的執行個體範本清單:
主控台
「Instance templates」(執行個體範本) 頁面列出您專案中的所有執行個體範本。
gcloud
如要取得所有區域執行個體範本的清單,請使用下列指令:
gcloud compute instance-templates list \ --regions
如要取得特定地區的區域執行個體範本清單,請使用下列指令:
gcloud compute instance-templates list \ --filter="region:(REGION)"
如要取得全域執行個體範本清單,請使用下列指令:
gcloud compute instance-templates list \ --global
如要取得所有執行個體範本的清單 (包括區域和全域範本),請使用下列指令:
gcloud compute instance-templates list
Go
Java
Node.js
Python
REST
如要取得地區執行個體範本清單,請提出
regionInstanceTemplates.list
要求:GET https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/instanceTemplates
如要取得全域執行個體範本清單,請提出
instanceTemplates.list
要求:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates
刪除執行個體範本
刪除執行個體範本會將它從您的範本清單中移除。如果代管執行個體群組參照執行個體範本,您無法將這個範本刪除。
主控台
gcloud
使用 Google Cloud CLI 執行:
gcloud compute instance-templates delete INSTANCE_TEMPLATE_NAME
如果是地區執行個體範本,INSTANCE_TEMPLATE_NAME 必須包含範本的完整網址。例如:
https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/instanceTemplates/example-regional-instance-template
。Go
Java
Node.js
Python
REST
如要刪除區域執行個體範本,請提出
regionInstanceTemplates.delete
要求:DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME
如要刪除全域執行個體範本,請提出
instanceTemplates.delete
要求:DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates/INSTANCE_TEMPLATE_NAME
代管執行個體群組中的 VM 有時會與群組的其餘部分不同步,並使用與群組其餘部分不同的執行個體範本。如果代管執行個體群組中的 VM 使用與群組指定範本不同的範本,即使該範本已刪除,該 VM 仍會繼續使用該範本進行修復。如要進一步瞭解如何套用新的執行個體範本,請參閱「將新的設定套用至 MIG 中的 VM」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-19 (世界標準時間)。
-