使用 app.yaml 配置应用

App Engine 应用是使用 app.yaml 文件进行配置的,该文件包含 CPU、内存、网络和磁盘资源设置、扩缩设置以及环境变量等其他常规设置。

app.yaml 文件简介

您可以在 app.yaml 文件中指定 .NET 应用的运行时配置,包括版本和网址。该文件充当特定服务版本的部署描述符。

您必须先为应用的 default 服务创建 app.yaml 文件,然后才能为其他服务创建和部署 app.yaml 文件。

以下 app.yaml 演示了对于 .NET 3.1 版及更低版本和版本 6 及更高版本,如何配置您的应用。请注意,您必须更新 app.yaml 文件才能使用新版本。如需详细了解如何使用新版运行时,请参阅 .NET 运行时

版本 6 及更高版本

runtime: aspnetcore
env: flex

runtime_config:
  operating_system: ubuntu22

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

env_variables:
  # The __ in My__Greeting will be translated to a : by ASP.NET.
  My__Greeting: Hello AppEngine!

3.1 版及更低版本

runtime: aspnetcore
env: flex

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

env_variables:
  # The __ in My__Greeting will be translated to a : by ASP.NET.
  My__Greeting: Hello AppEngine!
您可能只需在相应的 app.yaml 文件中定义几个元素,具体取决于应用服务的复杂程度。以下示例演示了柔性环境中的简单 .NET 应用可能需要定义的元素:

您可以为 app.yaml 文件指定一个独特的名称,但还必须使用部署命令指定该文件名。例如,如果您将 app.yaml 文件命名为 service-name-app.yamlapp.flexible.yaml,则必须使用下列任一命令部署您的应用:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
如需详细了解如何在应用中设计多个服务和 app.yaml 文件的结构,请参阅设计 Web 服务的结构

所有配置元素

如需查看此配置文件中所有受支持的元素的完整列表,请参阅 app.yaml 参考文档