Skip to content

Commit 8b62a5f

Browse files
authored
Upgrade provider and auto-create a vm for load balancer (#10)
* Upgrade provider and remove old doc section * Upgrade provider and auto-create a VM for lb
1 parent b230836 commit 8b62a5f

File tree

9 files changed

+187
-311
lines changed

9 files changed

+187
-311
lines changed

README.md

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ Automated talos cluster with system extensions
2222

2323
Docker is mandatory on the `Client` as this projects builds a custom talos image with system extensions using the [imager](https://github.com/siderolabs/talos/pkgs/container/installer) docker image on the `Client` itself.
2424

25-
## Create an HA Proxy Server
25+
## Options for creation of HA Proxy Server
2626

27-
You can use the [no-lb](https://github.com/Naman1997/simple-talos-cluster/tree/no-lb) branch in case you do not want to use an external load-balancer. This branch uses the 1st master node that gets created as the cluster endpoint.
28-
29-
I've installed `haproxy` on my Raspberry Pi. You can choose to do the same in a LXC container or a VM.
27+
The `main` banch will automatically create a VM for a load balancer with 2 CPUs and 2 GiB of memory on your Proxmox node.
3028

31-
You need to have passwordless SSH access to a user (from the Client node) in this node which has the permissions to modify the file `/etc/haproxy/haproxy.cfg` and permissions to run `sudo systemctl restart haproxy`. An example is covered in this [doc](docs/HA_Proxy.md).
29+
You can use the [no-lb](https://github.com/Naman1997/simple-talos-cluster/tree/no-lb) branch in case you do not want to use an external load-balancer. This branch uses the 1st master node that gets created as the cluster endpoint.
3230

31+
Another option is to use the [manual-lb](https://github.com/Naman1997/simple-talos-cluster/tree/manual-lb) branch in case you wish to create an external lb manually.
3332

3433
## Create the terraform.tfvars file
3534

@@ -50,24 +49,6 @@ terraform plan
5049
terraform apply --auto-approve
5150
```
5251

53-
## Using HAProxy as a Load Balancer for an Ingress
54-
55-
Since HAProxy is load-balancing ports 80 and 443 (of worker nodes), we can deploy nginx-controller such that it uses those ports as an external load balancer IP.
56-
57-
```
58-
kubectl label ns ingress-nginx pod-security.kubernetes.io/enforce=privileged
59-
# Update the IP address in the controller yaml
60-
vim ./nginx-example/nginx-controller.yaml
61-
helm install ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx --values ./nginx-example/nginx-controller.yaml --create-namespace
62-
kubectl create deployment nginx --image=nginx --replicas=5
63-
k expose deploy nginx --port 80
64-
# Edit this config to point to your domain
65-
vim ./nginx-example/ingress.yaml.example
66-
mv ./nginx-example/ingress.yaml.example ./nginx-example/ingress.yaml
67-
k create -f ./nginx-example/ingress.yaml
68-
curl -k https://192.168.0.101
69-
```
70-
7152
## Expose your cluster to the internet (Optional)
7253

7354
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

docs/Wireguard_Setup.md

Lines changed: 0 additions & 256 deletions
This file was deleted.

main.tf

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
}
88
proxmox = {
99
source = "bpg/proxmox"
10-
version = "0.57.1"
10+
version = "0.65.0"
1111
}
1212
}
1313
}
@@ -24,6 +24,7 @@ data "external" "versions" {
2424
}
2525

2626
locals {
27+
ha_proxy_user = "ubuntu"
2728
qemu_ga_version = data.external.versions.result["qemu_ga_version"]
2829
amd_ucode_version = data.external.versions.result["amd_ucode_version"]
2930
intel_ucode_version = data.external.versions.result["intel_ucode_version"]
@@ -159,10 +160,19 @@ module "worker_domain" {
159160
scan_interface = var.INTERFACE_TO_SCAN
160161
}
161162

163+
module "proxy" {
164+
source = "./modules/proxy"
165+
ha_proxy_user = local.ha_proxy_user
166+
DEFAULT_BRIDGE = var.DEFAULT_BRIDGE
167+
TARGET_NODE = var.TARGET_NODE
168+
ssh_key = join("", [var.SSH_KEY, ".pub"])
169+
}
170+
162171
resource "local_file" "haproxy_config" {
163172
depends_on = [
164173
module.master_domain.node,
165-
module.worker_domain.node
174+
module.worker_domain.node,
175+
module.proxy.node
166176
]
167177
content = templatefile("${path.root}/templates/haproxy.tmpl",
168178
{
@@ -181,17 +191,17 @@ resource "local_file" "haproxy_config" {
181191
destination = "/etc/haproxy/haproxy.cfg"
182192
connection {
183193
type = "ssh"
184-
host = var.ha_proxy_server
185-
user = var.ha_proxy_user
186-
private_key = file(var.ha_proxy_key)
194+
host = module.proxy.proxy_ipv4_address
195+
user = local.ha_proxy_user
196+
private_key = file(var.SSH_KEY)
187197
}
188198
}
189199

190200
provisioner "remote-exec" {
191201
connection {
192-
host = var.ha_proxy_server
193-
user = var.ha_proxy_user
194-
private_key = file(var.ha_proxy_key)
202+
host = module.proxy.proxy_ipv4_address
203+
user = local.ha_proxy_user
204+
private_key = file(var.SSH_KEY)
195205
}
196206
script = "${path.root}/scripts/haproxy.sh"
197207
}
@@ -200,11 +210,13 @@ resource "local_file" "haproxy_config" {
200210
resource "local_file" "talosctl_config" {
201211
depends_on = [
202212
module.master_domain.node,
203-
module.worker_domain.node
213+
module.worker_domain.node,
214+
module.proxy.node,
215+
resource.local_file.haproxy_config
204216
]
205217
content = templatefile("${path.root}/templates/talosctl.tmpl",
206218
{
207-
load_balancer = var.ha_proxy_server,
219+
load_balancer = module.proxy.proxy_ipv4_address,
208220
node_map_masters = tolist(module.master_domain.*.address),
209221
node_map_workers = tolist(module.worker_domain.*.address)
210222
primary_controller = module.master_domain[0].address

modules/domain/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
proxmox = {
44
source = "bpg/proxmox"
5-
version = "0.57.1"
5+
version = "0.65.0"
66
}
77
}
88
}

0 commit comments

Comments
 (0)