-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Module to get K8S join command from control plane (#2)
- Loading branch information
1 parent
26d9d6a
commit eee330e
Showing
8 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
# Kuberenetes Related Modules |
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,5 @@ | ||
# Get Join | ||
|
||
Small module that will ssh into a k8s control plan node and run the create join command. This will return a map of info needed to run the join command as well as the full join command. | ||
|
||
Intended to be passed to cloud-init of a pre-configured worker node to auto join a cluster. |
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,17 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
eval "$(jq -r '@sh "k8s_host=\(.hostname) ssh_user=\(.ssh_user)"')" | ||
|
||
out=$(ssh -q ${ssh_user}@${k8s_host} <<'EOF' | ||
kubeadm token create --print-join-command | ||
EOF | ||
) | ||
|
||
join_command="${out##*$'\n'}" | ||
join_command="$(echo "$join_command"|tr -d '\n')" | ||
|
||
join_command=($join_command) | ||
|
||
|
||
echo $(jq -n --arg host "${join_command[2]}" --arg token "${join_command[4]}" --arg cacerthash "${join_command[6]}" '{"host":$host,"token":$token,"cacerthash":$cacerthash}') |
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,5 @@ | ||
|
||
data "external" "k8s" { | ||
program = ["bash", "${path.module}/get_join.sh"] | ||
query = var.k8s_control_config | ||
} |
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,11 @@ | ||
output "k8s_join" { | ||
description = "Map of config values needed to join a kuberentes cluster." | ||
value = data.external.k8s.result | ||
senstive = true | ||
} | ||
|
||
output "full_join_command" { | ||
description = "Full command to join a worker node to kubernetes cluster." | ||
senstive = true | ||
value = "kubeadm join ${data.external.k8s.result.host} --token ${data.external.k8s.result.token} --discovery-token-ca-cert-hash ${data.external.k8s.result.cacerthash}" | ||
} |
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,7 @@ | ||
variable "k8s_control_config" { | ||
description = "Hostname/SSH User of K8S control plan node to get join command from. Assumes your private is deployed for `ssh_user`." | ||
type = object({ | ||
hostname = string | ||
ssh_user = string | ||
}) | ||
} |
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,3 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
} |