如果您執行下列操作,會發現這份教學課程非常有幫助:
- 在 Cloud Run 上託管應用程式。
- 使用 Cloud SQL 做為您的資料庫。
- 想使用 phpMyAdmin 做為 MySQL 的介面,或者偏好使用網路介面執行資料庫管理。
必要條件
- 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.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
- 建立採用私人 IP 的 Cloud SQL 第二代執行個體。
- 建立資料庫使用者。
前往 Google Cloud 控制台的 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
。
使用 phpMyAdmin 映像檔建立服務
控制台
使用 Cloud Run Proxy 連線至服務
如要安全存取受 IAM 保護的服務,請使用 Cloud Run 開發人員 Proxy。
疑難排解
如要取得 Cloud Run 錯誤的相關資訊,請在 Google Cloud 控制台中存取 Cloud Run 記錄。