2022-10-04 04:39:10 -07:00
# Nginx-based reverse proxy cluster
2022-10-26 05:31:04 -07:00
This blueprint shows how to deploy an autoscaling reverse proxy cluster using Nginx, based on regional Managed Instance Groups.
2022-10-04 04:39:10 -07:00
![High-level diagram ](reverse-proxy.png "High-level diagram" )
2022-10-26 05:31:04 -07:00
The autoscaling is driven by Nginx current connections metric, sent by Cloud Ops Agent.
2022-10-04 04:39:10 -07:00
2022-10-26 05:31:04 -07:00
The example is for Nginx, but it could be easily adapted to any other reverse proxy software (eg. Squid, Varnish, etc).
2022-10-04 04:39:10 -07:00
## Ops Agent image
2022-10-26 05:31:04 -07:00
There is a simple [`Dockerfile` ](Dockerfile ) available for building Ops Agent to be run inside the ContainerOS instance. Build the container, push it to your Container/Artifact Repository and set the `ops_agent_image` to point to the image you built.
2022-10-04 04:39:10 -07:00
<!-- BEGIN TFDOC -->
## Variables
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
2022-11-24 09:56:01 -08:00
| [autoscaling_metric ](variables.tf#L31 ) | Definition of metric to use for scaling. | < code title = "object({ name = string single_instance_assignment = number target = number type = string # GAUGE, DELTA_PER_SECOND, DELTA_PER_MINUTE filter = string }) default = { name = "workload.googleapis.com/nginx.connections_current" single_instance_assignment = null target = 10 # Target 10 connections per instance, just for demonstration purposes type = "GAUGE" filter = null }" > object({…} </ code > | ✓ | |
| [prefix ](variables.tf#L94 ) | Prefix used for resource names. | < code > string</ code > | ✓ | |
| [project_name ](variables.tf#L112 ) | Name of an existing project or of the new project. | < code > string</ code > | ✓ | |
2022-10-04 04:39:10 -07:00
| [autoscaling ](variables.tf#L17 ) | Autoscaling configuration for the instance group. | < code title = "object({ min_replicas = number max_replicas = number cooldown_period = number })" > object({…}) </ code > | | < code title = "{ min_replicas = 1 max_replicas = 10 cooldown_period = 30 }" > {…} </ code > |
2022-11-24 09:56:01 -08:00
| [backends ](variables.tf#L50 ) | Nginx locations configurations to proxy traffic to. | < code > string</ code > | | < code title = ""<<-EOT location / { proxy_pass http://10.0.16.58:80; proxy_http_version 1.1; proxy_set_header Connection ""; } EOT"" > "<< -EOT… EOT" </ code > |
| [cidrs ](variables.tf#L62 ) | Subnet IP CIDR ranges. | < code > map( string) </ code > | | < code title = "{ gce = "10.0.16.0/24" }" > {…} </ code > |
| [network ](variables.tf#L70 ) | Network name. | < code > string</ code > | | < code > " reverse-proxy-vpc" </ code > |
| [network_create ](variables.tf#L76 ) | Create network or use existing one. | < code > bool</ code > | | < code > true</ code > |
| [nginx_image ](variables.tf#L82 ) | Nginx container image to use. | < code > string</ code > | | < code > " gcr.io/ cloud-marketplace/ google/ nginx1:latest" </ code > |
| [ops_agent_image ](variables.tf#L88 ) | Google Cloud Ops Agent container image to use. | < code > string</ code > | | < code > " gcr.io/ sfans-hub-project-d647/ ops-agent:latest" </ code > |
| [project_create ](variables.tf#L103 ) | Parameters for the creation of the new project. | < code title = "object({ billing_account_id = string parent = string })" > object({…}) </ code > | | < code > null</ code > |
| [region ](variables.tf#L117 ) | Default region for resources. | < code > string</ code > | | < code > " europe-west4" </ code > |
| [subnetwork ](variables.tf#L123 ) | Subnetwork name. | < code > string</ code > | | < code > " gce" </ code > |
| [tls ](variables.tf#L129 ) | Also offer reverse proxying with TLS (self-signed certificate). | < code > bool</ code > | | < code > false</ code > |
2022-10-04 04:39:10 -07:00
## Outputs
| name | description | sensitive |
|---|---|:---:|
| [load_balancer_url ](outputs.tf#L17 ) | Load balancer for the reverse proxy instance group. | |
<!-- END TFDOC -->