diff --git a/kube.tf.example b/kube.tf.example index e90ecec8..986f912f 100644 --- a/kube.tf.example +++ b/kube.tf.example @@ -750,6 +750,11 @@ module "kube-hetzner" { # In which case, you need to define that hostname in the k3s TLS-SANs config to allow connection through it. It can be hostnames or IP addresses. # additional_tls_sans = ["cp.cluster.my.org"] + # If you create a hostname with multiple A records pointing to all of your + # control-plane nodes ips, you may want to use that hostname in the generated + # kubeconfig. + # kubeconfig_server_address = "cp.cluster.my.org" + # lb_hostname Configuration: # # Purpose: diff --git a/kubeconfig.tf b/kubeconfig.tf index 28188b60..228f98a6 100644 --- a/kubeconfig.tf +++ b/kubeconfig.tf @@ -12,9 +12,9 @@ data "remote_file" "kubeconfig" { } locals { - kubeconfig_server_address = var.use_control_plane_lb ? hcloud_load_balancer.control_plane.*.ipv4[0] : ( + kubeconfig_server_address = var.kubeconfig_server_address != "" ? var.kubeconfig_server_address : (var.use_control_plane_lb ? hcloud_load_balancer.control_plane.*.ipv4[0] : ( can(module.control_planes[keys(module.control_planes)[0]].ipv4_address) ? module.control_planes[keys(module.control_planes)[0]].ipv4_address : "unknown" - ) + )) kubeconfig_external = replace(replace(data.remote_file.kubeconfig.content, "127.0.0.1", local.kubeconfig_server_address), "default", var.cluster_name) kubeconfig_parsed = yamldecode(local.kubeconfig_external) kubeconfig_data = { diff --git a/variables.tf b/variables.tf index 44be92bb..5ce9eb22 100644 --- a/variables.tf +++ b/variables.tf @@ -805,6 +805,12 @@ variable "lb_hostname" { } } +variable "kubeconfig_server_address" { + type = string + default = "" + description = "The hostname used for kubeconfig." +} + variable "rancher_registration_manifest_url" { type = string description = "The url of a rancher registration manifest to apply. (see https://rancher.com/docs/rancher/v2.6/en/cluster-provisioning/registered-clusters/)."