From a00a4b9b5fe98c987f31ef8c8f95ceb6599f195a Mon Sep 17 00:00:00 2001 From: Ilia Kargapolov Date: Fri, 24 May 2024 18:45:15 +0200 Subject: [PATCH] Added support to provide SSH keys for k8s node groups --- README.md | 9 +++-- examples/example-1-zonal-with-2-ng/main.tf | 8 ++--- .../terraform.tfvars | 1 - .../example-1-zonal-with-2-ng/versions.tf | 4 +-- node_group.tf | 8 ++++- variables.tf | 34 ++++++++++++++----- versions.tf | 4 +-- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 59c1f17..4006767 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Features -- Create zonal Kubernetes cluster +- Create zonal Kubernetes cluster - Create user defined Kubernetes node groups - Easy to use in other resources via outputs @@ -63,11 +63,11 @@ module "kube" { subnet_id = "e9b3k97pr2nh1i80as04" }, { - zone = "eu-north1-b" + zone = "eu-north1-b" subnet_id = "e2laaglsc7u99ur8c4j1" }, { - zone = "eu-north1-c" + zone = "eu-north1-c" subnet_id = "b0ckjm3olbpmk2t6c28o" } ] @@ -206,6 +206,9 @@ No modules. | [service\_ipv4\_range](#input\_service\_ipv4\_range) | CIDR block. IP range from which Kubernetes service cluster IP addresses
will be allocated from. It should not overlap with
any subnet in the network the Kubernetes cluster located in | `string` | `"172.18.0.0/16"` | no | | [service\_ipv6\_range](#input\_service\_ipv6\_range) | IPv6 CIDR block. IP range for allocating pod addresses. | `string` | `null` | no | | [timeouts](#input\_timeouts) | Timeouts. | `map(string)` |
{
"create": "60m",
"delete": "60m",
"update": "60m"
}
| no | +| [ssh_username](#input\_ssh_username) | SSH Username. | `map(string)` |
{
"create": "60m",
"delete": "60m",
"update": "60m"
}
| no | +| [ssh_public_key](#input\_ssh_public_key) | SSH Public key content. | `map(string)` |
{
"create": "60m",
"delete": "60m",
"update": "60m"
}
| no | +| [ssh_public_key_path](#input\_ssh_public_key_path) | Path to SSH Public key file. | `map(string)` |
{
"create": "60m",
"delete": "60m",
"update": "60m"
}
| no | ## Outputs diff --git a/examples/example-1-zonal-with-2-ng/main.tf b/examples/example-1-zonal-with-2-ng/main.tf index c2a4b36..3364c60 100644 --- a/examples/example-1-zonal-with-2-ng/main.tf +++ b/examples/example-1-zonal-with-2-ng/main.tf @@ -3,7 +3,7 @@ module "kube" { source = "../../" - network_id = "btcci5d99ka84l988qvs" + network_id = "btcci5d99ka84l988qvs" master_locations = [ { @@ -28,7 +28,7 @@ module "kube" { } ] node_groups = { - "k8s-ng-h100-8gpu1" = { + "k8s-ng-h100-8gpu1" = { description = "Kubernetes nodes h100-8-gpu nodes with autoscaling" fixed_scale = { size = 2 @@ -40,12 +40,10 @@ module "kube" { node_gpus = 8 disk_type = "network-ssd-nonreplicated" disk_size = 372 - nat = true + nat = true node_labels = { "group" = "h100-8gpu" } } } } - - diff --git a/examples/example-1-zonal-with-2-ng/terraform.tfvars b/examples/example-1-zonal-with-2-ng/terraform.tfvars index 8b13789..e69de29 100644 --- a/examples/example-1-zonal-with-2-ng/terraform.tfvars +++ b/examples/example-1-zonal-with-2-ng/terraform.tfvars @@ -1 +0,0 @@ - diff --git a/examples/example-1-zonal-with-2-ng/versions.tf b/examples/example-1-zonal-with-2-ng/versions.tf index bd017d2..7605823 100644 --- a/examples/example-1-zonal-with-2-ng/versions.tf +++ b/examples/example-1-zonal-with-2-ng/versions.tf @@ -3,7 +3,7 @@ terraform { required_providers { nebius = { - source = "terraform-registry.storage.ai.nebius.cloud/nebius/nebius" + source = "terraform-registry.storage.ai.nebius.cloud/nebius/nebius" version = ">= 0.6.0" } local = { @@ -18,7 +18,7 @@ terraform { } provider "nebius" { - endpoint = "api.nemax.nebius.cloud:443" + endpoint = "api.nemax.nebius.cloud:443" folder_id = "bjer0eu4okh6vntopouq" } diff --git a/node_group.tf b/node_group.tf index 9a21e78..98f81fd 100644 --- a/node_group.tf +++ b/node_group.tf @@ -11,6 +11,9 @@ locals { ]) ]...) : [] master_locations_subnets_ids = concat(flatten([for location in var.master_locations : location.subnet_id])) + + ssh_public_key = var.ssh_public_key != null ? var.ssh_public_key : ( + fileexists(var.ssh_public_key_path) ? file(var.ssh_public_key_path) : null) } resource "nebius_kubernetes_node_group" "kube_node_groups" { @@ -32,11 +35,14 @@ resource "nebius_kubernetes_node_group" "kube_node_groups" { gpus = lookup(each.value, "node_gpus", var.node_groups_defaults.node_gpus) } + metadata = { + ssh-keys = local.ssh_public_key != null ? "${var.ssh_username}:${local.ssh_public_key}" : null + } dynamic "gpu_settings" { for_each = compact([lookup(each.value, "gpu_cluster_id", null)]) content { - gpu_cluster_id = each.value.gpu_cluster_id + gpu_cluster_id = each.value.gpu_cluster_id gpu_environment = each.value.gpu_environment } } diff --git a/variables.tf b/variables.tf index 354211a..d175bf9 100644 --- a/variables.tf +++ b/variables.tf @@ -73,7 +73,7 @@ variable "node_ipv4_cidr_mask_size" { variable "service_ipv4_range" { description = <