Skip to content

Commit

Permalink
Set cluster name based on env_name, location and cluster_number
Browse files Browse the repository at this point in the history
  • Loading branch information
khanh-ph committed Sep 26, 2023
1 parent dd766f0 commit 64076ff
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,23 @@ The project provides several Terraform variables that allow you to customize the
| <a name="input_pm_host"></a> [pm\_host](#input\_pm\_host) | The name of Proxmox node where the VM is placed. | `string` | n/a | yes |
| <a name="input_pm_parallel"></a> [pm\_parallel](#input\_pm\_parallel) | The number of simultaneous Proxmox processes. E.g: creating resources. | `number` | `2` | no |
| <a name="input_pm_timeout"></a> [pm\_timeout](#input\_pm\_timeout) | Timeout value (seconds) for proxmox API calls. | `number` | `600` | no |
| <a name="input_env_name"></a> [env\_name](#input\_env\_name) | n/a | `string` | `"test"` | no |
| <a name="input_internal_net_name"></a> [internal\_net\_name](#input\_internal\_net\_name) | Name of the internal network bridge. | `string` | `"vmbr1"` | no |
| <a name="input_internal_net_subnet_cidr"></a> [internal\_net\_subnet\_cidr](#input\_internal\_net\_subnet\_cidr) | CIDR of the internal network. For example: 10.0.1.0/24 | `string` | `""` | no |
| <a name="input_ssh_private_key"></a> [ssh\_private\_key](#input\_ssh\_private\_key) | SSH private key in base64. Used by Terraform client to connect to the VM after provisioning. | `string` | n/a | yes |
| <a name="input_ssh_public_keys"></a> [ssh\_public\_keys](#input\_ssh\_public\_keys) | SSH public keys in base64. | `string` | n/a | yes |
| <a name="input_env_name"></a> [env\_name](#input\_env\_name) | The stage of the development lifecycle for the k8s cluster. Example: `prod`, `dev`, `qa`, `stage`, `test` | `string` | `"test"` | no |
| <a name="input_location"></a> [location](#input\_location) | The city or region where the cluster is provisioned | `string` | `null` | no |
| <a name="input_cluster_number"></a> [cluster\_number](#input\_cluster\_number) | The instance count for the k8s cluster, to differentiate it from other clusters. Example: `00`, `01` | `string` | `"00"` | no |
| <a name="input_internal_net_name"></a> [internal\_net\_name](#input\_internal\_net\_name) | Name of the internal network bridge | `string` | `"vmbr1"` | no |
| <a name="input_internal_net_subnet_cidr"></a> [internal\_net\_subnet\_cidr](#input\_internal\_net\_subnet\_cidr) | CIDR of the internal network | `string` | `"10.0.1.0/24"` | no |
| <a name="input_ssh_private_key"></a> [ssh\_private\_key](#input\_ssh\_private\_key) | SSH private key in base64, will be used by Terraform client to connect to the VM after provisioning | `string` | n/a | yes |
| <a name="input_ssh_public_keys"></a> [ssh\_public\_keys](#input\_ssh\_public\_keys) | SSH public keys in base64 | `string` | n/a | yes |
| <a name="input_vm_user"></a> [vm\_user](#input\_vm\_user) | n/a | `string` | `"ubuntu"` | no |
| <a name="input_vm_sockets"></a> [vm\_sockets](#input\_vm\_sockets) | n/a | `number` | `1` | no |
| <a name="input_vm_max_vcpus"></a> [vm\_max\_vcpus](#input\_vm\_max\_vcpus) | The maximum CPU cores available per CPU socket to allocate to the VM. | `number` | `2` | no |
| <a name="input_vm_max_vcpus"></a> [vm\_max\_vcpus](#input\_vm\_max\_vcpus) | The maximum CPU cores available per CPU socket to allocate to the VM | `number` | `2` | no |
| <a name="input_vm_cpu_type"></a> [vm\_cpu\_type](#input\_vm\_cpu\_type) | The type of CPU to emulate in the Guest | `string` | `"host"` | no |
| <a name="input_vm_os_disk_storage"></a> [vm\_os\_disk\_storage](#input\_vm\_os\_disk\_storage) | Default storage pool where OS VM disk is placed. | `string` | n/a | yes |
| <a name="input_add_worker_node_data_disk"></a> [add\_worker\_node\_data\_disk](#input\_add\_worker\_node\_data\_disk) | A boolean value that indicates whether to add a data disk to each worker node of the cluster. | `bool` | `false` | no |
| <a name="input_worker_node_data_disk_storage"></a> [worker\_node\_data\_disk\_storage](#input\_worker\_node\_data\_disk\_storage) | The storage pool where the data disk is placed. | `string` | `""` | no |
| <a name="input_worker_node_data_disk_size"></a> [worker\_node\_data\_disk\_size](#input\_worker\_node\_data\_disk\_size) | The size of worker node data disk in Gigabyte. | `string` | `10` | no |
| <a name="input_vm_ubuntu_tmpl_name"></a> [vm\_ubuntu\_tmpl\_name](#input\_vm\_ubuntu\_tmpl\_name) | Name of Cloud-init template Ubuntu VM. | `string` | `"ubuntu-2204"` | no |
| <a name="input_bastion_ssh_ip"></a> [bastion\_ssh\_ip](#input\_bastion\_ssh\_ip) | IP of the bastion host. It could be either public IP or local network IP of the bastion host. | `string` | `""` | no |
| <a name="input_vm_os_disk_storage"></a> [vm\_os\_disk\_storage](#input\_vm\_os\_disk\_storage) | Default storage pool where OS VM disk is placed | `string` | n/a | yes |
| <a name="input_add_worker_node_data_disk"></a> [add\_worker\_node\_data\_disk](#input\_add\_worker\_node\_data\_disk) | A boolean value that indicates whether to add a data disk to each worker node of the cluster | `bool` | `false` | no |
| <a name="input_worker_node_data_disk_storage"></a> [worker\_node\_data\_disk\_storage](#input\_worker\_node\_data\_disk\_storage) | The storage pool where the data disk is placed | `string` | `""` | no |
| <a name="input_worker_node_data_disk_size"></a> [worker\_node\_data\_disk\_size](#input\_worker\_node\_data\_disk\_size) | The size of worker node data disk in Gigabyte | `string` | `10` | no |
| <a name="input_vm_ubuntu_tmpl_name"></a> [vm\_ubuntu\_tmpl\_name](#input\_vm\_ubuntu\_tmpl\_name) | Name of Cloud-init template Ubuntu VM | `string` | `"ubuntu-2204"` | no |
| <a name="input_bastion_ssh_ip"></a> [bastion\_ssh\_ip](#input\_bastion\_ssh\_ip) | IP of the bastion host, could be either public IP or local network IP of the bastion host | `string` | `""` | no |
| <a name="input_bastion_ssh_user"></a> [bastion\_ssh\_user](#input\_bastion\_ssh\_user) | n/a | `string` | `"ubuntu"` | no |
| <a name="input_bastion_ssh_port"></a> [bastion\_ssh\_port](#input\_bastion\_ssh\_port) | n/a | `number` | `22` | no |
| <a name="input_create_kubespray_host"></a> [create\_kubespray\_host](#input\_create\_kubespray\_host) | n/a | `bool` | `true` | no |
Expand Down
2 changes: 1 addition & 1 deletion kubespray/k8s-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ kube_encrypt_secret_data: false

# DNS configuration.
# Kubernetes cluster name, also will be used as DNS domain
cluster_name: cluster.local
cluster_name: ${cluster_name}
# Subdomains of DNS domain to be resolved via /etc/resolv.conf for hostnet pods
ndots: 2
# dns_timeout: 2
Expand Down
46 changes: 32 additions & 14 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ variable "pm_timeout" {
#

variable "env_name" {
type = string
default = "test"
type = string
description = "The stage of the development lifecycle for the k8s cluster. Example: `prod`, `dev`, `qa`, `stage`, `test`"
default = "test"
}

variable "location" {
type = string
description = "The city or region where the cluster is provisioned"
default = null
}

variable "cluster_number" {
type = string
description = "The instance count for the k8s cluster, to differentiate it from other clusters. Example: `00`, `01`"
default = "00"
}

locals {
cluster_name = var.location ? "k8s-${var.env_name}-${var.location}-${var.cluster_number}" : "k8s-${var.env_name}-${var.cluster_number}"
}

#
Expand All @@ -50,24 +67,24 @@ variable "env_name" {

variable "internal_net_name" {
type = string
description = "Name of the internal network bridge."
description = "Name of the internal network bridge"
default = "vmbr1"
}

variable "internal_net_subnet_cidr" {
type = string
description = "CIDR of the internal network. For example: 10.0.1.0/24"
default = ""
description = "CIDR of the internal network"
default = "10.0.1.0/24"
}

variable "ssh_private_key" {
type = string
description = "SSH private key in base64. Used by Terraform client to connect to the VM after provisioning."
description = "SSH private key in base64, will be used by Terraform client to connect to the VM after provisioning"
}

variable "ssh_public_keys" {
type = string
description = "SSH public keys in base64."
description = "SSH public keys in base64"
}

variable "vm_user" {
Expand All @@ -82,7 +99,7 @@ variable "vm_sockets" {

variable "vm_max_vcpus" {
type = number
description = "The maximum CPU cores available per CPU socket to allocate to the VM."
description = "The maximum CPU cores available per CPU socket to allocate to the VM"
default = 2
}

Expand All @@ -94,30 +111,30 @@ variable "vm_cpu_type" {

variable "vm_os_disk_storage" {
type = string
description = "Default storage pool where OS VM disk is placed."
description = "Default storage pool where OS VM disk is placed"
}

variable "add_worker_node_data_disk" {
type = bool
description = "A boolean value that indicates whether to add a data disk to each worker node of the cluster."
description = "A boolean value that indicates whether to add a data disk to each worker node of the cluster"
default = false
}

variable "worker_node_data_disk_storage" {
type = string
description = "The storage pool where the data disk is placed."
description = "The storage pool where the data disk is placed"
default = ""
}

variable "worker_node_data_disk_size" {
type = string
description = "The size of worker node data disk in Gigabyte."
description = "The size of worker node data disk in Gigabyte"
default = 10
}

variable "vm_ubuntu_tmpl_name" {
type = string
description = "Name of Cloud-init template Ubuntu VM."
description = "Name of Cloud-init template Ubuntu VM"
default = "ubuntu-2204"
}

Expand All @@ -127,7 +144,7 @@ variable "vm_ubuntu_tmpl_name" {

variable "bastion_ssh_ip" {
type = string
description = "IP of the bastion host. It could be either public IP or local network IP of the bastion host."
description = "IP of the bastion host, could be either public IP or local network IP of the bastion host"
default = ""
}

Expand Down Expand Up @@ -165,6 +182,7 @@ variable "kube_network_plugin" {
description = "Choose network plugin (cilium, calico, kube-ovn, weave or flannel. Use cni for generic cni plugin)"
default = "calico"
}

variable "enable_nodelocaldns" {
type = bool
description = "Enable nodelocal dns cache"
Expand Down
1 change: 1 addition & 0 deletions vm-kubespray-host.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ locals {
{
kube_version = var.kube_version
kube_network_plugin = var.kube_network_plugin
cluster_name = local.cluster_name
enable_nodelocaldns = var.enable_nodelocaldns
podsecuritypolicy_enabled = var.podsecuritypolicy_enabled
persistent_volumes_enabled = var.persistent_volumes_enabled
Expand Down

0 comments on commit 64076ff

Please sign in to comment.