🔧 Improve mk8s Terraform configuration

- instead of using 'kubectl wait nodes', we now use a simpler
  'kubectl get nodes -o name' and check if there is anything
  in the output. This seems to work better (as the previous
  method would sometimes remain stuck because the kubectl
  process would never get stopped by SIGPIPE).
- the shpod SSH NodePort is no longer hard-coded to 32222,
  which allows us to use e.g. vcluster to deploy multiple
  Kubernetes labs on a single 'home' (or 'outer') Kubernetes
  cluster.
This commit is contained in:
Jérôme Petazzoni
2023-05-13 08:19:19 +02:00
parent 11bc78851b
commit e29bfe7921
2 changed files with 5 additions and 3 deletions

View File

@@ -62,7 +62,7 @@ resource "null_resource" "wait_for_nodes" {
}
command = <<-EOT
while sleep 1; do
kubectl get nodes --watch | grep --silent --line-buffered . &&
kubectl get nodes -o name | grep --silent . &&
kubectl wait node --for=condition=Ready --all --timeout=10m &&
break
done

View File

@@ -90,7 +90,6 @@ resource "kubernetes_service" "shpod_${index}" {
name = "ssh"
port = 22
target_port = 22
node_port = 32222
}
type = "NodePort"
}
@@ -222,7 +221,10 @@ output "ip_addresses_of_nodes" {
value = join("\n", [
%{ for index, cluster in clusters ~}
join("\t", concat(
[ random_string.shpod_${index}.result, "ssh -l k8s -p 32222" ],
[
random_string.shpod_${index}.result,
"ssh -l k8s -p $${kubernetes_service.shpod_${index}.spec[0].port[0].node_port}"
],
split(" ", file("./externalips.${index}"))
)),
%{ endfor ~}