-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Envoy-based load balancing schemes (#269)
* Implement Envoy-based load balancing schemes Add configuration for load_balancing_scheme setting in forwarding rules and backend service configuration. Closes: #257 Signed-off-by: Jonathan Yu <[email protected]> * remove explicit pinned version in example * fix obj Signed-off-by: Jonathan Yu <[email protected]> Co-authored-by: Bharath KKB <[email protected]>
- Loading branch information
1 parent
7f30d88
commit 125bf68
Showing
22 changed files
with
396 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# External HTTPS Load Balancer with dynamic backends | ||
|
||
[](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/terraform-google-lb-http&working_dir=examples/dynamic-backend&page=shell&tutorial=README.md) | ||
|
||
This creates an external Envoy-based HTTPS Load Balancer using dynamic | ||
backends suitable for integrating with a Google Kubernetes Engine cluster | ||
running [gke-autoneg-controller](https://github.com/GoogleCloudPlatform/gke-autoneg-controller). | ||
The load balancer will not route traffic to any backend service or bucket; | ||
instead, it expects that an external user or service will register backends | ||
(such as Network Endpoint Groups) accordingly to serve traffic. The example | ||
will attempt to provision a Google-managed TLS certificate for the domain | ||
"example.com" by default and use `/api/health` as a health check endpoint. | ||
|
||
## Change to the example directory | ||
|
||
``` | ||
[[ `basename $PWD` != https-gke ]] && cd examples/dynamic-backend | ||
``` | ||
|
||
## Install Terraform | ||
|
||
1. Install Terraform if it is not already installed (visit [terraform.io](https://terraform.io) for other distributions): | ||
|
||
## Set up the environment | ||
|
||
1. Set the project, replace `YOUR_PROJECT` with your project ID: | ||
|
||
``` | ||
PROJECT=YOUR_PROJECT | ||
``` | ||
|
||
``` | ||
gcloud config set project ${PROJECT} | ||
``` | ||
|
||
2. Configure the environment for Terraform: | ||
|
||
``` | ||
[[ $CLOUD_SHELL ]] || gcloud auth application-default login | ||
export GOOGLE_PROJECT=$(gcloud config get-value project) | ||
``` | ||
|
||
3. Create the dynamic backend load balancer. | ||
|
||
``` | ||
( | ||
cd dynamic-backend/ | ||
terraform init | ||
terraform plan -out terraform.tfplan | ||
terraform apply terraform.tfplan | ||
) | ||
``` | ||
|
||
4. Deploy the `gke-autoneg-controller` into a GKE cluster and configure it according to the instructions. This will create a Network Endpoint Group for a service and bind it to this load balancer. | ||
|
||
|
||
## Cleanup | ||
|
||
1. Delete the load balancing resources created by terraform: | ||
|
||
``` | ||
terraform destroy | ||
``` | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| domains | Domain names to use in managed certificate | `list(string)` | <pre>[<br> "example.com"<br>]</pre> | no | | ||
| project | n/a | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No output. | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
provider "google" { | ||
project = var.project | ||
} | ||
|
||
provider "google-beta" { | ||
project = var.project | ||
} | ||
|
||
resource "google_compute_managed_ssl_certificate" "frontend" { | ||
name = "managedcert" | ||
|
||
managed { | ||
domains = var.domains | ||
} | ||
} | ||
|
||
module "load_balancer" { | ||
source = "../../modules/dynamic_backends" | ||
|
||
name = "dynamic-backend-lb" | ||
project = var.project | ||
enable_ipv6 = true | ||
create_ipv6_address = true | ||
http_forward = false | ||
|
||
load_balancing_scheme = "EXTERNAL_MANAGED" | ||
|
||
ssl = true | ||
use_ssl_certificates = true | ||
ssl_certificates = [ | ||
google_compute_managed_ssl_certificate.frontend.self_link | ||
] | ||
|
||
backends = { | ||
default = { | ||
description = null | ||
protocol = "HTTPS" | ||
port = 443 | ||
port_name = "https" | ||
timeout_sec = 30 | ||
connection_draining_timeout_sec = 0 | ||
enable_cdn = false | ||
security_policy = null | ||
session_affinity = null | ||
affinity_cookie_ttl_sec = null | ||
custom_request_headers = null | ||
custom_response_headers = null | ||
compression_mode = null | ||
|
||
health_check = { | ||
check_interval_sec = 15 | ||
timeout_sec = 15 | ||
healthy_threshold = 4 | ||
unhealthy_threshold = 4 | ||
request_path = "/api/health" | ||
port = 443 | ||
host = null | ||
logging = true | ||
} | ||
|
||
log_config = { | ||
enable = true | ||
sample_rate = 1.0 | ||
} | ||
|
||
# leave blank, NEGs are dynamically added to the lb via autoneg | ||
groups = [] | ||
|
||
iap_config = { | ||
enable = false | ||
oauth2_client_id = "" | ||
oauth2_client_secret = "" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "project" { | ||
type = string | ||
} | ||
|
||
variable "domains" { | ||
description = "Domain names to use in managed certificate" | ||
type = list(string) | ||
default = ["example.com"] | ||
} |
Oops, something went wrong.