0

我正在尝试使用 terraform 在 Openstack 上创建 Kubernetes 基础架构:

我想创建一个具有浮动 IP 的负载均衡器,该负载均衡器可以有 1 个或多个成员(我称他们为 master)。

到目前为止,这是我提出的,但我被困住了:

resource "openstack_compute_instance_v2" "k8s_master" {
  name       = "${var.cluster_name}-k8s-master-${count.index+1}"
  count      = "${var.number_of_k8s_masters}"
  image_name = "${var.image}"
  flavor_id  = "${var.flavor_k8s_master}"
  key_pair   = "${openstack_compute_keypair_v2.k8s.name}"

  network {
    name = "${var.network_name}"
  }

  security_groups = ["${openstack_compute_secgroup_v2.k8s_master.name}",
    "${openstack_compute_secgroup_v2.bastion.name}",
    "${openstack_compute_secgroup_v2.k8s.name}",
    "default",
  ]

  metadata = {
    ssh_user         = "${var.ssh_user}"
    kubespray_groups = "etcd,kube-master,k8s-cluster,vault"
    depends_on       = "${var.network_id}"
  }

}



resource "openstack_compute_floatingip_associate_v2" "k8s_master" {
      instance_id = "${var.loadbalancer_id}"
      floating_ip = "${var.k8s_master_fips}"
      fixed_ip    = "${openstack_compute_instance_v2.k8s_master.network.0.fixed_ip_v4}"
    }

resource "openstack_lb_loadbalancer_v2" "k8s" {
  name                = "${var.cluster_name}-lb"
  admin_state_up      = "true"
  vip_subnet_id = "${var.network_id}"
}

resource "openstack_lb_listener_v2" "k8s" {
  protocol        = "HTTP"
  protocol_port   = 6443
  loadbalancer_id = "${openstack_lb_loadbalancer_v2.k8s.id}"
}

resource "openstack_lb_pool_v2" "k8s" {
  protocol    = "HTTP"
  lb_method   = "ROUND_ROBIN"
  listener_id = "${openstack_lb_listener_v2.k8s.id}"
}

resource "openstack_lb_member_v2" "k8s" {
  count      = "${var.number_of_k8s_masters}"
  address       = "${var.k8s_master_priv_ips}"
  protocol_port = 6443
  pool_id  = "${var.network_id}"
}

resource "openstack_lb_monitor_v2" "k8s" {
  pool_id     = "${openstack_lb_pool_v2.k8s.id}"
  type        = "HTTP"
  delay       = 20
  timeout     = 10
  max_retries = 5
  url_path = "/"
  expected_codes = 200
}

我对如何使用具有任意数量主节点的 terraform 配置负载均衡器感到困惑。如果有人可以帮助查看上面的片段并提出任何建议,我将不胜感激。

谢谢

4

1 回答 1

1

有同样的问题,但很简单:

resource "openstack_lb_loadbalancer_v2" "lb_1" {
  vip_subnet_id = "${data.openstack_networking_subnet_v2.private.id}"
}


resource "openstack_networking_floatingip_v2" "floatip_1" {
  pool    = "public"
  port_id = "${openstack_lb_loadbalancer_v2.lb_1.vip_port_id}"
}
于 2018-11-25T17:38:45.043 回答