You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8 KiB

  1. resource "openstack_networking_floatingip_v2" "k8s_master" {
  2. count = "${var.number_of_k8s_masters}"
  3. pool = "${var.floatingip_pool}"
  4. }
  5. resource "openstack_networking_floatingip_v2" "k8s_node" {
  6. count = "${var.number_of_k8s_nodes}"
  7. pool = "${var.floatingip_pool}"
  8. }
  9. resource "openstack_compute_keypair_v2" "k8s" {
  10. name = "kubernetes-${var.cluster_name}"
  11. public_key = "${file(var.public_key_path)}"
  12. }
  13. resource "openstack_compute_secgroup_v2" "k8s_master" {
  14. name = "${var.cluster_name}-k8s-master"
  15. description = "${var.cluster_name} - Kubernetes Master"
  16. }
  17. resource "openstack_compute_secgroup_v2" "k8s" {
  18. name = "${var.cluster_name}-k8s"
  19. description = "${var.cluster_name} - Kubernetes"
  20. rule {
  21. ip_protocol = "tcp"
  22. from_port = "22"
  23. to_port = "22"
  24. cidr = "0.0.0.0/0"
  25. }
  26. rule {
  27. ip_protocol = "icmp"
  28. from_port = "-1"
  29. to_port = "-1"
  30. cidr = "0.0.0.0/0"
  31. }
  32. rule {
  33. ip_protocol = "tcp"
  34. from_port = "1"
  35. to_port = "65535"
  36. self = true
  37. }
  38. rule {
  39. ip_protocol = "udp"
  40. from_port = "1"
  41. to_port = "65535"
  42. self = true
  43. }
  44. rule {
  45. ip_protocol = "icmp"
  46. from_port = "-1"
  47. to_port = "-1"
  48. self = true
  49. }
  50. }
  51. resource "openstack_compute_instance_v2" "k8s_master" {
  52. name = "${var.cluster_name}-k8s-master-${count.index+1}"
  53. count = "${var.number_of_k8s_masters}"
  54. image_name = "${var.image}"
  55. flavor_id = "${var.flavor_k8s_master}"
  56. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  57. network {
  58. name = "${var.network_name}"
  59. }
  60. security_groups = [ "${openstack_compute_secgroup_v2.k8s_master.name}",
  61. "${openstack_compute_secgroup_v2.k8s.name}" ]
  62. floating_ip = "${element(openstack_networking_floatingip_v2.k8s_master.*.address, count.index)}"
  63. metadata = {
  64. ssh_user = "${var.ssh_user}"
  65. kubespray_groups = "etcd,kube-master,kube-node,k8s-cluster"
  66. }
  67. }
  68. resource "openstack_compute_instance_v2" "k8s_node" {
  69. name = "${var.cluster_name}-k8s-node-${count.index+1}"
  70. count = "${var.number_of_k8s_nodes}"
  71. image_name = "${var.image}"
  72. flavor_id = "${var.flavor_k8s_node}"
  73. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  74. network {
  75. name = "${var.network_name}"
  76. }
  77. security_groups = ["${openstack_compute_secgroup_v2.k8s.name}" ]
  78. floating_ip = "${element(openstack_networking_floatingip_v2.k8s_node.*.address, count.index)}"
  79. metadata = {
  80. ssh_user = "${var.ssh_user}"
  81. kubespray_groups = "kube-node,k8s-cluster"
  82. }
  83. }
  84. #output "msg" {
  85. # value = "Your hosts are ready to go!\nYour ssh hosts are: ${join(", ", openstack_networking_floatingip_v2.k8s_master.*.address )}"
  86. #}