-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove cluster token and instead generate a random one. * add worker node support * add worker node support * upgraded the terraform providers * update readme to show the changes. * worker nodes must depend on control plane node join
- Loading branch information
Showing
10 changed files
with
277 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
resource "digitalocean_volume" "microk8s-worker-node" { | ||
region = var.region | ||
count = var.node_count | ||
name = "microk8s-worker-fs-${count.index}" | ||
size = var.worker_node_disksize | ||
description = "A volume to attach to the worker" | ||
} | ||
|
||
resource "digitalocean_droplet" "microk8s-worker-node" { | ||
image = var.os_image | ||
name = "microk8s-worker-${var.cluster_name}-${count.index}" | ||
region = var.region | ||
size = var.worker_node_size | ||
count = var.worker_node_count | ||
private_networking = true | ||
|
||
tags = [ | ||
digitalocean_tag.microk8s-worker.id | ||
] | ||
|
||
ssh_keys = [ | ||
var.digitalocean_ssh_fingerprint, | ||
] | ||
user_data = element(data.template_file.node_config.*.rendered, count.index) | ||
volume_ids = [element(digitalocean_volume.microk8s-worker-node.*.id, count.index)] | ||
|
||
} | ||
|
||
# Tag to label nodes | ||
resource "digitalocean_tag" "microk8s-worker" { | ||
name = "microk8s-worker-${var.cluster_name}" | ||
} | ||
|
||
|
||
resource "null_resource" "join_workers" { | ||
count = var.worker_node_count | ||
depends_on = [null_resource.setup_tokens, null_resource.join_nodes] | ||
triggers = { | ||
rerun = random_id.cluster_token.hex | ||
} | ||
connection { | ||
host = element(digitalocean_droplet.microk8s-worker-node.*.ipv4_address, count.index) | ||
user = "root" | ||
type = "ssh" | ||
private_key = file(var.digitalocean_private_key) | ||
timeout = "20m" | ||
} | ||
|
||
provisioner "local-exec" { | ||
interpreter = ["bash", "-c"] | ||
command = "while [[ $(cat /tmp/current_joining_worker_node.txt) != \"${count.index}\" ]]; do echo \"${count.index} is waiting...\";sleep 5;done" | ||
} | ||
|
||
provisioner "file" { | ||
content = templatefile("${path.module}/templates/join-worker.sh", | ||
{ | ||
dns_zone = var.dns_zone | ||
cluster_token = random_id.cluster_token.hex | ||
main_node_ip = digitalocean_droplet.microk8s-node[0].ipv4_address_private | ||
}) | ||
destination = "/usr/local/bin/join-worker.sh" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"sh /usr/local/bin/join-worker.sh" | ||
] | ||
} | ||
|
||
provisioner "local-exec" { | ||
interpreter = ["bash", "-c"] | ||
command = "echo \"${count.index+1}\" > /tmp/current_joining_worker_node.txt" | ||
} | ||
} | ||
|
||
# Discrete DNS records for each controller's private IPv4 for ingress usage | ||
resource "digitalocean_record" "microk8s-worker-node" { | ||
count = var.worker_node_count | ||
# DNS zone where record should be created | ||
domain = var.dns_zone | ||
|
||
# DNS record (will be prepended to domain) | ||
name = "microk8s-worker-worker-node-${count.index}" | ||
type = "A" | ||
ttl = 300 | ||
|
||
value = element(digitalocean_droplet.microk8s-worker-node.*.ipv4_address, count.index) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
until microk8s.status --wait-ready; | ||
do sleep 3; echo "waiting for worker status.."; | ||
done | ||
|
||
|
||
if microk8s status | grep "datastore master nodes: 127.0.0.1:19001" > /dev/null 2>&1; then | ||
echo "adding microk8s-cluster.${dns_zone} dns to CSR." | ||
sed -i 's@#MOREIPS@DNS.99 = microk8s-cluster.${dns_zone}\n#MOREIPS\n@g' /var/snap/microk8s/current/certs/csr.conf.template | ||
echo "done." | ||
sleep 10 | ||
microk8s join ${main_node_ip}:25000/${cluster_token} --worker | ||
else | ||
echo "Join process already done. Nothing to do" | ||
fi |
Oops, something went wrong.