Scaling an App Engine application involves configuring the scaling settings in the app.yaml
file and deploying the changes. I’ll provide an example using the Standard Environment, showing the process for automatic scaling, basic scaling, and manual scaling. The process for the Flexible Environment is similar.
Table of Contents
- Configure the scaling settings in the
app.yaml
file:
a. Automatic Scaling:
runtime: python39
instance_class: F1
automatic_scaling:
min_instances: 1
max_instances: 10
target_cpu_utilization: 0.5
target_throughput_utilization: 0.5
handlers:
- url: /.*
script: auto
b. Basic Scaling:
runtime: python39
instance_class: B1
basic_scaling:
max_instances: 5
idle_timeout: 10m
handlers:
- url: /.*
script: auto
c. Manual Scaling:
runtime: python39
instance_class: F1
manual_scaling:
instances: 2
handlers:
- url: /.*
script: auto
- Deploy the updated
app.yaml
file using the Google Cloud SDK CLI:
gcloud app deploy app.yaml
Unfortunately, there is no direct way to manage App Engine scaling using the GCP Console or Terraform. You must configure scaling settings in the app.yaml
file and deploy the changes using the Google Cloud SDK CLI.
However, you can use Terraform to manage the Google Cloud Build trigger for a Git repository containing the App Engine application code and app.yaml
. When you push changes to the repository, Cloud Build will automatically deploy the updated app.yaml
file.
Here’s a Terraform example for creating a Cloud Build trigger:
resource "google_cloudbuild_trigger" "app_engine_trigger" {
project = "my-gcp-project"
name = "app-engine-trigger"
description = "Deploy App Engine application on Git push"
trigger_template {
repo_name = "my-repo"
branch_name = "main"
}
substitutions = {
_APP_YAML = "path/to/app.yaml"
}
build {
source {
repo_source {
repo_name = "my-repo"
branch_name = "main"
}
}
step {
name = "gcr.io/cloud-builders/gcloud"
args = [
"app", "deploy", "${var._APP_YAML}"
]
}
}
}
After applying the Terraform configuration, pushing changes to the app.yaml
file in the Git repository will trigger a Cloud Build job that deploys the updated settings to App Engine.
Leave a Reply