具有浮动IP的Terraform Openstack负载均衡器

时间:2018-03-21 15:54:52

标签: terraform terraform-provider-openstack

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

我想创建一个带有浮动IP的负载均衡器,负载均衡器可以有一个或多个成员(我称之为主人)。

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

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配置负载均衡器感到困惑。如果有人可以帮助查看上面的代码段并给出任何建议,我将不胜感激。

由于

1 个答案:

答案 0 :(得分:0)

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

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}"
}