本頁面說明如何取得、列出及刪除執行個體範本。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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.
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.
- 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.
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.
- 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.
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.
- 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.
For more information, see Set up authentication for a local development environment.
Python
To use the Python 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.
- 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.
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.
-
取得執行個體範本相關資訊
主控台
- 前往 Google Cloud 控制台的「Instance Templates」(執行個體範本) 頁面。
- 按一下執行個體範本的名稱,查看範本的詳細資料。
gcloud
如要取得區域或全域執行個體範本的相關資訊,請使用 instance-templates describe command
。
如為地區執行個體範本,請使用下列指令:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME \ --region=REGION
針對全域執行個體範本,請使用下列指令:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME
Go
Java
Node.js
Python
REST
如要取得區域性執行個體範本的相關資訊,請使用 regionInstanceTemplates.get
方法,如下所示:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME
如要取得全域執行個體範本的相關資訊,請使用 instanceTemplates.get
,如下所示:
GET https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/instanceTemplates/[INSTANCE_TEMPLATE]
列出執行個體範本
如要取得您建立的執行個體範本清單:
主控台
「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
刪除執行個體範本
刪除執行個體範本會將它從您的範本清單中移除。如果代管執行個體群組參照執行個體範本,您無法將這個範本刪除。
主控台
- 前往 Google Cloud 控制台的「Instance Templates」(執行個體範本) 頁面。
- 選取您想刪除的執行個體範本。
- 點選「刪除」。
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」。