创建具有配置依赖项的应用

在本快速入门中,您将根据示例应用设置具有配置依赖项的应用,然后单独部署应用的各个部分。

准备工作

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Google Kubernetes Engine API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Google Kubernetes Engine API.

    Enable the API

  8. 安装 Git。 将示例复制到您的计算机需要使用 Git。
  9. 如果您尚未安装 Cloud Code 插件,请先安装该插件。

创建应用

  1. 克隆 Bank of Anthos 代码库:

    1. 在顶部菜单栏中,依次点击 Terminal(终端)> New Terminal(新建终端)。
    2. 克隆 Bank of Anthos 代码库:

      git clone https://github.com/GoogleCloudPlatform/bank-of-anthos.git
      
  2. 如需打开基于 Anthos 银行的工作区,请在 VS Code 中依次点击 File(文件)> Open folder(打开文件夹),然后前往克隆代码库的文件夹。

  3. 双击 skaffold.yaml 文件。

    1. 该文件包含多个配置,这些配置由 YAML 文档分隔符 (---) 分隔。每个配置都可以单独部署或作为依赖项进行引用。

      ---
      apiVersion: skaffold/v2beta18
      kind: Config
      
    2. 指定了名称的配置称为 Skaffold 模块。以下代码段定义了 frontend 模块。

      metadata:
      name: frontend # module defining frontend service
      
    3. 配置之间的依赖项使用 configs 标记指定。必须先部署必需的配置,然后才能部署当前配置。该示例展示了同一文件中定义的依赖项。configs 标记还可以引用当前项目中的其他 skaffold.yaml 文件。

      requires:
      - configs: [db]
      

部署模块

  1. 打开 Command Palette (Ctrl/Cmd+Shift+P),然后运行 Cloud Code: Run on Kubernetes
  2. 点击选择模块
  3. 选择要部署的模块,然后点击确定

    如果您点击 db,系统会构建 db 配置以及所需的 setup 配置。

  4. 出现提示时,选择一个映像注册表,然后按 Enter

清理

终止应用后,系统会自动删除在运行期间部署的所有 Kubernetes 资源。

如需避免系统因本快速入门中使用的其他资源向您的账号收取费用,请务必删除您创建的集群和项目。

如果您使用的是 Google Cloud ,且只想删除集群,则可以按照以下步骤操作:

  1. 点击 Cloud Code,然后展开 Kubernetes 探索器。
  2. 将光标悬停在集群名称上,然后点击 open_in_new 在 Google Cloud 控制台中打开
  3. 点击删除,然后再次点击删除进行确认。

如需删除项目(以及关联的资源,包括所有集群),请执行以下操作:

  1. 进入 Google Cloud 控制台中的“项目”页面:

    转到“项目”页面

  2. 选择您为本快速入门创建的项目,然后点击删除

  3. 输入项目 ID 进行确认,然后点击关停

    这将关闭该项目并安排将其删除。

后续步骤