快速入門導覽課程:部署至 Cloud Run

本頁說明如何使用 Cloud Run 部署範例容器。

事前準備

  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. Make sure that you have the following role or roles on the project: Cloud Run Developer, Service Account Creator, Service Account User

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「IAM」頁面
    2. 選取專案。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]
  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  7. Make sure that you have the following role or roles on the project: Cloud Run Developer, Service Account Creator, Service Account User

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「IAM」頁面
    2. 選取專案。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]

部署範例容器

如要部署容器,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Cloud Run」頁面:

    前往 Cloud Run

  2. 從選單中選取「服務」,然後按一下「部署容器」

  3. 在「建立服務」表單中,確認已選取「透過現有的容器映像檔部署單一修訂版本」選項。

  4. 在「建立服務」頁面中,按一下「容器映像檔網址」的「使用範例容器進行測試」

  5. 在「Service name」(服務名稱) 欄位中輸入服務名稱,或使用預設值。

  6. 在「Region」(區域) 清單中,使用預設值「us-central1」,或選取要部署容器的區域

  7. 在「Authentication」(驗證) 部分中,選取「Allow unauthenticated invocations」(允許未經驗證的叫用)

  8. 按一下「建立」,然後等待容器部署至 Cloud Run。部署完成後,容器的網址會顯示在「URL:」文字旁。

  9. 如要查看執行中的容器,請點選「Copy to clipboard」(複製到剪貼簿) 複製容器的網址,然後將網址貼到瀏覽器的網址列。

    如果您受到網域限制組織政策限制,專案無法進行未經驗證的呼叫,則必須按照「測試私人服務」一節的說明存取已部署的服務。

Cloud Run 位置

Cloud Run 具有「地區性」,這表示執行 Cloud Run 服務的基礎架構位於特定地區,並由 Google 代管,可為該地區內所有區域提供備援功能。

選擇 Cloud Run 服務的執行地區時,請將延遲時間、可用性或耐用性需求做為主要考量。一般而言,您可以選擇最靠近使用者的地區,但您應考量 Cloud Run 服務所使用的其他 Google Cloud 產品位置。使用分散在不同位置的 Google Cloud 產品,可能會影響服務的延遲時間和費用。

Cloud Run 可在下列地區使用:

採用級別 1 定價

採用級別 2 定價

如果您已建立 Cloud Run 服務,即可在 Google Cloud 控制台的 Cloud Run 資訊主頁中查看地區。

Cloud Run 會根據需求自動調度容器執行個體,您只需要支付處理要求期間使用的 CPU、記憶體和網路費用。

後續步驟

如要瞭解如何從程式碼來源建構容器、將容器推送至 Artifact Registry 並進行部署,請參閱: