> ## Documentation Index
> Fetch the complete documentation index at: https://docs.use.observer/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy to Google Cloud

> A script for Cloud Shell that runs the agent on a small Compute Engine VM in your own network.

The deploy script puts the Observer Agent on a small Compute Engine VM
in a network you choose. From there the agent checks what that network
can reach, such as private databases, internal APIs and Prometheus. It
only makes outbound calls: the firewall denies all inbound traffic
except SSH through Identity-Aware Proxy. Your cloud's pricing applies
to everything the script creates.

[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://shell.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fuseobserver%2Fagent\&cloudshell_tutorial=deploy%2Fgcp%2Ftutorial.md\&show=terminal)

## What the script creates

Every name comes from `--name` (default `observer-agent`):

* A Secret Manager secret `observer-agent-key` that holds the agent
  key. The key is never in the VM's metadata.
* A service account `observer-agent@<project>.iam.gserviceaccount.com`
  that may read only that secret.
* Two firewall rules on the network, for the VM's network tag:
  `observer-agent-allow-iap-ssh` allows SSH from Identity-Aware Proxy
  (`35.235.240.0/20`) and `observer-agent-deny-ingress` denies every
  other inbound connection.
* A VM `observer-agent`: `e2-micro`, Debian 12, a 10 GB balanced disk,
  Shielded VM and OS Login turned on. Its startup script reads the key
  with the service account and runs the
  [install script](https://docs.use.observer/agent/reference/install-script.md), which installs the
  agent binary as the `observer-agent` systemd service. Later boots
  skip the install.

The script also enables the Compute Engine, Secret Manager and IAM
APIs in the project.

## Before you start

* Create the agent in Observer: **Agents**, **Add agent**, then
  **Cloud platforms**. Copy the key. Observer shows it once.
* To check private services, note their VPC network and subnet. The
  subnet needs outbound internet access: keep the VM's external IP (the
  default), or use a subnet with Cloud NAT and pass `--no-address`.

## Deploy from Cloud Shell

**1. Open Cloud Shell**

Choose **Open in Cloud Shell** above and confirm. Cloud Shell clones
the agent repository and opens a short tutorial next to the terminal.

**2. Choose the project**

```bash theme={null}
gcloud config set project <project-id>
```

**3. Run the script**

```bash theme={null}
bash deploy/gcp/deploy.sh --zone us-central1-a
```

The script asks for the key and hides what you type. To check services
in another network, add `--network <name>` and `--subnet <name>`. When
it finishes, it prints the command that shows the agent's logs and the
one that removes everything it created.

## Deploy from any shell

Where `gcloud` is installed and signed in:

```bash theme={null}
git clone --depth 1 https://github.com/useobserver/agent observer-agent && cd observer-agent
AGENT_KEY="obs_live_..." bash deploy/gcp/deploy.sh
```

Without `AGENT_KEY` the script asks for the key on the terminal.

## Flags

| Flag | Default | What it does |
| - | - | - |
| `--project <id>` | gcloud's configured project | Project to deploy into |
| `--zone <zone>` | gcloud's configured zone, else `us-central1-a` | Zone of the VM |
| `--network <name>` | `default` | VPC network of the services to check |
| `--subnet <name>` | the region's subnet | Subnet in that network |
| `--no-address` | | No external IP. The subnet needs Cloud NAT for outbound traffic |
| `--machine-type <type>` | `e2-micro` | Machine type of the VM |
| `--name <name>` | `observer-agent` | Name of the VM and of everything else the script creates. 6 to 28 characters: lowercase letters, digits and hyphens, starting with a letter |
| `--cloud-url <url>` | `https://use.observer` | Observer address. Leave as is |
| `--delete` | | Delete the VM, the firewall rules, the secret and the service account |
| `-h`, `--help` | | Print the help |

Running the script again is safe: it adds the key as a new secret
version and leaves an existing VM as it is.

## Check that it connected

A minute or two after the script finishes, the Add agent screen shows
**Connected** and the Agents page marks the agent as **running**.

If it does not connect, read the agent's logs through Identity-Aware
Proxy (the script prints this command with your values):

```bash theme={null}
gcloud compute ssh observer-agent --project <project-id> --zone us-central1-a \
  --tunnel-through-iap --command 'sudo journalctl -u observer-agent -f'
```

Your account needs permission to use IAP TCP forwarding and OS Login
with admin rights; project owners have both. The agent logs every
failed call to Observer with the reason. The most common cause is a
wrong or replaced agent key.

If the `observer-agent` service does not exist, the install failed.
Read the startup script's output with
`sudo journalctl -u google-startup-scripts.service` on the VM. The
usual cause is a subnet without outbound internet access.

## Add settings and secrets

The agent reads its environment from `/etc/observer-agent/agent.env`.
To add a variable, such as `PROMETHEUS_SERVER_URL` or a secret that a
probe references by name (`connection_string_ref` and the like), edit
the file over IAP SSH and restart the service:

```bash theme={null}
gcloud compute ssh observer-agent --zone us-central1-a --tunnel-through-iap
sudo vi /etc/observer-agent/agent.env
sudo systemctl restart observer-agent
```

After a [key rotation](https://docs.use.observer/agent/guides/rotate-agent-key.md), put the new
key in `AGENT_KEY` in the same file. The VM reads Secret Manager only
for its first install. See
[Environment variables](https://docs.use.observer/agent/reference/environment-variables.md) for
every setting.

## Upgrades

The VM installs the agent binary with the install script. To upgrade,
run the script again on the VM. It replaces the binary, restarts the
service, and keeps the key and your settings:

```bash theme={null}
gcloud compute ssh observer-agent --zone us-central1-a --tunnel-through-iap \
  --command 'curl -fsSL https://use.observer/install.sh | sh'
```

To install a given release, use `sh -s -- --version <X.Y.Z>` in place
of `sh`.

## Remove

From the same repository checkout (Cloud Shell keeps it in your home
directory), run the script with `--delete` and the same project, zone
and name:

```bash theme={null}
bash deploy/gcp/deploy.sh --delete --project <project-id> --zone us-central1-a
```

It deletes the VM, the two firewall rules, the secret and the service
account. The APIs it enabled stay enabled. Delete the agent in
Observer (**Agents**) too if you no longer need it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.