2022-10-04 04:39:10 -07:00
# Nginx-based reverse proxy cluster
This blueprint shows how to deploy an autoscaling reverse proxy cluster using Nginx, based on regional
Managed Instance Groups.
![High-level diagram ](reverse-proxy.png "High-level diagram" )
The autoscaling is driven by Nginx current connections metric, sent by Cloud Ops Agent.
The example is for Nginx, but it could be easily adapted to any other reverse proxy software (eg.
Squid, Varnish, etc).
## Ops Agent image
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.
<!-- BEGIN TFDOC -->
## Variables
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [autoscaling_metric ](variables.tf#L31 ) | | < 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 > | ✓ | |
2022-10-20 09:56:54 -07:00
| [project_name ](variables.tf#L108 ) | 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-10-20 09:56:54 -07:00
| [backends ](variables.tf#L49 ) | 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#L61 ) | Subnet IP CIDR ranges. | < code > map( string) </ code > | | < code title = "{ gce = "10.0.16.0/24" }" > {…} </ code > |
| [network ](variables.tf#L69 ) | Network name. | < code > string</ code > | | < code > " reverse-proxy-vpc" </ code > |
| [network_create ](variables.tf#L75 ) | Create network or use existing one. | < code > bool</ code > | | < code > true</ code > |
| [nginx_image ](variables.tf#L81 ) | Nginx container image to use. | < code > string</ code > | | < code > " gcr.io/ cloud-marketplace/ google/ nginx1:latest" </ code > |
| [ops_agent_image ](variables.tf#L87 ) | Google Cloud Ops Agent container image to use. | < code > string</ code > | | < code > " gcr.io/ sfans-hub-project-d647/ ops-agent:latest" </ code > |
| [prefix ](variables.tf#L93 ) | Prefix used for resources that need unique names. | < code > string</ code > | | < code > "" </ code > |
| [project_create ](variables.tf#L99 ) | 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#L113 ) | Default region for resources. | < code > string</ code > | | < code > " europe-west4" </ code > |
| [subnetwork ](variables.tf#L119 ) | Subnetwork name. | < code > string</ code > | | < code > " gce" </ code > |
| [tls ](variables.tf#L125 ) | 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 -->