Google cloud platform 如何使用terraform平衡google计算实例的负载?
在我的terraform配置文件中,我这样定义我的资源:Google cloud platform 如何使用terraform平衡google计算实例的负载?,google-cloud-platform,terraform,Google Cloud Platform,Terraform,在我的terraform配置文件中,我这样定义我的资源: resource "google_compute_instance" "test" { ... count = 2 } 我现在想要的是创建负载平衡器,它将平衡我的google compute实例的两个实例。不幸的是,我在文档中找不到与此任务相关的任何内容。似乎google_compute_target_pool或google_compute_lb_ip_ranges与我的问题无关。您必须使用此地形上指示的“转发规则”。若
resource "google_compute_instance" "test" {
...
count = 2
}
我现在想要的是创建负载平衡器,它将平衡我的google compute实例的两个实例。不幸的是,我在文档中找不到与此任务相关的任何内容。似乎google_compute_target_pool或google_compute_lb_ip_ranges与我的问题无关。您必须使用此地形上指示的“转发规则”。若要使用负载平衡和协议转发,必须创建一个转发规则,将流量定向到特定的目标实例。在云平台上使用您可以找到的转发规则。在常见情况下,您可以使用以下内容:
resource "google_compute_instance" "test" {
name = "nlb-node${count.index}"
zone = "europe-west3-b"
machine_type = "f1-micro"
count = 2
boot_disk {
auto_delete = true
initialize_params {
image = "ubuntu-os-cloud/ubuntu-1604-lts"
size = 10
type = "pd-ssd"
}
}
network_interface {
subnetwork = "default"
access_config {
nat_ip = ""
}
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
resource "google_compute_http_health_check" "nlb-hc" {
name = "nlb-health-checks"
request_path = "/"
port = 80
check_interval_sec = 10
timeout_sec = 3
}
resource "google_compute_target_pool" "nlb-target-pool" {
name = "nlb-target-pool"
session_affinity = "NONE"
region = "europe-west3"
instances = [
"${google_compute_instance.test.*.self_link}"
]
health_checks = [
"${google_compute_http_health_check.nlb-hc.name}"
]
}
resource "google_compute_forwarding_rule" "network-load-balancer" {
name = "nlb-test"
region = "europe-west3"
target = "${google_compute_target_pool.nlb-target-pool.self_link}"
port_range = "80"
ip_protocol = "TCP"
load_balancing_scheme = "EXTERNAL"
}
您可以通过${google\u compute\u forwarding\u rule.network load balancer.ip\u address}获取负载平衡器外部ip
谢谢你,先生!我会检查的!
// output.tf
output "network_load_balancer_ip" {
value = "${google_compute_forwarding_rule.network-load-balancer.ip_address}"
}