Merge pull request #50 from phaer/remove-templates

Replace k3s config templates with yamlencode
This commit is contained in:
Karim Naufal 2022-02-08 16:09:03 +01:00 committed by GitHub
commit 940b5d628e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 57 deletions

View File

@ -59,11 +59,12 @@ resource "hcloud_server" "agents" {
EOT
}
# Generating and uploading the angent.conf file
# Generating and uploading the agent.conf file
provisioner "file" {
content = templatefile("${path.module}/templates/agent.conf.tpl", {
server_url = "https://${local.first_control_plane_network_ip}:6443"
node_token = random_password.k3s_token.result
server = "https://${local.first_control_plane_network_ip}:6443"
token = random_password.k3s_token.result
})
destination = "/etc/rancher/k3s/agent.conf"
@ -75,11 +76,13 @@ resource "hcloud_server" "agents" {
}
}
# Generating k3s server config file
# Generating k3s agent config file
provisioner "file" {
content = templatefile("${path.module}/templates/agent_config.yaml.tpl", {
node_ip = cidrhost(hcloud_network.k3s.ip_range, 2 + var.servers_num + count.index)
node_name = self.name
content = yamlencode({
node-name = self.name
kubelet-arg = "cloud-provider=external"
flannel-iface = "eth1"
node-ip = cidrhost(hcloud_network.k3s.ip_range, 2 + var.servers_num + count.index)
})
destination = "/etc/rancher/k3s/config.yaml"

View File

@ -59,11 +59,17 @@ resource "hcloud_server" "first_control_plane" {
# Generating k3s master config file
provisioner "file" {
content = templatefile("${path.module}/templates/master_config.yaml.tpl", {
node_ip = local.first_control_plane_network_ip
token = random_password.k3s_token.result
node_name = self.name
allow_scheduling_on_control_plane = var.allow_scheduling_on_control_plane
content = yamlencode({
node-name = self.name
cluster-init = true
disable-cloud-controller = true
disable = ["servicelb", "local-storage"]
flannel-iface = "eth1"
kubelet-arg = "cloud-provider=external"
node-ip = local.first_control_plane_network_ip
advertise-address = local.first_control_plane_network_ip
token = random_password.k3s_token.result
node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"]
})
destination = "/etc/rancher/k3s/config.yaml"

View File

@ -60,12 +60,19 @@ resource "hcloud_server" "control_planes" {
# Generating k3s server config file
provisioner "file" {
content = templatefile("${path.module}/templates/server_config.yaml.tpl", {
first_control_plane_url = "https://${local.first_control_plane_network_ip}:6443"
node_ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index)
token = random_password.k3s_token.result
node_name = self.name
allow_scheduling_on_control_plane = var.allow_scheduling_on_control_plane
content = yamlencode({
node-name = self.name
server = "https://${local.first_control_plane_network_ip}:6443"
cluster-init = true
disable-cloud-controller = true
disable = "servicelb, local-storage"
flannel-iface = "eth1"
kubelet-arg = "cloud-provider=external"
node-ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index)
advertise-address = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index)
tls-san = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index)
token = random_password.k3s_token.result
node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"]
})
destination = "/etc/rancher/k3s/config.yaml"

View File

@ -1,3 +1,3 @@
SERVER_URL="${server_url}"
NODE_TOKEN="${node_token}"
AGENT_OPTS=
SERVER_URL="${server}"
NODE_TOKEN="${token}"
AGENT_OPTS=""

View File

@ -1,4 +0,0 @@
node-ip: ${node_ip}
kubelet-arg: "cloud-provider=external"
flannel-iface: eth1
node-name: ${node_name}

View File

@ -1,16 +0,0 @@
cluster-init: true
disable-cloud-controller: true
disable:
- servicelb
- local-storage
flannel-iface: eth1
node-ip: ${node_ip}
advertise-address: ${node_ip}
tls-san: ${node_ip}
kubelet-arg: "cloud-provider=external"
token: ${token}
node-name: ${node_name}
%{ if !allow_scheduling_on_control_plane }
node-taint:
- node-role.kubernetes.io/master:NoSchedule
%{ endif }

View File

@ -1,16 +0,0 @@
server: ${first_control_plane_url}
disable-cloud-controller: true
disable:
- servicelb
- local-storage
flannel-iface: eth1
node-ip: ${node_ip}
advertise-address: ${node_ip}
tls-san: ${node_ip}
kubelet-arg: "cloud-provider=external"
token: ${token}
node-name: ${node_name}
%{ if !allow_scheduling_on_control_plane }
node-taint:
- node-role.kubernetes.io/master:NoSchedule
%{ endif }