Skip to content

Commit aa797a2

Browse files
committed
add janky tf
1 parent d9cef77 commit aa797a2

File tree

6 files changed

+243
-0
lines changed

6 files changed

+243
-0
lines changed

infra/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Meshdb Environment Setup
2+
3+
1. Configure a user for the [proxmox provider](https://registry.terraform.io/providers/Telmate/proxmox/latest/docs) and setup env vars.
4+
2. Setup tfvars + ssh keys
5+
3. `terraform plan --var-file=your.tfvars`
6+
4. `terraform apply --var-file=your.tfvars`
7+
5. Login via serial and figure out the IPs that were recieved from DHCP
8+
6. SSH into the master node and setup
9+
```
10+
curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable servicelb
11+
12+
echo "cluster-init: true" >> /etc/rancher/k3s/config.yaml
13+
echo "disable: servicelb" >> /etc/rancher/k3s/config.yaml
14+
```
15+
16+
7. Install metallb on master node
17+
18+
```
19+
IP_RANGE="10.70.90.71/32"
20+
cat <<EOF > /var/lib/rancher/k3s/server/manifests/metallb.yaml
21+
apiVersion: v1
22+
kind: Namespace
23+
metadata:
24+
name: metallb-system
25+
---
26+
apiVersion: helm.cattle.io/v1
27+
kind: HelmChart
28+
metadata:
29+
name: metallb
30+
namespace: metallb-system
31+
spec:
32+
repo: https://metallb.github.io/metallb
33+
chart: metallb
34+
targetNamespace: metallb-system
35+
36+
---
37+
apiVersion: metallb.io/v1beta1
38+
kind: IPAddressPool
39+
metadata:
40+
name: pool-1
41+
namespace: metallb-system
42+
spec:
43+
addresses:
44+
- $IP_RANGE
45+
46+
---
47+
apiVersion: metallb.io/v1beta1
48+
kind: L2Advertisement
49+
metadata:
50+
name: k3s-l2
51+
namespace: metallb-system
52+
spec:
53+
ipAddressPools:
54+
- pool-1
55+
EOF
56+
57+
```
58+
59+
8. Setup each node (from the manager)
60+
61+
`bash setup_node.sh <NODE IP>`
62+
63+
```
64+
#!/bin/bash
65+
# setup_node.sh
66+
MASTER_IP="$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)"
67+
NODE_TOKEN="$(cat /var/lib/rancher/k3s/server/node-token)"
68+
69+
target_host="$1"
70+
71+
ssh -t ubuntu@$target_host "curl -sfL https://get.k3s.io>k3s; sudo bash k3s --server https://${MASTER_IP}:6443 --token $NODE_TOKEN"
72+
```
73+
74+
9. Install helm chart...

infra/tf/example.tfvars

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
meshdb_proxmox_host = ""
2+
meshdb_proxmox_node = "jon"
3+
meshdb_proxmox_template_image = "ubuntu-cloud"
4+
meshdb_proxmox_storage_location = "local-lvm"
5+
meshdb_env_name = "garfield"
6+
meshdb_local_user = "ubuntu"
7+
meshdb_local_password = ""

infra/tf/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_providers {
3+
proxmox = {
4+
source = "telmate/proxmox"
5+
version = "3.0.1-rc1"
6+
}
7+
}
8+
}
9+
10+
provider "proxmox" {
11+
# Configuration options
12+
pm_api_url = "https://${vars.meshdb_proxmox_host}:8006/api2/json"
13+
# TODO: Setup cert
14+
pm_tls_insecure = true
15+
pm_debug = true
16+
}

infra/tf/mgr.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resource "proxmox_vm_qemu" "meshdbdevmgr" {
2+
name = "meshdb${var.meshdb_env_name}mgr"
3+
desc = "managment server for meshdb ${var.meshdb_env_name}"
4+
target_node = var.meshdb_proxmox_node
5+
6+
clone = var.meshdb_proxmox_template_image
7+
8+
cores = 2
9+
sockets = 1
10+
memory = 2560
11+
os_type = "cloud-init"
12+
agent = 0
13+
cloudinit_cdrom_storage = var.meshdb_proxmox_storage_location
14+
ciuser = var.meshdb_local_user
15+
cipassword = var.meshdb_local_password
16+
17+
scsihw = "virtio-scsi-pci"
18+
19+
disks {
20+
scsi {
21+
scsi0 {
22+
disk {
23+
backup = false
24+
size = 50
25+
storage = var.meshdb_proxmox_storage_location
26+
27+
}
28+
}
29+
}
30+
}
31+
32+
network {
33+
bridge = "vmbr0"
34+
model = "virtio"
35+
}
36+
37+
ipconfig0 = "ip=dhcp"
38+
39+
ssh_user = "root"
40+
ssh_private_key = file("${path.module}/meshdb${var.meshdb_env_name}")
41+
42+
sshkeys = file("${path.module}/meshdb${var.meshdb_env_name}.pub")
43+
44+
serial {
45+
id = 0
46+
type = "socket"
47+
}
48+
49+
tags = "meshdb${var.meshdb_env_name}"
50+
}

infra/tf/vars.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "meshdb_proxmox_host" {
2+
type = string
3+
description = "ip/domain of the proxmox server"
4+
}
5+
6+
variable "meshdb_proxmox_node" {
7+
type = string
8+
description = "target node on the proxmox server"
9+
default = "jon"
10+
}
11+
12+
variable "meshdb_proxmox_template_image" {
13+
type = string
14+
description = "name of the template you have already setup in proxmox"
15+
default = "ubuntu-cloud"
16+
}
17+
18+
variable "meshdb_proxmox_storage_location" {
19+
type = string
20+
description = "target resource pool on the proxmox server"
21+
default = "local-lvm"
22+
}
23+
24+
variable "meshdb_env_name" {
25+
type = string
26+
description = "name of the environment(dev0, dev1, stage, prod)"
27+
}
28+
29+
variable "meshdb_local_user" {
30+
type = string
31+
description = "local user username"
32+
default = "ubuntu"
33+
}
34+
35+
variable "meshdb_local_password" {
36+
type = string
37+
description = "password for the local user"
38+
sensitive = true
39+
}

infra/tf/workers.tf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
resource "proxmox_vm_qemu" "meshdbnode" {
2+
for_each = {
3+
"node1" = { name = "1" }
4+
"node2" = { name = "2" }
5+
"node3" = { name = "3" }
6+
}
7+
8+
name = "meshdb${var.meshdb_env_name}node${each.value.name}"
9+
desc = "node ${each.value.name} for meshdb ${var.meshdb_env_name}"
10+
target_node = var.meshdb_proxmox_node
11+
12+
clone = var.meshdb_proxmox_template_image
13+
14+
cores = 2
15+
sockets = 1
16+
memory = 2560
17+
os_type = "cloud-init"
18+
agent = 0
19+
cloudinit_cdrom_storage = var.meshdb_proxmox_storage_location
20+
ciuser = var.meshdb_local_user
21+
cipassword = var.meshdb_local_password
22+
23+
scsihw = "virtio-scsi-pci"
24+
25+
disks {
26+
scsi {
27+
scsi0 {
28+
disk {
29+
backup = false
30+
size = 50
31+
storage = var.meshdb_proxmox_storage_location
32+
33+
}
34+
}
35+
}
36+
}
37+
38+
network {
39+
bridge = "vmbr0"
40+
model = "virtio"
41+
}
42+
43+
ipconfig0 = "ip=dhcp"
44+
45+
#ssh_user = "root"
46+
#ssh_private_key = file("${path.module}/meshdb${var.meshdb_env_name}")
47+
48+
sshkeys = file("${path.module}/meshdb${var.meshdb_env_name}.pub")
49+
50+
serial {
51+
id = 0
52+
type = "socket"
53+
}
54+
55+
tags = "meshdb${var.meshdb_env_name}"
56+
}
57+

0 commit comments

Comments
 (0)