建立代管執行個體群組 (MIG)
瞭解如何使用 Google Cloud 控制台,在 Compute Engine 中建立代管執行個體群組 (MIG)。
MIG 是虛擬機器 (VM) 執行個體的集合,您可以將此群組做為單一實體進行管理。MIG 支援自動修復、自動調度資源、負載平衡、多可用區涵蓋範圍和有狀態工作負載等功能。
MIG 中的每個 VM 都是以執行個體範本為基礎。您必須先建立執行個體範本,才能建立 MIG。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 啟用 Compute Engine API。
建立執行個體範本
- 前往 Google Cloud 控制台的「Instance Templates」(執行個體範本) 頁面。 
- 按一下 - 「Create instance template」(建立執行個體範本) 。
- 如要建立採用 Ubuntu OS 的範本,請執行下列步驟: - 按一下 - 「Boot disk」(開機磁碟) 專區中的「Change」(變更)。
- 在「Operating system」(作業系統) 清單中選取「Ubuntu」。 
- 按一下「Select」(選取)。 
 - 範本會將這些設定套用至依據這個範本建立的所有 VM。請記下範本名稱,以便在後續的教學課程中使用。 
- 如要建立執行個體範本,請按一下「Create」(建立)。 
請稍候幾分鐘,讓 Compute Engine 建立範本。準備就緒之後,範本會出現在「Instance templates」(執行個體範本) 頁面中。
依據執行個體範本建立 MIG
- 前往 - 「Instance groups」(執行個體群組) 頁面。
- 按一下 - 「Create instance group」(建立執行個體群組) ,然後執行下列步驟:- 在「Name」(名稱) 欄位中接受預設名稱或輸入 - quickstart-instance-group-1。
- 在「Instance template」(執行個體範本) 清單中,選取稍早建立的執行個體範本。 
- 在 - 「Location」(位置) 專區中確認已選取「Single zone」(單一可用區)。
- 在「Region」(區域) 欄位中,選擇要建立 MIG 的區域。 
- 接受 - 「Autoscaling」(自動調度資源) 部分中的預設設定,或是視需求調整。
 
- 如要建立 MIG,請按一下「Create」(建立)。 
請稍候幾分鐘,讓 Compute Engine 建立群組和相關 VM。準備就緒之後,群組會出現在「Instance groups」(執行個體群組) 頁面中。
您已成功建立代管執行個體群組。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
刪除資源
如果您使用現有的 Google Cloud 專案,請刪除稍早建立的資源,以免系統向您的帳戶收取費用。
- 前往「Instance groups」(執行個體群組) 頁面。 
- 選取要刪除的執行個體群組。 
- 按一下「Delete」(刪除)。 
- 按照系統提示輸入所需的值,然後按一下「Delete」(刪除)。 
刪除專案
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
後續步驟
- 瞭解如何使用代管型執行個體。
- 瞭解建立 MIG 的其他基本情境。
- 進一步瞭解自動調度資源功能,以及如何使用不同的自動調度資源信號,在負載增加時自動建立 VM,並在負載減少時刪除 VM。
- 如要提高應用程式的可用性,請設定以應用程式為基礎的自動修復健康狀態檢查。以應用程式為準的健康狀態檢查會指示 MIG,如果應用程式無法按照預期產生回應,則會自動重新建立健康狀態不良的 VM。
- 如要進一步提高可用性,您可以瞭解如何建立區域性 MIG,並將當中的 VM 分散至所屬區域的多個可用區。
- 如要更新 MIG 中的 VM 設定,請建立並套用新的執行個體範本。詳情請參閱「將新的設定套用至 MIG 中的 VM」一文。
- 如要處理有狀態的工作負載,請參閱這篇文章來瞭解如何新增有狀態的設定。