# Connect Google Cloud

Step 1 of `https://infrapilot.fly/docs/onboard.md`. You create a service account for Pilot, grant it roles, and let Infrapilot use it. Where offered, no key is created: Infrapilot impersonates the account an hour at a time.


## Before you start

```bash
gcloud config get-value project
gcloud config get-value account
```

Confirm the project and region with the person. You need `roles/iam.serviceAccountAdmin` and `roles/resourcemanager.projectIamAdmin`, or Owner.

## 1. Enable the APIs

```bash
PROJECT=<project id>
# What Pilot reads through, on every project
gcloud services enable --project $PROJECT \
  cloudasset.googleapis.com monitoring.googleapis.com logging.googleapis.com \
  cloudresourcemanager.googleapis.com iamcredentials.googleapis.com
```

Existing services already have their APIs on. For workloads Pilot will build, enable:

| Workload kind or service | API |
| --- | --- |
| `http-service`, `worker`, Cloud Run | `run.googleapis.com` |
| `queue`, `worker`, Pub/Sub | `pubsub.googleapis.com` |
| `bucket`, Cloud Storage | `storage.googleapis.com` |
| Managed instance groups, load balancers | `compute.googleapis.com` |
| Cloud SQL | `sqladmin.googleapis.com` |
| Cloud Functions | `cloudfunctions.googleapis.com` |
| Memorystore for Redis | `redis.googleapis.com` |
| Memorystore for Valkey | `memorystore.googleapis.com` |
| Cloud Run jobs | `run.googleapis.com` |
| Cloud Scheduler | `cloudscheduler.googleapis.com` |
| `database` | `sqladmin.googleapis.com`, `servicenetworking.googleapis.com`, `compute.googleapis.com` |
| `cache` | `redis.googleapis.com`, `compute.googleapis.com` |
| `schedule` | `run.googleapis.com`, `cloudscheduler.googleapis.com` |
| `secrets:` in a workload's spec | `secretmanager.googleapis.com` |
| Actual cost (the billing export) | `bigquery.googleapis.com` |

## 2. Create the service account and grant roles

Name the account exactly as Infrapilot says: `connection.trust.service_account_name` in `GET /api/v1/setup` (it looks like `infrapilot-1a2b3c4d5e6f7a8b`). The name ties the account to this workspace, and keyless access is refused for any other name.

```bash
SA_NAME=<connection.trust.service_account_name>
gcloud iam service-accounts create $SA_NAME --project $PROJECT \
  --display-name "Infrapilot agent"
SA=$SA_NAME@$PROJECT.iam.gserviceaccount.com

# Read: find resources by label, read metrics, read the audit log
for ROLE in roles/cloudasset.viewer roles/monitoring.viewer roles/logging.viewer roles/browser; do
  gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" --role $ROLE --condition None
done
```

**For level observe, stop here**, after adding the read-only viewer roles for the services the fleet has, and submit the connection with `"access": "observe"` (step 3):

```bash
for ROLE in roles/viewer roles/logging.viewer roles/cloudasset.viewer; do
  gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" --role $ROLE --condition None
done
```

`roles/viewer` reads configuration across the project and no data in Cloud SQL or Cloud Storage objects' contents beyond what a project viewer sees; grant per-service viewer roles (`roles/run.viewer`, `roles/cloudsql.viewer`, `roles/compute.viewer`, `roles/pubsub.viewer`) instead if that is too wide. Pilot then reviews the project and the engine refuses every change before it is attempted.

Otherwise grant only the rows the fleet uses:

| The fleet has | Role | Lets Pilot |
| --- | --- | --- |
| Cloud Run services | `roles/run.developer` | tune scaling, concurrency, CPU, memory; create declared services |
| Pub/Sub | `roles/pubsub.editor` | tune subscriptions; create declared topics and subscriptions |
| Managed instance groups | `roles/compute.viewer` and custom `infrapilotCompute` (below) | tune autoscalers and resize groups, nothing else |
| Cloud SQL | `roles/cloudsql.viewer` to observe, `roles/cloudsql.editor` to tune | change tier and storage, never data |
| Cloud Functions | `roles/cloudfunctions.viewer` to observe, `roles/cloudfunctions.developer` to tune | change memory, timeout, instance limits |
| Cloud Storage buckets | `roles/storage.bucketViewer` to observe, custom `infrapilotBuckets` (below) to build | read and create buckets; no object access |
| Load balancers, Cloud CDN | custom `infrapilotLoadBalancing` (below) | read routes; tune backend timeouts and Cloud CDN, nothing else |
| Memorystore (Redis, Valkey) | `roles/redis.viewer` / `roles/memorystore.viewer` to observe, custom `infrapilotMemorystore` (below) to tune | resize memory, shards and replicas; never read keys, never delete (creating a declared `cache` is in `infrapilotBuild`) |
| Cloud Run jobs | `roles/run.developer` (the same role as for services) | tune task count, parallelism, timeout, CPU, memory |
| Cloud Scheduler | custom `infrapilotScheduler` (below) | find the schedules of the fleet's jobs; tune retries. Never the schedule or the target |

```bash
gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" --role roles/run.developer --condition None
```

The custom roles avoid much broader predefined ones. Create only what you need:

```bash
gcloud iam roles create infrapilotCompute --project $PROJECT \
  --title "Infrapilot: autoscalers and instance groups" \
  --permissions compute.autoscalers.get,compute.autoscalers.list,compute.autoscalers.update,compute.instanceGroupManagers.get,compute.instanceGroupManagers.list,compute.instanceGroupManagers.update,compute.instanceGroupManagers.use,compute.zoneOperations.get,compute.regionOperations.get,compute.regions.get

gcloud iam roles create infrapilotLoadBalancing --project $PROJECT \
  --title "Infrapilot: load balancing" \
  --permissions compute.urlMaps.get,compute.urlMaps.list,compute.backendServices.get,compute.backendServices.list,compute.backendServices.update,compute.backendBuckets.get,compute.backendBuckets.update,compute.networkEndpointGroups.get,compute.globalOperations.get

gcloud iam roles create infrapilotBuckets --project $PROJECT \
  --title "Infrapilot: buckets" \
  --permissions storage.buckets.create,storage.buckets.get,storage.buckets.list,storage.buckets.update,storage.buckets.delete

# Leave out the redis.* or the memorystore.* permissions if the fleet has only the other kind
gcloud iam roles create infrapilotMemorystore --project $PROJECT \
  --title "Infrapilot: Memorystore" \
  --permissions redis.instances.get,redis.instances.list,redis.instances.update,redis.operations.get,memorystore.instances.get,memorystore.instances.list,memorystore.instances.update,memorystore.operations.get

gcloud iam roles create infrapilotScheduler --project $PROJECT \
  --title "Infrapilot: Cloud Scheduler" \
  --permissions cloudscheduler.jobs.get,cloudscheduler.jobs.list,cloudscheduler.jobs.update

gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" \
  --role projects/$PROJECT/roles/infrapilotCompute --condition None
```

None of these roles can change IAM.

Cloud Run (and Cloud Functions) revisions run as the service's runtime account, so Pilot must act as it to change them. For services you adopt, that is the account they already run as (often the project's default compute account, `<project number>-compute@developer.gserviceaccount.com`). Services Pilot builds get an account of their own: see [Build access](#build-access-when-pilot-builds-from-nothing).

```bash
gcloud iam service-accounts add-iam-policy-binding <runtime service account email> \
  --member "serviceAccount:$SA" --role roles/iam.serviceAccountUser --project $PROJECT
```

Pilot never changes IAM. When a build needs a binding (public access, a queue's or a schedule's invoker) it asks the person, with the command.

## Build access (when Pilot builds from nothing)

For a fleet spec with `workloads:` and an empty project. The same spec works on AWS and Azure; this is what each kind becomes here.

| Kind | Becomes | Notes |
| --- | --- | --- |
| `http-service` | a Cloud Run service (`run.googleapis.com/Service`), and a domain mapping (`run.googleapis.com/DomainMapping`) per entry of `domains` | `cpu` below 1 becomes 1 vCPU: under a whole vCPU Cloud Run serves one request at a time per instance, and CPU is billed while requests are handled, not for the size. `health_path` is the startup and liveness probe. `public: true` also needs one IAM binding from you (below). |
| `worker` | a Cloud Run service nothing outside the project reaches; with `queue:`, the queue's subscription pushes to it | The container must listen on `$PORT` (8080): on Cloud Run work arrives as HTTP requests, and with a queue each message is one request, which is what scales it. A process that only polls and listens on no port cannot run this way (Cloud Run worker pools are not built yet): Pilot tells you instead of building something that will not start. Without a queue it gets CPU all the time and at least one instance. |
| `database` | a Cloud SQL for PostgreSQL instance (`sqladmin.googleapis.com/Instance`), Enterprise edition | `size`: `small` = `db-custom-1-3840` (1 vCPU, 3.75 GB), `medium` = `db-custom-2-7680` (2 vCPU, 7.5 GB), `large` = `db-custom-4-15360` (4 vCPU, 15 GB): an estimated $53, $102 and $201 a month with 20 GB of SSD at us-central1 list prices, twice that with `high_availability`. `version` defaults to 17. |
| `cache` | a Memorystore for Redis instance (`redis.googleapis.com/Instance`), Basic tier, `memory_gb` GiB (1 by default, about $36 a month) | `high_availability: true` makes it Standard tier (a replica with failover, about twice the price). `engine: valkey` is not built: Memorystore for Valkey needs a network policy in your project first, so Pilot asks you and offers Redis. |
| `schedule` | a Cloud Run job (`run.googleapis.com/Job`, node `<name>-job`) and the Cloud Scheduler job that starts it (`cloudscheduler.googleapis.com/Job`) | `cron` is read in `timezone` (UTC by default). With `target:` the job runs that workload's image with `command`, as the same account, and follows its deploys. A failed task is retried up to three times (Cloud Run's default). |
| `queue` | a Pub/Sub topic and subscription | |
| `bucket` | a Cloud Storage bucket, public access prevented | |

**What "private" means here.** The database has no public IP address. It has one address on the project's `default` VPC network, TLS is required, and only workloads on that network reach it: the Cloud Run services and jobs Pilot builds, which get Direct VPC egress on the `default` network and subnet (private ranges only; other traffic leaves as before, so no NAT is needed). Nothing on the internet can open a connection to it, with or without credentials. The cache likewise has no public address and is reachable from that network only; Redis AUTH and TLS are off, as on any new Memorystore instance, so anything on the network can connect to it. Storage is encrypted by Google at rest. The database has daily backups, point-in-time recovery and deletion protection on. Pilot never deletes a database or a cache, and its role cannot.

**Credentials.** Pilot never sets, reads or stores a database password: an op that names one is refused before it reaches Google. A new instance's built-in `postgres` user has no password and cannot sign in until you choose how applications do (below). `secrets:` are references (`projects/<project>/secrets/<name>`, optionally `/versions/<n>`): the service gets them as environment variables from Secret Manager, and Pilot never reads a secret's value.

### What the blueprints assume, and what you do first

Pilot does not create service accounts, grant roles, verify domains or change networks. Do these once, before the build; if one is missing, Google refuses that resource, Pilot removes anything half-made, tells you what is missing with the command, and builds the rest.

```bash
FLEET=<the spec's fleet name>
# 1. An identity for each workload that runs a container (http-service, worker, and a schedule with
#    its own image; a schedule with target: runs as its target). The account is <fleet>-<workload>:
#    6 to 30 characters, or name another in the workload's spec as service_account.
for W in web worker; do
  gcloud iam service-accounts create $FLEET-$W --project $PROJECT --display-name "$FLEET $W"
  gcloud iam service-accounts add-iam-policy-binding $FLEET-$W@$PROJECT.iam.gserviceaccount.com \
    --project $PROJECT --member "serviceAccount:$SA" --role roles/iam.serviceAccountUser
done

# 2. Each secret a workload's spec references, readable by that workload's account and no other
gcloud secrets add-iam-policy-binding database-url --project $PROJECT \
  --member "serviceAccount:$FLEET-web@$PROJECT.iam.gserviceaccount.com" \
  --role roles/secretmanager.secretAccessor

# 3. For a database: private services access on the default network (once per project)
gcloud services enable servicenetworking.googleapis.com --project $PROJECT
gcloud compute addresses create google-managed-services-default --project $PROJECT \
  --global --purpose VPC_PEERING --prefix-length 20 --network default
gcloud services vpc-peerings connect --project $PROJECT \
  --service servicenetworking.googleapis.com --ranges google-managed-services-default --network default
```

The project needs its `default` network with a subnet in the fleet's region (new projects have one unless an organization policy removed it). Pilot does not build networks: without it the database, the cache and anything that connects to them become a request to you.

For `domains`: verify the domain in [Search Console](https://search.google.com/search-console) and add Pilot's service account (`$SA`) as an owner of the property; Google refuses a mapping from an identity that does not own the domain. Pilot then creates the mapping, and the review page shows the DNS records to add (a `CNAME` to `ghs.googlehosted.com.` for a subdomain, `A` and `AAAA` records for an apex domain). The mapping shows as pending until the records resolve and Google has issued the certificate, usually within an hour. Pilot uses Cloud Run domain mappings rather than a load balancer: one resource, no monthly charge, a certificate Google issues and renews, and the records come from the API. Their limits: Google offers them in some regions only (us-central1, us-east1, europe-west1 and a few more) and still labels them a preview with higher latency than a load balancer. For a busy production site put a global load balancer in front yourself; Pilot adopts and observes it (see the load balancing rows below) and does not build one.

### Roles for building

`roles/run.developer`, `roles/pubsub.editor` and `infrapilotBuckets` from the table above, plus one custom role for what they lack:

```bash
gcloud iam roles create infrapilotBuild --project $PROJECT \
  --title "Infrapilot: build declared workloads" \
  --permissions cloudsql.instances.create,cloudsql.instances.get,cloudsql.instances.list,cloudsql.instances.update,redis.instances.create,redis.instances.get,redis.instances.list,redis.instances.update,redis.operations.get,cloudscheduler.jobs.create,cloudscheduler.jobs.get,cloudscheduler.jobs.list,cloudscheduler.jobs.update,cloudscheduler.jobs.delete,run.domainmappings.create,run.domainmappings.get,run.domainmappings.list,run.domainmappings.delete

gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" \
  --role projects/$PROJECT/roles/infrapilotBuild --condition None
```

It cannot delete a database or a cache, read a secret, create a service account or a database user, or change IAM or a network. A database or cache whose creation failed therefore stays recorded for you to remove; everything else Pilot builds it can also remove when a create fails its health check.

### After the build

Pilot raises a request for each of these when the resource exists, with the exact names:

```bash
# A public http-service: let anyone call it
gcloud run services add-iam-policy-binding $FLEET-web --project $PROJECT --region <region> \
  --member allUsers --role roles/run.invoker
# A worker with a queue: Pub/Sub calls the worker as the worker's own account
gcloud run services add-iam-policy-binding $FLEET-worker --project $PROJECT --region <region> \
  --member "serviceAccount:$FLEET-worker@$PROJECT.iam.gserviceaccount.com" --role roles/run.invoker
# A schedule: Cloud Scheduler starts the job as the account the job runs as (its target's, here web)
gcloud run jobs add-iam-policy-binding $FLEET-nightly-job --project $PROJECT --region <region> \
  --member "serviceAccount:$FLEET-web@$PROJECT.iam.gserviceaccount.com" --role roles/run.invoker
```

How applications sign in to the database is yours to choose. Either IAM database authentication (the flag is on; no password exists):

```bash
gcloud sql users create $FLEET-web@$PROJECT.iam --project $PROJECT --instance $FLEET-db \
  --type cloud_iam_service_account
gcloud projects add-iam-policy-binding $PROJECT --condition None \
  --member "serviceAccount:$FLEET-web@$PROJECT.iam.gserviceaccount.com" --role roles/cloudsql.instanceUser
```

or a password you set yourself and keep in Secret Manager, as the `DATABASE_URL` a `secrets:` entry references:

```bash
gcloud sql users set-password postgres --project $PROJECT --instance $FLEET-db --prompt-for-password
# postgres://postgres:<password>@<the database's private_ip, shown in the review>:5432/postgres?sslmode=require
gcloud secrets versions add database-url --project $PROJECT --data-file=-
```

### Deploys and logs

`infrapilot deploy <workload> <image>` works for every workload that runs a container. A service's new revision must become ready (its startup probe must pass) or the deploy is undone. A deploy to a service also updates the jobs of schedules that name it as `target`, after the service's own check passes. A Cloud Run job has no revision: its check is that Cloud Run accepts the change and finds the image; an image that starts and then crashes shows at the next run, as `last_execution_failed` on the job, so put an objective on it for jobs that matter. The review links each service, job, schedule and database to its logs in Cloud Logging.

### Actual cost (optional, at any access level)

Pilot estimates cost from list prices. To show what Google actually bills beside that estimate, it reads the Cloud Billing export in BigQuery. Without it everything else works and the overview says the bill is not connected.

1. **Turn the export on** (once per billing account; needs Billing Account Costs Manager or Administrator, and BigQuery User on the project that will hold the data). In the console: Billing > Billing export > BigQuery export. Enable **Detailed usage cost** (cost per resource) or **Standard usage cost** (cost per service only) into a dataset. Google creates the table a few hours later: `gcp_billing_export_resource_v1_<billing account id>` for detailed, `gcp_billing_export_v1_<billing account id>` for standard. A multi-region dataset (US or EU) is backfilled from the start of the previous month.
2. **Let Pilot read it.** Two grants, both read-only:

```bash
BILLING_PROJECT=<project that holds the export>   # often not the fleet's project
# Run queries, in the fleet's own project (that is where the query is billed)
gcloud projects add-iam-policy-binding $PROJECT --member "serviceAccount:$SA" \
  --role roles/bigquery.jobUser --condition None
# Read the export's dataset, and nothing else in that project
bq add-iam-policy-binding --member "serviceAccount:$SA" --role roles/bigquery.dataViewer \
  $BILLING_PROJECT:<dataset>
```

3. **Name the table** when you submit the connection (step 3) as `"billing_table": "<project>.<dataset>.<table>"`, or later in the fleet spec under `scope: {billing_table: ...}`.

Pilot runs at most two queries every six hours, each limited to 10 GiB scanned (a few cents at most; normally well inside BigQuery's free tier). It reads this project's rows only. Cost is matched to the fleet by label, so usage from before a resource was labelled, and services that carry no labels (load balancing, network egress, Cloud Scheduler), show as the project's cost that the fleet does not explain.

## 3. Let Infrapilot use the service account

Check `connection.kinds` and `connection.trust` in `GET /api/v1/setup`.

**If `gcp_impersonation` is listed** (preferred, no key):

```bash
gcloud iam service-accounts add-iam-policy-binding $SA --project $PROJECT \
  --member "serviceAccount:<connection.trust.platform_service_account>" \
  --role roles/iam.serviceAccountTokenCreator

curl -s -X POST $INFRAPILOT_URL/api/v1/setup/cloud \
  -H "Authorization: Bearer $INFRAPILOT_TOKEN" -H "Content-Type: application/json" \
  -d "{\"kind\": \"gcp_impersonation\", \"service_account\": \"$SA\", \"project_id\": \"$PROJECT\", \"region\": \"<region, e.g. us-central1>\"}"
# with a billing export, add:  \"billing_table\": \"<project>.<dataset>.<table>\"
```

**Otherwise use `gcp_key`.** Never put the key in the repository; delete the file afterwards.

```bash
gcloud iam service-accounts keys create /tmp/infrapilot-key.json --iam-account $SA
curl -s -X POST $INFRAPILOT_URL/api/v1/setup/cloud \
  -H "Authorization: Bearer $INFRAPILOT_TOKEN" -H "Content-Type: application/json" \
  -d "{\"kind\": \"gcp_key\", \"project_id\": \"$PROJECT\", \"region\": \"<region>\", \"key\": $(cat /tmp/infrapilot-key.json)}"
```

| Check | Needs |
| --- | --- |
| `access token` | the impersonation binding, or a valid key |
| `resourcemanager.projects.get` | `roles/browser` |
| `cloudasset.assets.searchAllResources` | `roles/cloudasset.viewer` and the Cloud Asset API |
| `discovery document (run v2)` | nothing (public) |
| `monitoring.timeSeries.list` | `roles/monitoring.viewer` |
| `logging.logEntries.list` | `roles/logging.viewer` |
| `bigquery billing export` (only when a table is named) | `roles/bigquery.jobUser` on the project, `roles/bigquery.dataViewer` on the export's dataset, and the table's exact name |

IAM usually takes a minute or two. Allowing Infrapilot's platform account to impersonate yours (`gcp_impersonation`) can take up to 15 minutes, because that account lives in another project. If a check fails with a permission error right after granting, wait and resubmit.

## 4. Label what Pilot should adopt

Label keys can't contain colons, so use `infrapilot-fleet` and `infrapilot-name`, here and in the spec.

```bash
gcloud run services update checkout --region us-central1 \
  --update-labels infrapilot-fleet=shop,infrapilot-name=api
gcloud pubsub subscriptions update jobs-sub --update-labels infrapilot-fleet=shop,infrapilot-name=jobs
gcloud sql instances patch orders --update-labels infrapilot-fleet=shop,infrapilot-name=db
gcloud storage buckets update gs://shop-assets --update-labels infrapilot-fleet=shop,infrapilot-name=assets
```

```yaml
adopt:
  - tag: {"infrapilot-fleet": "shop"}
```

- **New labels take a few minutes** to appear in Cloud Asset Inventory. If discover doesn't list something, wait and retry.
- **Instance groups have no labels.** Adopt by identifier; the autoscaler comes with it:

  ```yaml
  adopt:
    - tag: {"infrapilot-fleet": "shop"}
    - resource:
        type: compute.googleapis.com/InstanceGroupManager
        identifier: projects/<project>/zones/<zone>/instanceGroupManagers/<name>
        name: web
  ```
- A subscription's topic and push target are linked automatically. Label the topic only if an objective names it.
- **Cloud Scheduler jobs have no labels.** One that starts a labelled Cloud Run job (`gcloud run jobs update nightly-export --region us-central1 --update-labels infrapilot-fleet=shop,infrapilot-name=export`) is found and linked to it as `export-schedule`. Any other is adopted by identifier (`type: cloudscheduler.googleapis.com/Job`, `identifier: projects/<project>/locations/<region>/jobs/<name>`).
- Memorystore: `gcloud redis instances update cache --region us-central1 --update-labels infrapilot-fleet=shop,infrapilot-name=cache` (for Valkey, `gcloud memorystore instances update`).
- Relabelling Cloud Run creates a new revision with the same config. Relabelling a Cloud Function (`gcloud functions deploy <name> --gen2 --update-labels ...`) redeploys it.
- Pilot builds in the connection's region. For zonal resources set `scope: {zone: <zone>}` in the spec.

## What Pilot understands on Google Cloud

Full list: `curl -s $INFRAPILOT_URL/api/types/gcp`.

| Service | Type | Common objectives |
| --- | --- | --- |
| Cloud Run | `run.googleapis.com/Service` | `request_latencies` (p99, ms), `request_count`, `container/instance_count` |
| Pub/Sub | `pubsub.googleapis.com/Subscription` | `subscription/num_undelivered_messages`, `subscription/oldest_unacked_message_age` |
| Managed instance groups | `compute.googleapis.com/InstanceGroupManager` | `instance/cpu/utilization`, `instance_group/size` |
| Autoscalers | `compute.googleapis.com/Autoscaler` | (tuned instead of the group size) |
| Cloud SQL | `sqladmin.googleapis.com/Instance` | `database/cpu/utilization`, `database/memory/utilization`, `database/disk/utilization` |
| Cloud Functions (2nd gen) | `cloudfunctions.googleapis.com/Function` | `function/execution_times` (p99, ms), `function/execution_count` |
| Pub/Sub topics | `pubsub.googleapis.com/Topic` | `topic/send_request_count` |
| Cloud Storage | `storage.googleapis.com/Bucket` | observed only |
| Load balancing | `compute.googleapis.com/UrlMap` (observed only), `compute.googleapis.com/BackendService` | `https/total_latencies` (p99, ms), `requests_5xx`, `https/backend_latencies` |
| Cloud CDN | `compute.googleapis.com/BackendBucket`, a backend service's `cdnPolicy` | `cache_hits`, `https/request_count` |
| Memorystore for Redis | `redis.googleapis.com/Instance` | `stats/memory/usage_ratio` (%), `stats/evicted_keys`, `stats/cpu_utilization`, `clients/connected` |
| Memorystore for Valkey | `memorystore.googleapis.com/Instance` | `instance/memory/maximum_utilization` (%), `instance/stats/total_evicted_keys_count`, `instance/cpu/maximum_utilization` |
| Cloud Run jobs | `run.googleapis.com/Job` | `last_execution_failed` (1 while the newest execution failed), `failed_task_attempts`, `job/running_executions` |
| Cloud Scheduler | `cloudscheduler.googleapis.com/Job` | `last_attempt_failed`; the schedule is observed |
| Custom domains | `run.googleapis.com/DomainMapping` | `ready` (1 once the certificate is issued); created and removed, never changed |

URL maps and backend services carry no labels: adopt the URL map by identifier and its backend services come with it, linked to the Cloud Run service or instance group behind them. Pilot tunes backend timeouts and Cloud CDN only; routes and backends stay yours.

Good to know:

- Every change is checked against the service's discovery document before it is sent.
- A Cloud Run instance ceiling bound is `api.template.scaling.maxInstanceCount`.
- **Metrics lag one to four minutes**, so Pilot reacts a few minutes after load changes. Pub/Sub backlog has the same lag.
- **Cloud Run and autoscalers own the instance count.** Pilot sets their range (`minInstanceCount`/`maxInstanceCount`, `minNumReplicas`/`maxNumReplicas`) and instance size.
- **Pilot sends only the Cloud Run fields it changes.** A deploy that lands while Pilot is deciding keeps its image, unless Pilot's change is to the containers themselves (CPU, memory, environment); then the containers it sends are the ones it read. If you deploy many times an hour, pause Pilot during deploys.
- **Plain environment variables are recorded.** Keep secrets in Secret Manager.
- **Memorystore.** Pilot grows a Redis instance's memory (`cache.memorySizeGb` as a bound) and a Valkey cluster's shard count (`cache.shardCount`). A Redis resize keeps the data and resets client connections once, for up to a couple of minutes. A Valkey node type change and any change to engine settings such as `maxmemory-policy` always come to you as a request, whatever the intent's level. A Redis instance's tier (Basic or Standard) cannot change in place.
- **Cron.** On a Cloud Run job Pilot tunes task count, parallelism, the task timeout and the container's CPU and memory; a change applies from the next execution. On the Cloud Scheduler job it tunes retries only: when and what to run stays yours.

Workloads Pilot builds: `http-service`, `worker`, `database`, `cache`, `schedule`, `queue` and `bucket`. What each becomes, what it needs from you and what "private" means are under [Build access](#build-access-when-pilot-builds-from-nothing).

## Revoking access

```bash
gcloud iam service-accounts delete $SA --project $PROJECT
```

Access ends within the hour; everything keeps running as left.
