Enable services, create an artifact registry and the GKE cluster

检查我的进度

/ 20

Create a container image with Cloud Build

检查我的进度

/ 20

Create the Continuous Integration (CI) Pipeline

检查我的进度

/ 20

Store SSH key secret in Secret Manager

检查我的进度

/ 20

Create the Test Environment and CD Pipeline

检查我的进度

/ 20

此实验可能会提供 AI 工具来支持您学习。
此内容尚未针对移动设备进行优化。
为获得最佳体验,请在桌面设备上访问通过电子邮件发送的链接。

GSP1077

Google Cloud 自学实验

概览

Cloud Build 是一项服务,可以在 Google Cloud 上执行您的构建任务。它可以完成导入源代码、执行构建等任务。

在本实验中,您将创建一个持续集成和持续部署 (CI/CD) 流水线。该流水线可以根据提交的代码自动构建容器映像,将映像存储在 Artifact Registry 中,更新 Git 代码库中的 Kubernetes 清单,并使用该清单将应用部署到 Google Kubernetes Engine。

CI/CD 流程

在本实验中,您将使用托管在专用自托管 Gitea Git 服务器 (git-server) 上的 2 个 Git 代码库:

  • app:包含应用的源代码 (hello-cloudbuild-app)
  • env:包含 Kubernetes 部署清单 (hello-cloudbuild-env)

当您将更改推送到 app 代码库时,Cloud Build 流水线会运行测试、构建容器映像,并将映像推送到 Artifact Registry。推送映像后,Cloud Build 会更新部署清单,并将清单推送到 env 代码库。这会触发另一个 Cloud Build 流水线,该流水线会将清单应用于 GKE 集群;如果部署成功,它还会将该清单存储到 env 代码库的另一个分支中。

分别设立 app 代码库和 env 代码库,是因为两者的生命周期和用途不同。app 代码库专用于特定应用,主要由真实用户使用。env 代码库可能由多个应用共享,供自动化系统(例如 Cloud Build)使用。env 代码库可以有多个分支,每个分支映射到特定环境并引用特定的容器映像;app 代码库则不会有多个分支。

完成本实验后,您的系统将能够轻松实现以下操作:

  • 查看 Cloud Build 历史记录,以区分失败和成功的部署。
  • 查看 env 代码库的生产分支,以访问当前使用的清单。
  • 重新执行相应的 Cloud Build 构建作业,以回滚到以前的任何版本。

GitOps 流程

目标

在本实验中,您将学习如何执行以下任务:

  • 创建 Kubernetes Engine 集群。
  • 连接到专用 Git 服务器并初始化 Git 代码库。
  • 从源代码库执行 Cloud Build 流水线。
  • 通过 Cloud Build 进行自动测试并发布可部署的容器映像。
  • 通过 Cloud Build 管理部署在 Kubernetes Engine 集群中的资源。

设置和要求

点击“开始实验”按钮前的注意事项

请阅读以下说明。实验是计时的,并且您无法暂停实验。计时器在您点击开始实验后即开始计时,显示 Google Cloud 资源可供您使用多长时间。

此实操实验可让您在真实的云环境中开展实验活动,免受模拟或演示环境的局限。为此,我们会向您提供新的临时凭据,您可以在该实验的规定时间内通过此凭据登录和访问 Google Cloud。

为完成此实验,您需要:

  • 能够使用标准的互联网浏览器(建议使用 Chrome 浏览器)。
注意:请使用无痕模式(推荐)或无痕浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。
  • 完成实验的时间 - 请注意,实验开始后无法暂停。
注意:请仅使用学生账号完成本实验。如果您使用其他 Google Cloud 账号,则可能会向该账号收取费用。

如何开始实验并登录 Google Cloud 控制台

  1. 点击开始实验按钮。如果该实验需要付费,系统会打开一个对话框供您选择支付方式。右侧是实验设置和访问权限面板,其中包含以下内容:

    • 打开 Google Cloud 控制台按钮
    • 您在本实验中必须使用的临时凭证(用户名和密码)
    • 帮助您逐步完成该实验所需的其他信息(如果需要)

    请注意,实验计时器位于页面顶部附近,将显示剩余时间。

  2. 点击打开 Google Cloud 控制台(如果您使用的是 Chrome 浏览器,请右键点击并选择在无痕式窗口中打开链接)。

    该实验会启动资源并打开另一个标签页,显示“登录”页面。

    提示:可以将这些标签页分别放在不同的窗口中,并排显示。

    注意:如果您看见选择账号对话框,请点击使用其他账号。
  3. 如有必要,请复制下方的用户名,然后将其粘贴到登录对话框中。

    {{{user_0.username | "<用户名>"}}}

    您也可以在实验设置和访问权限面板中找到“用户名”。

  4. 点击下一步。

  5. 复制下面的密码,然后将其粘贴到欢迎对话框中。

    {{{user_0.password | "<密码>"}}}

    您也可以在实验设置和访问权限面板中找到“密码”。

  6. 点击下一步。

    重要提示:您必须使用实验提供的凭证。请勿使用您的 Google Cloud 账号凭证。 注意:在本实验中使用您自己的 Google Cloud 账号可能会产生额外费用。
  7. 依次点击进入后续页面:

    • 接受条款及条件。
    • 由于这是临时账号,请勿添加账号恢复选项或双重身份验证。
    • 请勿注册免费试用。

片刻之后,系统会在此标签页中打开 Google Cloud 控制台。

注意:如需访问 Google Cloud 产品和服务,请点击导航菜单,或在搜索字段中输入服务或产品的名称。 “导航菜单”图标和“搜索”字段

激活 Cloud Shell

Cloud Shell 是一种装有开发者工具的虚拟机。它提供了一个永久性的 5GB 主目录,并且在 Google Cloud 上运行。Cloud Shell 提供可用于访问您的 Google Cloud 资源的命令行工具。

  1. 点击 Google Cloud 控制台顶部的激活 Cloud Shell “激活 Cloud Shell”图标。

  2. 在弹出的窗口中执行以下操作:

    • 继续完成 Cloud Shell 信息窗口中的设置。
    • 授权 Cloud Shell 使用您的凭据进行 Google Cloud API 调用。

如果您连接成功,即表示您已通过身份验证,且项目 ID 会被设为您的 Project_ID 。输出内容中有一行说明了此会话的 Project_ID:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud 是 Google Cloud 的命令行工具。它已预先安装在 Cloud Shell 上,且支持 Tab 自动补全功能。

  1. (可选)您可以通过此命令列出活跃账号名称:
gcloud auth list
  1. 点击授权。

输出:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (可选)您可以通过此命令列出项目 ID:
gcloud config list project

输出:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} 注意:如需查看在 Google Cloud 中使用 gcloud 的完整文档,请参阅 gcloud CLI 概览指南。

任务 1. 对实验进行初始化

在此任务中,您将设置自己的环境:

  • 导入项目 ID、项目编号和 Git 服务器 IP 作为变量
  • 启用 GKE、Cloud Build、Secret Manager 和 Artifact Analysis 的 API
  • 创建 Artifact Registry Docker 仓库
  • 创建一个 GKE 集群,用于部署本实验的示例应用
  1. 在 Cloud Shell 中,运行以下命令来设置项目 ID、项目编号和区域:
export PROJECT_ID=$(gcloud config get-value project) export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)') export REGION={{{ project_0.default_region }}} gcloud config set compute/region $REGION export GIT_SERVER_IP=$(gcloud compute instances describe git-server --zone={{{ project_0.default_zone }}} --format='get(networkInterfaces[0].accessConfigs[0].natIP)') echo "Git Server IP is: ${GIT_SERVER_IP}"
  1. 运行以下命令,为 GKE、Cloud Build、Secret Manager 和 Artifact Analysis 启用 API:
gcloud services enable container.googleapis.com \ cloudbuild.googleapis.com \ secretmanager.googleapis.com \ containeranalysis.googleapis.com
  1. 在 区域创建名为 my-repository 的 Artifact Registry Docker 仓库,用于存储容器映像:
gcloud artifacts repositories create my-repository \ --repository-format=docker \ --location=$REGION
  1. 创建一个 GKE 集群,用于部署本实验的示例应用:
gcloud container clusters create hello-cloudbuild --num-nodes 1 --region $REGION
  1. 运行以下命令,在 Cloud Shell 中配置 Git: git config --global user.name "giteaadmin" git config --global user.email "student@qwiklabs.net"

点击检查我的进度以验证是否完成了以下目标: 启用服务,创建 Artifact Registry 和 GKE 集群

任务 2. 连接到 Git 服务器上的 Git 代码库

在此任务中,您将在专用 Git 服务器 (git-server) 上初始化两个 Git 代码库(hello-cloudbuild-app 和 hello-cloudbuild-env),并推送初始示例代码。

  1. 从 Cloud Storage 下载示例代码:
cd ~ git clone http://${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-app.git

您克隆的代码包含一个简单的“Hello World”应用:

from flask import Flask app = Flask('hello-cloudbuild') @app.route('/') def hello(): return "Hello World!\n" if __name__ == '__main__': app.run(host = '0.0.0.0', port = 8080)

任务 3. 使用 Cloud Build 创建容器映像

在此任务中,您将使用现有的 Dockerfile,通过 Cloud Build 创建并存储一个容器映像。

您之前克隆的代码包含以下 Docker 文件:

FROM python:3.11-slim RUN pip install flask WORKDIR /app COPY app.py /app/app.py ENTRYPOINT ["python"] CMD ["/app/app.py"]

有了此 Dockerfile,您便可使用 Cloud Build 来创建一个容器映像,并将其存储在 Artifact Registry 中。

  1. 在 Cloud Shell 中,基于最近的提交,使用以下命令创建一个 Cloud Build 构建作业:
cd ~/hello-cloudbuild-app COMMIT_ID="$(git rev-parse --short=7 HEAD)" gcloud builds submit --tag="${REGION}-docker.pkg.dev/${PROJECT_ID}/my-repository/hello-cloudbuild:${COMMIT_ID}" .

您执行此命令时,Cloud Build 会将创建容器映像过程生成的日志流式传输到终端。

  1. 构建完成后,在 Google Cloud 控制台标题栏的搜索字段中输入 Artifact Registry,然后点击搜索结果中的 Artifact Registry。验证您的新容器映像在 Artifact Registry 中确实可用。点击 my-repository,在映像列表中查看 hello-cloudbuild 映像。

点击检查我的进度以验证是否完成了以下目标: 使用 Cloud Build 创建容器映像

任务 4. 创建并运行持续集成 (CI) 流水线

在此任务中,您将配置并运行 Cloud Build,使其自动运行单元测试、构建容器映像,并将映像推送到 Artifact Registry。

架构

已包含在代码中的 cloudbuild.yaml 文件是该流水线的配置。

  1. 提交更改并将其推送到 Git 服务器:
cd ~/hello-cloudbuild-app git add . git commit -m "Trigger CI pipeline" git push http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-app.git main
  1. 使用以下命令将构建作业提交到 Cloud Build:
gcloud builds submit --config=cloudbuild.yaml --substitutions=SHORT_SHA=$(git rev-parse --short=7 HEAD) .
  1. 在 Google Cloud 控制台中,搜索 Cloud Build,然后点击左侧窗格中的历史记录。您可以检查 CI 构建的执行日志。

点击检查我的进度以验证是否完成了以下目标: 创建持续集成 (CI) 流水线

任务 5. 将 SSH 密钥 Secret 存储在 Secret Manager 中

在此步骤中,您将在 Secret Manager 中存储私钥 Secret,并向 Cloud Build 授予访问 Secret Manager 的权限。

创建 SSH 密钥并将其存储在 Secret Manager 中

  1. 在 Cloud Shell 中,创建 SSH 密钥:

    mkdir -p ~/workingdir && cd ~/workingdir ssh-keygen -t rsa -b 4096 -N '' -f id_rsa -C "student@qwiklabs.net"
  2. 在 Cloud Shell 中运行以下命令,将 SSH 私钥存储在 Secret Manager 中:

gcloud secrets create ssh_key_secret --data-file=$HOME/workingdir/id_rsa

或者,您也可以在 Google Cloud 控制台中进行以下操作: a. 首先将 id_rsa 下载到您的计算机:在 Cloud Shell 中,点击更多 (“更多”图标) > 下载文件,输入 workingdir/id_rsa,然后点击下载。 b. 搜索 Secret Manager,然后点击 Secret Manager。 c. 点击创建 Secret。 d. 将名称设置为 ssh_key_secret。 e. 在 Secret 值下,选择上传,然后上传下载的 id_rsa 文件。 f. 点击创建 Secret。

授予服务账号访问 Secret Manager 的权限

在 Cloud Shell 中运行以下命令,向 Compute Engine 默认服务账号授予访问 Secret Manager 的权限:

PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format='value(projectNumber)') gcloud projects add-iam-policy-binding ${PROJECT_NUMBER} \ --member=serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com \ --role=roles/secretmanager.secretAccessor

点击检查我的进度以验证是否完成了以下目标: 在 Secret Manager 中存储 SSH 密钥 Secret

任务 6. 创建测试环境和 CD 流水线

您还可以使用 Cloud Build 构建持续交付流水线。每次将提交推送到 hello-cloudbuild-env 代码库的候选分支时,该流水线都会运行。该流水线会将新版本的清单应用于 Kubernetes 集群,如果成功,则将清单复制到生产分支。此过程具有以下属性:

  • 候选分支是部署尝试的历史记录。
  • 生产分支是成功部署的历史记录。
  • 您可以在 Cloud Build 中查看成功和失败的部署。
  • 您可以在 Cloud Build 中重新执行相应的构建作业,从而回滚到任何先前的部署。回滚还会更新生产分支,以真实反映部署的历史记录。

接下来,您将修改此持续集成流水线,以更新 hello-cloudbuild-env 代码库的候选分支,从而触发持续交付流水线。

为 Cloud Build 授予 GKE 的访问权限

要在 Kubernetes 集群中部署应用,Cloud Build 需要 Kubernetes Engine Developer 这一角色。

  1. 在 Cloud Shell 中,执行以下命令:
PROJECT_NUMBER="$(gcloud projects describe ${PROJECT_ID} --format='get(projectNumber)')" gcloud projects add-iam-policy-binding ${PROJECT_NUMBER} \ --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \ --role=roles/container.developer

您需要使用生产分支和候选分支以及描述部署过程的 Cloud Build 配置文件对 hello-cloudbuild-env 代码库进行初始化。

  1. 在 Cloud Shell 中,从 Cloud Storage 下载示例代码:
cd ~ git clone http://${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git
  1. 在 Cloud Shell 中,运行以下命令,替换 hello-cloudbuild-env 代码库中 cloudbuild.yaml 的内容:
cd ~/hello-cloudbuild-env cat <<'EOF' > cloudbuild.yaml # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. substitutions: _COMMIT_SHA: 'v1.0' steps: # This step deploys the new version of our container image # in the hello-cloudbuild Kubernetes Engine cluster. - name: 'gcr.io/cloud-builders/kubectl' id: Deploy args: - 'apply' - '-f' - 'kubernetes.yaml' env: - 'CLOUDSDK_COMPUTE_REGION={{{ project_0.default_region }}}' - 'CLOUDSDK_CONTAINER_CLUSTER=hello-cloudbuild' # This step copies the applied manifest to the production branch - name: 'gcr.io/cloud-builders/gcloud' id: Copy to production branch entrypoint: /bin/sh args: - '-c' - | set -x && \ git clone -b production http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git prod_repo && \ cd prod_repo && \ git config user.email "student@qwiklabs.net" && \ git config user.name "Cloud Build" && \ cp ../kubernetes.yaml kubernetes.yaml && \ git add kubernetes.yaml && \ git commit -m "Deployed manifest from commit $_COMMIT_SHA" && \ git push origin production options: logging: CLOUD_LOGGING_ONLY EOF sed -i "s/\${GIT_SERVER_IP}/$GIT_SERVER_IP/g" cloudbuild.yaml

提交并将更新推送到 hello-cloudbuild-env:

cd ~/hello-cloudbuild-env git checkout candidate git add cloudbuild.yaml git commit -m "Create cloudbuild.yaml for deployment" git push http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git candidate

修改持续集成流水线以触发持续交付流水线

接下来,更新 hello-cloudbuild-app 中的持续集成流水线,以生成新版本的 Kubernetes 清单并将其推送到 hello-cloudbuild-env,从而触发 CD 流水线。

  1. 在 Cloud Shell 中,运行以下命令来替换 hello-cloudbuild-app 中的 cloudbuild.yaml,并将其中占位符替换为您自己的 Git 服务器 IP:
cd ~/hello-cloudbuild-app cat <<'EOF' > cloudbuild.yaml # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. substitutions: _SHORT_SHA: 'v1.0' _COMMIT_SHA: 'v1.0' steps: # This step runs the unit tests on the app - name: 'python:3.11-slim' id: Test entrypoint: /bin/sh args: - -c - 'pip install flask && python test_app.py -v' # This step builds the container image. - name: 'gcr.io/cloud-builders/docker' id: Build args: - 'build' - '-t' - '{{{ project_0.default_region }}}-docker.pkg.dev/$PROJECT_ID/my-repository/hello-cloudbuild:$_SHORT_SHA' - '.' # This step pushes the image to Artifact Registry - name: 'gcr.io/cloud-builders/docker' id: Push args: - 'push' - '{{{ project_0.default_region }}}-docker.pkg.dev/$PROJECT_ID/my-repository/hello-cloudbuild:$_SHORT_SHA' # This step clones the hello-cloudbuild-env repository - name: 'gcr.io/cloud-builders/gcloud' id: Clone env repo entrypoint: /bin/sh args: - '-c' - | git clone http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git && \ cd hello-cloudbuild-env && \ git checkout candidate && \ git config user.email "student@qwiklabs.net" && \ git config user.name "Cloud Build" # This step generates the new manifest - name: 'gcr.io/cloud-builders/gcloud' id: Generate manifest entrypoint: /bin/sh args: - '-c' - | sed "s/GOOGLE_CLOUD_PROJECT/${PROJECT_ID}/g" kubernetes.yaml.tpl | \ sed "s/COMMIT_SHA/${_SHORT_SHA}/g" > hello-cloudbuild-env/kubernetes.yaml # This step pushes the manifest back to hello-cloudbuild-env candidate branch - name: 'gcr.io/cloud-builders/gcloud' id: Push manifest entrypoint: /bin/sh args: - '-c' - | set -x && \ cd hello-cloudbuild-env && \ git add kubernetes.yaml && \ git commit -m "Deploying image {{{ project_0.default_region }}}-docker.pkg.dev/$PROJECT_ID/my-repository/hello-cloudbuild:${_SHORT_SHA} Built from commit ${_COMMIT_SHA} of repository hello-cloudbuild-app Author: $(git log --format='%an <%ae>' -n 1 HEAD)" && \ git push origin candidate options: logging: CLOUD_LOGGING_ONLY EOF sed -i "s/\${GIT_SERVER_IP}/$GIT_SERVER_IP/g" cloudbuild.yaml
  1. 提交修改,将其推送到 Git 服务器,然后提交流水线构建作业:
cd ~/hello-cloudbuild-app git add cloudbuild.yaml git commit -m "Trigger CD pipeline" git push http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-app.git main gcloud builds submit --config=cloudbuild.yaml --substitutions=_SHORT_SHA=$(git rev-parse --short=7 HEAD),_COMMIT_SHA=$(git rev-parse HEAD) .

这会触发 Cloud Build 中的持续集成流水线,该流水线会构建应用映像,并将新的 kubernetes.yaml 清单推送到 hello-cloudbuild-env 代码库。

  1. 拉取 hello-cloudbuild-env 中生成的清单,并触发持续交付 (CD) 部署构建作业:
cd ~/hello-cloudbuild-env git pull http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git candidate gcloud builds submit --config=cloudbuild.yaml --substitutions=_COMMIT_SHA=$(git rev-parse HEAD) .

点击检查我的进度以验证是否完成了以下目标: 创建测试环境和 CD 流水线

任务 7. 审核 Cloud Build 流水线

在此任务中,您将在控制台中审核 Cloud Build 流水线。

  1. 在控制台中,前往 Cloud Build > 历史记录。
  2. 点击最近的构建作业,以跟踪其执行情况并检查其日志。
  3. 验证构建流水线是否成功执行了所有步骤。

任务 8. 测试完整的流水线

现在,您已配置了完整的 CI/CD 流水线。在此任务中,您将执行端到端测试。

  1. 在控制台的导航菜单 (“导航菜单”图标) 中,点击 Kubernetes Engine > 网关、服务和入站流量 > 服务。

列表中应该有一个名为 hello-cloudbuild 的服务。该服务是由刚刚运行的持续交付构建作业所创建。

  1. 点击 hello-cloudbuild 服务的端点。您应该会看到“Hello World!”。如果没有端点,或者如果您看到负载均衡器错误,则可能需要等待几分钟,以便负载均衡器完成初始化。如果需要,点击刷新以更新该页面。

应用 1:Hello World!

  1. 在 Cloud Shell 中,在应用和单元测试中将“Hello World”替换为“Hello Cloud Build”:
cd ~/hello-cloudbuild-app sed -i 's/Hello World/Hello Cloud Build/g' app.py sed -i 's/Hello World/Hello Cloud Build/g' test_app.py
  1. 提交更改并将其推送到 Git 服务器,然后提交 CI 构建作业:
git add app.py test_app.py git commit -m "Hello Cloud Build" git push http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-app.git main gcloud builds submit --config=cloudbuild.yaml --substitutions=_SHORT_SHA=$(git rev-parse --short=7 HEAD),_COMMIT_SHA=$(git rev-parse HEAD) .
  1. 将更新后的清单拉取到 hello-cloudbuild-env 中,并提交部署流水线构建作业以部署新的应用版本:
cd ~/hello-cloudbuild-env git pull http://giteaadmin:GiteaPassword123@${GIT_SERVER_IP}:3000/giteaadmin/hello-cloudbuild-env.git candidate gcloud builds submit --config=cloudbuild.yaml --substitutions=_COMMIT_SHA=$(git rev-parse HEAD) .

几分钟后,在浏览器中重新加载应用。您现在应该会看到“Hello Cloud Build!”。

应用 2:Hello Cloud Build!

任务 9. 测试回滚

在此任务中,您将回滚到显示“Hello World!”的应用版本。

  1. 在控制台标题栏的搜索字段中,输入 Cloud Build 信息中心,然后点击搜索结果中的 Cloud Build。确保在左侧窗格中选择了历史记录。
  2. 在构建历史记录中,点击所列出的第二新的构建作业。
  3. 点击重建。

“回滚成功”界面

完成构建作业后,在浏览器中重新加载应用。您现在应该会再次看到“Hello World!”。

应用 1:Hello World!

恭喜!

现在,您可以使用 Cloud Build 在 GKE on Google Cloud 中创建和回滚持续集成流水线了。

Google Cloud 培训和认证

…可帮助您充分利用 Google Cloud 技术。我们的课程会讲解各项技能与最佳实践,可帮助您迅速上手使用并继续学习更深入的知识。我们提供从基础到高级的全方位培训,并有点播、直播和虚拟三种方式选择,让您可以按照自己的日程安排学习时间。各项认证可以帮助您核实并证明您在 Google Cloud 技术方面的技能与专业知识。

上次更新手册的时间:2026 年 7 月 20 日

上次测试实验的时间:2026 年 7 月 20 日

版权所有 2026 Google LLC 保留所有权利。Google 和 Google 徽标是 Google LLC 的商标。其他所有公司名和产品名可能是其各自相关公司的商标。

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

使用无痕浏览模式

  1. 复制系统为实验提供的用户名和密码
  2. 在无痕浏览模式下,点击打开控制台

登录控制台

  1. 使用您的实验凭证登录。使用其他凭证可能会导致错误或产生费用。
  2. 接受条款,并跳过恢复资源页面
  3. 除非您已完成此实验或想要重新开始,否则请勿点击结束实验,因为点击后系统会清除您的工作并移除该项目

此内容目前不可用

一旦可用,我们会通过邮件告知您

太好了!

一旦可用,我们会通过邮件联系您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

使用无痕模式或无痕浏览器窗口是运行此实验的最佳方式。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。