Skip to content

Commit

Permalink
Fix k0sctl usage, remove deprecated function and update readme (#17)
Browse files Browse the repository at this point in the history
* Fix k0sctl usage, remove deprecated function and update readme

* Fix github action

* Formatted terraform files

---------

Co-authored-by: Naman1997 <Naman1997@users.noreply.github.com>
  • Loading branch information
Naman1997 and Naman1997 authored Jan 14, 2025
1 parent ce85198 commit 822b56a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 47 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# Install terraform
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "^1.3.7"
terraform_wrapper: false

# Copy the terraform.tfvars.example file for variables
- name: Create terraform.tfvars
run: cp ./terraform.tfvars.example ./terraform.tfvars
Expand Down
29 changes: 7 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ A simple kubernetes cluster using Fedora Core OS, Proxmox and k0sctl.
| [Terraform](https://www.terraform.io/) | Client |
| [k0sctl](https://github.com/k0sproject/k0sctl) | Client |

## One-time Configuration

### Make versions.sh executable

A shell script is used to figure out the latest versions of coreos and k0s. This script needs to be executable by the client where you're running `terraform apply`.

```
git clone https://github.com/Naman1997/simple-fcos-cluster.git
cd simple-fcos-cluster/scripts
chmod +x ./versions.sh
```


### Create the terraform.tfvars file

Expand All @@ -39,6 +27,11 @@ cp terraform.tfvars.example terraform.tfvars
vim terraform.tfvars
```

## Enable the Snippets feature in Proxmox

In the proxmox web portal, go to `Datacenter` > `Storage` > Click on `local` > `Edit` > Under `Content` choose `Snippets` > Click on `OK` to save.

![local directory](image.png)

## Creating the cluster

Expand All @@ -52,23 +45,15 @@ terraform plan
terraform apply --auto-approve
```

The created VMs will reboot twice before `qemu-guest-agent` is able to detect their IP addresses. This can take anywhere from 2-5 mins depending on your hardware.

## Expose your cluster to the internet using an Ingress (Optional)

It is possible to expose your cluster to the internet over a small vps even if both your vps and your public ips are dynamic. This is possible by setting up dynamic dns for both your internal network and the vps using something like duckdns
and a docker container to regularly monitor the IP addresses on both ends. A connection can be then made using wireguard to traverse the network between these 2 nodes. This way you can hide your public IP while exposing services to the internet.

Project Link: [wireguard-k8s-lb](https://github.com/Naman1997/wireguard-k8s-lb) (This is one possible implementation)

### How to do this manually?

You'll need an account with duckdns - they provide you with a free subdomain that you can use to host your web services from your home internet. You'll also be needing a VPS in the cloud that can take in your traffic from a public IP address so that you don't expose your own IP address. Oracle provides a [free tier](https://www.oracle.com/in/cloud/free/) account with 4 vcpus and 24GB of memory. I'll be using this to create a VM. To expose the traffic properly, follow this [guide](https://github.com/Naman1997/simple-fcos-cluster/blob/main/docs/Wireguard_Setup.md).

For this setup, we'll be installing wireguard on the VPS and the node that is running haproxy. The traffic flow is shown in the image below.

![Wireguard_Flow drawio (1) drawio](https://user-images.githubusercontent.com/19908560/210160766-31491844-8ae0-41d9-b31c-7cfe5ee8669a.png)

## Notes

### Poweroff all VMs in the cluster

```
Expand Down
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.66.3"
version = "0.69.1"
}
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ resource "null_resource" "setup_cluster" {
MAX_RETRIES=5
RETRY_INTERVAL=10
for ((i = 1; i <= MAX_RETRIES; i++)); do
k0sctl apply --config k0sctl.yaml --disable-telemetry
k0sctl apply --config k0sctl.yaml
code=$?
if [ $code -eq 0 ]; then
break
Expand All @@ -269,7 +269,7 @@ resource "null_resource" "setup_cluster" {
fi
done
mkdir -p ~/.kube
k0sctl kubeconfig > ~/.kube/config --disable-telemetry
k0sctl kubeconfig > ~/.kube/config
chmod 600 ~/.kube/config
EOT
when = create
Expand Down
2 changes: 1 addition & 1 deletion modules/domain/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.66.3"
version = "0.69.1"
}
}
}
Expand Down
21 changes: 9 additions & 12 deletions modules/ignition/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@ terraform {
required_providers {
ct = {
source = "poseidon/ct"
version = "~> 0.13"
version = " 0.13.0"
}
}
}

# Butane config
data "template_file" "config" {
template = file("${path.module}/system-units/template.yaml")
vars = {
domain_name = var.name
ssh_authorized_key = file(pathexpand(var.ssh_key))
}
}

# Worker config converted to Ignition
data "ct_config" "ignition" {
content = data.template_file.config.*.rendered[0]
strict = true
content = templatefile(
"${path.module}/system-units/template.yaml",
{
domain_name = var.name,
ssh_authorized_key = file(pathexpand(var.ssh_key))
}
)
strict = true
}

# Send Ignition file to Proxmox server
Expand Down
16 changes: 7 additions & 9 deletions modules/proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.66.3"
version = "0.69.1"
}
}
}
Expand Down Expand Up @@ -44,14 +44,12 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
}

resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
content_type = "iso"
datastore_id = "local"
node_name = var.TARGET_NODE
url = "https://cloud-images.ubuntu.com/oracular/20241109/oracular-server-cloudimg-amd64.img"
checksum = "05bbfe57d7701c685d8c65f4d34cebe947bc89e3509c4d8a2b9c77f39e91f3ca"
checksum_algorithm = "sha256"
upload_timeout = 1000
overwrite = false
content_type = "iso"
datastore_id = "local"
node_name = var.TARGET_NODE
url = "https://cloud-images.ubuntu.com/oracular/current/oracular-server-cloudimg-amd64.img"
upload_timeout = 1000
overwrite = false
}

resource "proxmox_virtual_environment_vm" "node" {
Expand Down
Empty file modified scripts/template.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Hypervisor config
# Make sure `ssh PROXMOX_USERNAME@<PROXMOX_IP> -i <PROXMOX_SSH_KEY>` works
PROXMOX_API_ENDPOINT = "https://192.168.0.103:8006/api2/json"
PROXMOX_USERNAME = "root"
PROXMOX_PASSWORD = "password"
Expand Down

0 comments on commit 822b56a

Please sign in to comment.