如果您執行下列操作,會發現這份教學課程非常有幫助:
- 在 Cloud Run 上託管應用程式。
- 使用 Cloud SQL 做為您的資料庫。
- 想使用 phpMyAdmin 做為 MySQL 的介面,或者偏好使用網路介面執行資料庫管理。
目標
- 瞭解如何在 Cloud Run 上部署 phpMyAdmin。
費用
本教學課程使用 Trusted Cloud by S3NS的計費元件,包括:
如要根據預測用量估算費用,請使用 Pricing Calculator。
事前準備
-
In the Trusted Cloud console, on the project selector page, select or create a Trusted 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.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Trusted Cloud project.
-
Install the gcloud CLI.
-
設定 gcloud CLI 以使用您的聯合身分。
詳情請參閱「 使用聯合身分登入 gcloud CLI」。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
- 建立採用私人 IP 的 Cloud SQL 第二代執行個體。
- 建立資料庫使用者。
前往 Trusted Cloud by S3NS 控制台的 Cloud Run:
選取「建立服務」。
- 在「Container image」(容器映像檔) 網址欄位中,輸入
phpmyadmin
。Cloud Run 會從公開的 Docker Hub 提取映像檔。 - 在「Service name」(服務名稱) 欄位中輸入
phpmyadmin
。 - 請檢查
Require authentication
。 - 按一下「容器、磁碟區、網路與安全性」,設定下列選項:
- 在「Port」(通訊埠) 欄位中,輸入
80
做為容器通訊埠的值。 - 在「環境變數」中新增
PMA_HOST
,並將值設為 Cloud SQL 執行個體的內部 IP 位址。
- 在「Port」(通訊埠) 欄位中,輸入
在「Networking」(網路) 中,選取「Connect to a VPC for outbound traffic」(連線至虛擬私有雲,以傳出流量) 和「Send traffic directly to a VPC」(直接將流量傳送至虛擬私有雲)。選擇與 Cloud SQL 執行個體相同的網路。
- 在「Container image」(容器映像檔) 網址欄位中,輸入
如要在先前建立的服務上啟動 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
。- In the Trusted 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.
- In the Trusted Cloud console, go to the Instances page.
- Click the name of the SQL instance you that want to delete.
- To delete the instance, click Delete, and then follow the instructions.
- 進一步瞭解 phpMyAdmin。
- 探索 Google Cloud 的參考架構、圖表和最佳做法。 歡迎瀏覽我們的雲端架構中心。
使用 phpMyAdmin 映像檔建立服務
控制台
使用 Cloud Run Proxy 連線至服務
如要安全存取受 IAM 保護的服務,請使用 Cloud Run 開發人員 Proxy。
疑難排解
如要取得 Cloud Run 錯誤的相關資訊,請在 Trusted Cloud 控制台中存取 Cloud Run 記錄。
清除所用資源
完成教學課程後,您可以清除所建立的資源,這樣資源就不會繼續使用配額,也不會產生費用。下列各節將說明如何刪除或關閉這些資源。
刪除專案
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案:
刪除執行個體
如要刪除 Cloud SQL 執行個體: