From d25acf5439e160b0a61ae10f8339ab6dfff7f930 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Sat, 25 Sep 2021 15:12:37 +0200 Subject: [PATCH] Fixed a potential bug coming from hardcoded interface names, now it should detect it automatically --- README.md | 10 +++++++++- main.tf | 2 +- master.tf | 6 +++--- variables.tf | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ba73d7f..c84ab56 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,15 @@ terraform init terraform apply -auto-approve ``` -It will take a few minutes to complete, and then you should see a green output with the IP addresses of the nodes. Then you can immediately kubectl into it without any further action. +It will take a few minutes to complete, and then you should see a green output with the IP addresses of the nodes. Then you can immediately kubectl into it (using the kubeconfig.yaml saved to the project's directory after the install). + +Just using the command `kubectl --kubeconfig kubeconfig.yaml` would work, but for more convenience, either create a symlink from `~/.kube/config` to `kubeconfig.yaml`, or add an export statement to your `~/.bashrc` or `~/.zshrc` file, as follows: + +```sh +export KUBECONFIG=//kubeconfig.yaml +``` + +To get the path, of course, you could use the `pwd` command. diff --git a/main.tf b/main.tf index fe076ec..f238da8 100644 --- a/main.tf +++ b/main.tf @@ -84,7 +84,7 @@ data "hcloud_image" "linux" { } data "template_file" "init_cfg" { - template = file("init.cfg") + template = file("${path.module}/init.cfg") } # Render a multi-part cloud-init config making use of the part diff --git a/master.tf b/master.tf index b7ce3a4..8f22a6c 100644 --- a/master.tf +++ b/master.tf @@ -49,15 +49,15 @@ resource "hcloud_server" "first_control_plane" { } provisioner "local-exec" { - command = "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${var.private_key} root@${self.ipv4_address}:/etc/rancher/k3s/k3s.yaml ./kubeconfig.yaml" + command = "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${var.private_key} root@${self.ipv4_address}:/etc/rancher/k3s/k3s.yaml ${path.module}/kubeconfig.yaml" } provisioner "local-exec" { - command = "sed -i -e 's/127.0.0.1/${self.ipv4_address}/g' ./kubeconfig.yaml" + command = "sed -i -e 's/127.0.0.1/${self.ipv4_address}/g' ${path.module}/kubeconfig.yaml" } provisioner "local-exec" { - command = "helm install --values=manifests/helm/cilium/values.yaml cilium cilium/cilium -n kube-system" + command = "helm repo add cilium https://helm.cilium.io/ --kubeconfig ${path.module}/kubeconfig.yaml; helm install --values=manifests/helm/cilium/values.yaml cilium cilium/cilium -n kube-system --kubeconfig ${path.module}/kubeconfig.yaml" } network { diff --git a/variables.tf b/variables.tf index c0c736e..a443486 100644 --- a/variables.tf +++ b/variables.tf @@ -46,12 +46,12 @@ variable "agent_server_type" { variable "k3s_server_flags" { description = "Important flags to make our setup work" - default = "--disable-cloud-controller --disable-network-policy --disable=traefik --disable=servicelb --disable='local-storage' --kubelet-arg='cloud-provider=external' --flannel-backend=none --flannel-iface=ens10" + default = "--disable-cloud-controller --disable-network-policy --disable=traefik --disable=servicelb --disable='local-storage' --kubelet-arg='cloud-provider=external' --flannel-backend=none" } variable "k3s_agent_flags" { description = "Important flags to make our setup work" - default = "--kubelet-arg='cloud-provider=external' --flannel-iface=ens10" + default = "--kubelet-arg='cloud-provider=external'" } variable "initial_commands" {