使用 Cloud Shell 執行 gcloud 指令

瞭解如何在 Cloud Shell 中執行 gcloud CLI 指令。


如要直接在 Cloud Shell 編輯器中按照逐步指南操作,請按一下「Guide me」

逐步引導


事前準備

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

設定 gcloud 屬性

  1. 啟動 Cloud Shell 編輯器
  2. 設定核心屬性,避免在終端機中輸出訊息時使用顏色:

    gcloud config set disable_color true
    
  3. 取消設定 disable_color 屬性:

    gcloud config unset disable_color
    
  4. 如果您已啟用 Compute Engine API,請設定偏好的 Compute Engine 區域。將 REGION 替換為地區名稱,例如 us-east1

    gcloud config set compute/region REGION
    

    或者,您也可以設定偏好的區域。將 ZONE 替換為區域名稱,例如 us-east1-b

    gcloud config set compute/zone ZONE
    

    如要瞭解 Compute Engine 地區和區域,請參閱「地區和區域」。

  5. 顯示可用屬性清單:

    gcloud topic configurations
    

執行核心指令

  1. 列出將憑證儲存在本機系統中的帳戶:

    gcloud auth list
    

    gcloud CLI 會顯示已驗證帳戶的清單,其中 ACCOUNT_EMAIL 代表一或多個有效帳戶的清單:

    Credentialed Accounts
    ACTIVE  ACCOUNT
    \*      ACCOUNT_EMAIL
    
  2. 列出 gcloud CLI 有效設定中的屬性:

    gcloud config list
    

    gcloud CLI 會顯示類似下方的屬性清單,其中 ACCOUNT_EMAILPROJECT_ID 會顯示您的電子郵件和專案 ID:

    [core]
    account = ACCOUNT_EMAIL
    disable_usage_reporting = False
    project = PROJECT_ID
    
  3. 查看 gcloud CLI 安裝作業和有效設定的相關資訊:

    gcloud info
    

查看 gcloud 指令的說明

  1. 查看 gcloud compute instances create 指令的說明:

    gcloud help compute instances create
    
  2. 查看 gcloud topic 下方的可用指令:

    gcloud help topic
    
  3. 查看篩選功能的相關資訊:

    gcloud topic filters
    
  4. 進一步瞭解 gcloud 指令結構:

    gcloud topic command-conventions
    

後續步驟