Last active
February 26, 2022 19:00
-
-
Save egeneralov/af62207c700ba220a2de6fa52823083d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "zone" { | |
type = string | |
default = "ru-central1-a" | |
} | |
variable "k8s_nodes" { | |
type = list(string) | |
default = [ | |
"k8s-dev-0", | |
"k8s-dev-1", | |
"k8s-dev-2", | |
"k8s-dev-3", | |
"k8s-dev-4", | |
] | |
} | |
resource "yandex_compute_instance" "bastion" { | |
name = "bastion" | |
hostname = "bastion" | |
# platform_id = "standard-v1" # Intel Broadwell # allowed core fractions: 5, 20, 100 | |
# platform_id = "standard-v2" # Intel Cascade Lake | |
platform_id = "standard-v3" # Intel Ice Lake | |
zone = var.zone | |
allow_stopping_for_update = true | |
resources { | |
cores = 2 | |
memory = 2 | |
core_fraction = 20 | |
} | |
boot_disk { | |
auto_delete = true | |
device_name = "bastion" | |
initialize_params { | |
image_id = "fd8nfjfrki3b9ctrh50r" # debian-11-v20220131 | |
type = "network-ssd" | |
size = 10 | |
} | |
} | |
network_interface { | |
nat = true | |
subnet_id = yandex_vpc_subnet.k8s_dev.id | |
} | |
metadata = { | |
serial-port-enable = 1 | |
ssh-keys = "debian:${file("~/.ssh/id_rsa.pub")}" | |
} | |
scheduling_policy { | |
preemptible = true | |
} | |
} | |
resource "yandex_compute_instance" "k8s_nodes" { | |
count = length(var.k8s_nodes) | |
name = var.k8s_nodes[count.index] | |
hostname = var.k8s_nodes[count.index] | |
# platform_id = "standard-v1" # Intel Broadwell # allowed core fractions: 5, 20, 100 | |
# platform_id = "standard-v2" # Intel Cascade Lake | |
platform_id = "standard-v3" # Intel Ice Lake | |
zone = var.zone | |
allow_stopping_for_update = true | |
resources { | |
cores = 4 | |
memory = 8 | |
core_fraction = 20 | |
} | |
boot_disk { | |
auto_delete = true | |
device_name = var.k8s_nodes[count.index] | |
initialize_params { | |
image_id = "fd8nfjfrki3b9ctrh50r" # debian-11-v20220131 | |
type = "network-ssd-nonreplicated" # must be /93Gb | |
size = 93 | |
} | |
} | |
network_interface { | |
nat = false | |
subnet_id = yandex_vpc_subnet.k8s_dev.id | |
} | |
metadata = { | |
serial-port-enable = 1 | |
ssh-keys = "debian:${file("~/.ssh/id_rsa.pub")}" | |
} | |
scheduling_policy { | |
preemptible = true | |
} | |
} | |
resource "local_file" "hosts" { | |
content = <<-EOT | |
[all] | |
%{for node in yandex_compute_instance.k8s_nodes~} | |
${node.name} ansible_host=${node.network_interface.0.ip_address} etcd_member_name=${node.name} | |
%{endfor~} | |
${yandex_compute_instance.bastion.name} ansible_host=${yandex_compute_instance.bastion.network_interface.0.nat_ip_address} | |
[all:vars] | |
ansible_python_interpreter=/usr/bin/python3 | |
[bastion] | |
${yandex_compute_instance.bastion.name} | |
[kube-master] | |
%{for node in yandex_compute_instance.k8s_nodes~} | |
${node.name} | |
%{endfor~} | |
[kube-node] | |
%{for node in yandex_compute_instance.k8s_nodes~} | |
${node.name} | |
%{endfor~} | |
[etcd] | |
%{for node in yandex_compute_instance.k8s_nodes~} | |
${node.name} | |
%{endfor~} | |
[k8s-cluster:children] | |
kube-master | |
kube-node | |
EOT | |
filename = format("%s/../.ansible/inventory/k8s_dev/hosts.ini", abspath(path.root)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment