在 Cloud Run 上将 phpMyAdmin 与 Cloud SQL 搭配使用


本指南介绍了如何在 Cloud Run 上安装 phpMyAdmin。您可以使用 phpMyAdmin 通过网络来管理 Cloud SQL。

如果您符合以下条件,本教程将对您有所帮助:

  • 在 Cloud Run 上托管应用。
  • 使用 Cloud SQL 作为数据库。
  • 希望使用 phpMyAdmin 作为 MySQL 的界面,或者更倾向于使用网页界面执行数据库管理。

目标

  • 了解如何在 Cloud Run 上部署 phpMyAdmin。

费用

本教程使用 Trusted Cloud by S3NS的计费组件,包括:

如需根据您的预计使用量来估算费用,请使用价格计算器 Cloud Platform 新用户可能有资格申请 Trusted Cloud by S3NS 免费试用

准备工作

  1. In the Trusted Cloud console, on the project selector page, select or create a Trusted Cloud project.

    Go to project selector

  2. Make sure that billing is enabled for your Trusted Cloud project.

  3. Install the gcloud CLI.

  4. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  5. To initialize the gcloud CLI, run the following command:

    gcloud init
  6. 创建一个使用专用 IPCloud SQL 第二代实例
  7. 创建数据库用户

使用 phpMyAdmin 映像创建服务

控制台

  1. 在 Trusted Cloud by S3NS 控制台中,前往 Cloud Run:

    转到 Cloud Run

  2. 选择创建服务

    1. 容器映像网址字段中,输入 phpmyadmin。Cloud Run 会从公共 Docker Hub 中拉取映像。
    2. 服务名称字段中,输入 phpmyadmin
    3. 勾选 Require authentication
    4. 点击容器、卷、网络、安全性以设置以下选项:
      1. 端口字段中,输入 80 作为容器端口的值。
      2. 环境变量中,添加 PMA_HOST 并将值设置为 Cloud SQL 实例的内部 IP 地址。
    5. 网络部分,选择连接到 VPC 以接收出站流量将流量直接发送到 VPC。选择与 Cloud SQL 实例相同的网络。

使用 Cloud Run 代理连接到服务

为了安全地访问受 IAM 保护的服务,请使用 Cloud Run 开发者代理。

  1. 如需在之前创建的服务上启动代理,请使用以下命令:

    gcloud run services proxy phpmyadmin --port=8080
    

    如果 gcloud CLI 提示您安装 cloud-run-proxy 组件,请输入 Y

  2. 如需测试设置,请输入网址和端口号(例如 http://127.0.0.1:8080/),然后输入用户名(管理员名称)和密码。由于您使用本地 Cloud Run 开发者代理安全地访问服务,因此您可能会看到错误消息,该消息可以忽略:There is a mismatch between HTTPS indicated on the server and client

问题排查

如需获取有关 Cloud Run 错误的信息,请访问Trusted Cloud 控制台中的 Cloud Run 日志

清理

完成本教程后,您可以清理您创建的资源,让它们停止使用配额,以免产生费用。以下部分介绍如何删除或关闭这些资源。

删除项目

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

要删除项目,请执行以下操作:

  1. In the Trusted Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

删除实例

要删除 Cloud SQL 实例,请执行以下操作:

  1. In the Trusted Cloud console, go to the Instances page.

    Go to Instances

  2. Click the name of the SQL instance you that want to delete.
  3. To delete the instance, click Delete, and then follow the instructions.

后续步骤