Skip to content

Commit

Permalink
add janky tf
Browse files Browse the repository at this point in the history
  • Loading branch information
james-otten committed Apr 27, 2024
1 parent d9cef77 commit aa797a2
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 0 deletions.
74 changes: 74 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Meshdb Environment Setup

1. Configure a user for the [proxmox provider](https://registry.terraform.io/providers/Telmate/proxmox/latest/docs) and setup env vars.
2. Setup tfvars + ssh keys
3. `terraform plan --var-file=your.tfvars`
4. `terraform apply --var-file=your.tfvars`
5. Login via serial and figure out the IPs that were recieved from DHCP
6. SSH into the master node and setup
```
curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable servicelb
echo "cluster-init: true" >> /etc/rancher/k3s/config.yaml
echo "disable: servicelb" >> /etc/rancher/k3s/config.yaml
```

7. Install metallb on master node

```
IP_RANGE="10.70.90.71/32"
cat <<EOF > /var/lib/rancher/k3s/server/manifests/metallb.yaml
apiVersion: v1
kind: Namespace
metadata:
name: metallb-system
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: metallb
namespace: metallb-system
spec:
repo: https://metallb.github.io/metallb
chart: metallb
targetNamespace: metallb-system
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: pool-1
namespace: metallb-system
spec:
addresses:
- $IP_RANGE
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: k3s-l2
namespace: metallb-system
spec:
ipAddressPools:
- pool-1
EOF
```

8. Setup each node (from the manager)

`bash setup_node.sh <NODE IP>`

```
#!/bin/bash
# setup_node.sh
MASTER_IP="$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)"
NODE_TOKEN="$(cat /var/lib/rancher/k3s/server/node-token)"
target_host="$1"
ssh -t ubuntu@$target_host "curl -sfL https://get.k3s.io>k3s; sudo bash k3s --server https://${MASTER_IP}:6443 --token $NODE_TOKEN"
```

9. Install helm chart...
7 changes: 7 additions & 0 deletions infra/tf/example.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
meshdb_proxmox_host = ""
meshdb_proxmox_node = "jon"
meshdb_proxmox_template_image = "ubuntu-cloud"
meshdb_proxmox_storage_location = "local-lvm"
meshdb_env_name = "garfield"
meshdb_local_user = "ubuntu"
meshdb_local_password = ""
16 changes: 16 additions & 0 deletions infra/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "3.0.1-rc1"
}
}
}

provider "proxmox" {
# Configuration options
pm_api_url = "https://${vars.meshdb_proxmox_host}:8006/api2/json"
# TODO: Setup cert
pm_tls_insecure = true
pm_debug = true
}
50 changes: 50 additions & 0 deletions infra/tf/mgr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
resource "proxmox_vm_qemu" "meshdbdevmgr" {
name = "meshdb${var.meshdb_env_name}mgr"
desc = "managment server for meshdb ${var.meshdb_env_name}"
target_node = var.meshdb_proxmox_node

clone = var.meshdb_proxmox_template_image

cores = 2
sockets = 1
memory = 2560
os_type = "cloud-init"
agent = 0
cloudinit_cdrom_storage = var.meshdb_proxmox_storage_location
ciuser = var.meshdb_local_user
cipassword = var.meshdb_local_password

scsihw = "virtio-scsi-pci"

disks {
scsi {
scsi0 {
disk {
backup = false
size = 50
storage = var.meshdb_proxmox_storage_location

}
}
}
}

network {
bridge = "vmbr0"
model = "virtio"
}

ipconfig0 = "ip=dhcp"

ssh_user = "root"
ssh_private_key = file("${path.module}/meshdb${var.meshdb_env_name}")

sshkeys = file("${path.module}/meshdb${var.meshdb_env_name}.pub")

serial {
id = 0
type = "socket"
}

tags = "meshdb${var.meshdb_env_name}"
}
39 changes: 39 additions & 0 deletions infra/tf/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "meshdb_proxmox_host" {
type = string
description = "ip/domain of the proxmox server"
}

variable "meshdb_proxmox_node" {
type = string
description = "target node on the proxmox server"
default = "jon"
}

variable "meshdb_proxmox_template_image" {
type = string
description = "name of the template you have already setup in proxmox"
default = "ubuntu-cloud"
}

variable "meshdb_proxmox_storage_location" {
type = string
description = "target resource pool on the proxmox server"
default = "local-lvm"
}

variable "meshdb_env_name" {
type = string
description = "name of the environment(dev0, dev1, stage, prod)"
}

variable "meshdb_local_user" {
type = string
description = "local user username"
default = "ubuntu"
}

variable "meshdb_local_password" {
type = string
description = "password for the local user"
sensitive = true
}
57 changes: 57 additions & 0 deletions infra/tf/workers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
resource "proxmox_vm_qemu" "meshdbnode" {
for_each = {
"node1" = { name = "1" }
"node2" = { name = "2" }
"node3" = { name = "3" }
}

name = "meshdb${var.meshdb_env_name}node${each.value.name}"
desc = "node ${each.value.name} for meshdb ${var.meshdb_env_name}"
target_node = var.meshdb_proxmox_node

clone = var.meshdb_proxmox_template_image

cores = 2
sockets = 1
memory = 2560
os_type = "cloud-init"
agent = 0
cloudinit_cdrom_storage = var.meshdb_proxmox_storage_location
ciuser = var.meshdb_local_user
cipassword = var.meshdb_local_password

scsihw = "virtio-scsi-pci"

disks {
scsi {
scsi0 {
disk {
backup = false
size = 50
storage = var.meshdb_proxmox_storage_location

}
}
}
}

network {
bridge = "vmbr0"
model = "virtio"
}

ipconfig0 = "ip=dhcp"

#ssh_user = "root"
#ssh_private_key = file("${path.module}/meshdb${var.meshdb_env_name}")

sshkeys = file("${path.module}/meshdb${var.meshdb_env_name}.pub")

serial {
id = 0
type = "socket"
}

tags = "meshdb${var.meshdb_env_name}"
}

0 comments on commit aa797a2

Please sign in to comment.