如果您執行下列操作,會發現這份教學課程非常有幫助:
- 在 Cloud Run 代管應用程式。
- 使用 Cloud SQL 做為您的資料庫。
- 想使用 phpMyAdmin 做為 MySQL 的介面,或偏好使用網頁介面管理資料庫。
目標
- 瞭解如何在 Cloud Run 部署 phpMyAdmin。
費用
本教學課程使用 Google Cloud的計費元件,包括:
您可以使用 Pricing Calculator,根據預測用量估算費用。
事前準備
- 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud 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 -
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud 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 - 建立具有私人 IP 的 Cloud SQL 第二代執行個體。
- 建立資料庫使用者。
使用 phpMyAdmin 映像檔建立服務
控制台
前往 Google Cloud 控制台的「Cloud Run」頁面:
選取「建立服務」。
- 在「Container image」(容器映像檔) 網址欄位中,輸入
phpmyadmin。Cloud Run 會從公開的 Docker Hub 提取映像檔。 - 在「Service name」(服務名稱) 欄位中輸入
phpmyadmin。 - 請檢查
Require authentication。 - 按一下「Container(s), volumes, networking, security」(容器、磁碟區、網路、安全性),設定下列選項:
- 在「Port」(通訊埠) 欄位中,輸入
80做為容器通訊埠的值。 - 在「Environment variables」(環境變數) 中,新增
PMA_HOST,並將值設為 Cloud SQL 執行個體的內部 IP 位址。
- 在「Port」(通訊埠) 欄位中,輸入
在「網路」中,選取「連線至虛擬私有雲,以傳出流量」和「直接將流量傳送至虛擬私有雲」。選擇與 Cloud SQL 執行個體相同的網路。
- 在「Container image」(容器映像檔) 網址欄位中,輸入
使用 Cloud Run Proxy 連線至服務
如要安全存取受 IAM 保護的服務,請使用 Cloud Run 開發人員 Proxy。
如要在先前建立的服務上啟動 Proxy,請使用下列指令:
gcloud run services proxy phpmyadmin --port=8080如果 gcloud CLI 提示您安裝
cloud-run-proxy元件,請輸入Y。如要測試設定,請輸入網址和通訊埠號碼 (例如
http://127.0.0.1:8080/),然後使用使用者名稱 (管理員名稱) 和密碼登入。由於您是使用本機 Cloud Run 開發人員 Proxy 安全存取服務,因此可能會看到錯誤訊息,但可以忽略:There is a mismatch between HTTPS indicated on the server and client。
疑難排解
如要取得 Cloud Run 錯誤的相關資訊,請前往Google Cloud 控制台,存取 Cloud Run 記錄。
清除所用資源
完成教學課程後,您可以清除所建立的資源,這樣資源就不會繼續使用配額,也不會產生費用。下列各節將說明如何刪除或關閉這些資源。
刪除專案
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
刪除專案的方法如下:
- 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。
- 在專案清單中選取要刪除的專案,然後點選「Delete」(刪除)。
- 在對話方塊中輸入專案 ID,然後按一下 [Shut down] (關閉) 以刪除專案。
刪除執行個體
如要刪除 Cloud SQL 執行個體:
- 前往 Google Cloud 控制台的「Instances」(執行個體) 頁面。
- 按一下要刪除的 SQL 執行個體名稱。
- 如要刪除執行個體,請依序點選 >「Delete」(刪除),然後按照指示操作。
後續步驟
- 進一步瞭解 phpMyAdmin。
- 查看 Google Cloud 的參考架構、圖表和最佳做法。歡迎瀏覽 Cloud Architecture Center。