我正在学习使用Terraform在DO上创建k8s集群的方法,我一直在尝试获取我已创建的单个K8s节点的ID
,并从负载均衡器中引用它。
这样做的主要原因是,我可以在.tf
文件中声明FQDN。
首先,这是集群声明:
variable "digitalocean_token" {}
provider "digitalocean" {
token = "${var.digitalocean_token}"
}
resource "digitalocean_kubernetes_cluster" "foo" {
name = "foo"
region = "nyc1"
version = "1.12.1-do.2"
node_pool {
name = "woker-pool"
size = "s-1vcpu-2gb"
node_count = 1
}
}
这是负载均衡器声明:
resource "digitalocean_loadbalancer" "foo" {
name = "k8s-lb.nyc1"
region = "nyc1"
forwarding_rule {
entry_port = 80
entry_protocol = "http"
target_port = 80
target_protocol = "http"
}
droplet_ids = ["${digitalocean_kubernetes_cluster.foo.node_pool.0.id}"]
}
output "loadbalancer_ip" {
value = "${digitalocean_loadbalancer.foo.ip}"
}
resource "digitalocean_record" "terraform" {
domain = "example.com" # "${digitalocean_domain.example.name}"
type = "A"
name = "terraform"
value = "${digitalocean_loadbalancer.foo.ip}"
}
# Output the FQDN for the record
output "fqdn" {
value = "${digitalocean_record.terraform.fqdn}"
}
我猜想也许
digitalocean_loadbalancer
资源仅设置为可与单个小滴一起使用?这是输出错误:当我运行
terraform apply
时:* output.loadbalancer_ip: Resource 'digitalocean_loadbalancer.foo' not found for variable 'digitalocean_loadbalancer.foo.ip'
* digitalocean_record.terraform: Resource 'digitalocean_loadbalancer.foo' not found for variable 'digitalocean_loadbalancer.foo.ip'
* digitalocean_loadbalancer.foo: droplet_ids.0: cannot parse '' as int: strconv.ParseInt: parsing "d4292e64-9c0a-4afb-83fc-83f239bcb4af": invalid syntax
铂2
我添加了
digitalocean_droplet
资源,以查看将什么样的ID传递给负载均衡器。resource "digitalocean_droplet" "web" {
name = "web-1"
size = "s-1vcpu-1gb"
image = "ubuntu-18-04-x64"
region = "nyc1"
}
digitalocean_kubernetes_cluster.foo.node_pool.0.id = '6ae6a787-d837-4e78-a915-cb52155f66fe'
digitalocean_droplet.web.id = 132533158
最佳答案
因此,digitalocean_loadbalancer
资源具有一个可选的droplet_tag
参数,可用于提供给创建的节点/液滴的通用标签。
但是,当在kubernetes中声明一个负载均衡器时,仍然会创建一个新的负载均衡器。因此,至少目前看来,在digitalocean上无法使用Terraform定义域/ CNAME记录