-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dbrennand/k3s
Merge progress to dev
- Loading branch information
Showing
24 changed files
with
452 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# Used on Proxmox node(s) to generate a certificate for the node's Tailscale FQDN | ||
# This allows for the Proxmox Web GUI to be accessed via the Tailscale FQDN | ||
# Requires jq and tailscale to be installed | ||
# Checks every 60 days if the certificate needs to be renewed | ||
|
||
# File where the last run date is stored | ||
LAST_RUN_FILE="${HOME}/proxmox_tailscale_cert.last_run" | ||
|
||
# Read the last run date from the file | ||
if [[ -f "${LAST_RUN_FILE}" ]]; then | ||
last_run=$(cat "${LAST_RUN_FILE}") | ||
else | ||
last_run=$(date -d "60 days ago" +%F) | ||
fi | ||
|
||
# Calculate the next run date (60 days after the last run) | ||
next_run=$(date -d "${last_run} + 60 days" +%F) | ||
today=$(date +%F) | ||
|
||
# Run the task if today is the next run date | ||
if [[ "${today}" == "${next_run}" ]]; then | ||
# Snippet below taken from: https://tailscale.com/kb/1133/proxmox#enable-https-access-to-the-proxmox-web-ui | ||
NAME="$(tailscale status --json | jq '.Self.DNSName | .[:-1]' -r)" | ||
tailscale cert "${NAME}" | ||
pvenode cert set "${NAME}.crt" "${NAME}.key" --force --restart | ||
# Update the last run date | ||
echo "${today}" > "${LAST_RUN_FILE}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
# control group_vars | ||
k3s_control_node: true | ||
k3s_server: | ||
node-ip: "{{ ansible_host }}" | ||
tls-san: | ||
- "{{ kube_vip_address }}" | ||
disable-cloud-controller: true | ||
write-kubeconfig-mode: "644" | ||
disable: | ||
- traefik | ||
- servicelb | ||
k3s_server_manifests_urls: | ||
# kube-vip rbac - https://kube-vip.io/docs/usage/k3s/#step-2-upload-kube-vip-rbac-manifest | ||
- url: https://raw.githubusercontent.com/kube-vip/kube-vip/main/docs/manifests/rbac.yaml | ||
filename: kube-vip-rbac.yaml | ||
# kube-vip cloud controller - https://kube-vip.io/docs/usage/cloud-provider/ | ||
- url: https://raw.githubusercontent.com/kube-vip/kube-vip-cloud-provider/main/manifest/kube-vip-cloud-controller.yaml | ||
filename: kube-vip-cloud-controller.yaml | ||
k3s_server_manifests_templates: | ||
- kube-vip-daemonset.yml.j2 | ||
- kubevip-configmap.yml.j2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
# workers group_vars | ||
k3s_control_node: false | ||
k3s_agent: | ||
node-ip: "{{ ansible_host }}" | ||
longhorn_disk: /dev/sdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
- name: Build K3s cluster | ||
hosts: k3s | ||
vars_files: | ||
- ../vars/k3s.yml | ||
pre_tasks: | ||
- name: Longhorn tasks | ||
when: not k3s_control_node | ||
tags: | ||
- longhorn | ||
block: | ||
- name: Install open-iscsi and nfs-common for Longhorn | ||
ansible.builtin.apt: | ||
name: | ||
- open-iscsi | ||
- nfs-common | ||
state: present | ||
become: true | ||
|
||
- name: Create /mnt/longhorn directory | ||
ansible.builtin.file: | ||
path: /mnt/longhorn | ||
state: directory | ||
mode: u=rwx,g=rx,o=rx | ||
become: true | ||
|
||
- name: "Ensure disk partition exists on {{ longhorn_disk }}" | ||
community.general.parted: | ||
device: "{{ longhorn_disk }}" | ||
number: 1 | ||
label: gpt | ||
part_start: 0% | ||
part_end: 100% | ||
part_type: primary | ||
fs_type: ext4 | ||
state: present | ||
become: true | ||
|
||
- name: "Ensure ext4 filesystem exists on {{ longhorn_disk }}1" # noqa name[template] | ||
community.general.filesystem: | ||
fstype: ext4 | ||
dev: "{{ longhorn_disk }}1" | ||
become: true | ||
|
||
- name: "Get UUID for {{ longhorn_disk }}1" # noqa name[template] | ||
ansible.builtin.command: | ||
cmd: "blkid {{ longhorn_disk }}1 -s UUID -o value" | ||
register: longhorn_block_device_part_uuid | ||
changed_when: false | ||
become: true | ||
|
||
- name: "Mount /mnt/longhorn on {{ longhorn_block_device_part_uuid.stdout }}" | ||
ansible.posix.mount: | ||
path: /mnt/longhorn | ||
src: "UUID={{ longhorn_block_device_part_uuid.stdout }}" | ||
fstype: ext4 | ||
state: mounted | ||
become: true | ||
roles: | ||
- role: xanmanning.k3s | ||
post_tasks: | ||
- name: Copy kubeconfig to local machine | ||
when: k3s_control_node | ||
block: | ||
- name: Ensure ~/.kube directory exists | ||
ansible.builtin.file: | ||
path: ~/.kube | ||
state: directory | ||
mode: u=rwx,g=,o= | ||
delegate_to: localhost | ||
|
||
- name: Copy kubeconfig from control node to local machine | ||
ansible.builtin.fetch: | ||
src: /etc/rancher/k3s/k3s.yaml | ||
dest: ~/.kube/config | ||
flat: true | ||
|
||
- name: Replace localhost with control node IP | ||
ansible.builtin.replace: | ||
path: ~/.kube/config | ||
regexp: '127.0.0.1' | ||
replace: "{{ kube_vip_address }}" | ||
delegate_to: localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
# https://pve.proxmox.com/wiki/Cluster_Manager#_corosync_external_vote_support | ||
# https://www.apalrd.net/posts/2022/cluster_qdevice/ | ||
- name: Proxmox Nodes - Cluster External Vote Support | ||
hosts: proxmox | ||
become: true | ||
tasks: | ||
- name: Install corosync-qdevice | ||
ansible.builtin.apt: | ||
name: | ||
- corosync-qdevice | ||
state: present | ||
|
||
- name: Raspberry Pi - Cluster External Vote Support | ||
hosts: pihole.net.dbren.uk | ||
become: true | ||
tasks: | ||
- name: Install corosync-qnetd | ||
ansible.builtin.apt: | ||
name: | ||
- corosync-qnetd | ||
state: present | ||
|
||
- name: Next steps | ||
ansible.builtin.debug: | ||
msg: | | ||
Run the following command on the Proxmox primary node: | ||
pvecm qdevice setup <QDEVICE-IP> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
- name: Provision Proxmox LVM Storage | ||
hosts: proxmox | ||
become: true | ||
vars: | ||
ssds: | ||
# Crucial SSD | ||
- device: /dev/sdb | ||
partition_name: pv-ssd-crucial | ||
vg_name: vg-ssd-crucial | ||
lv_name: lv-ssd-crucial | ||
# Samsung SSD | ||
- device: /dev/sdc | ||
partition_name: pv-ssd-samsung | ||
vg_name: vg-ssd-samsung | ||
lv_name: lv-ssd-samsung | ||
tasks: | ||
- name: Create | LVM Physical Volume Partition | ||
loop: "{{ ssds }}" | ||
community.general.parted: | ||
device: "{{ item.device }}" | ||
name: "{{ item.partition_name }}" | ||
label: gpt | ||
number: 1 | ||
part_start: 0% | ||
part_end: 100% | ||
flags: | ||
- lvm | ||
state: present | ||
|
||
- name: Create | LVM Volume Group | ||
loop: "{{ ssds }}" | ||
community.general.lvg: | ||
vg: "{{ item.vg_name }}" | ||
pvs: "{{ item.device }}1" | ||
state: present | ||
|
||
- name: Create | LVM Logical Volume | ||
loop: "{{ ssds }}" | ||
when: item.lv_name not in ansible_lvm.lvs | ||
community.general.lvol: | ||
vg: "{{ item.vg_name }}" | ||
thinpool: "{{ item.lv_name }}" | ||
size: 100%FREE | ||
state: present | ||
|
||
- name: Proxmox | Configure LVM Logical Volumes | ||
loop: "{{ ssds }}" | ||
loop_control: | ||
index_var: index | ||
ansible.builtin.blockinfile: | ||
path: /etc/pve/storage.cfg | ||
backup: true | ||
marker: "\n# {mark} ANSIBLE MANAGED BLOCK {{ index }}" | ||
block: | | ||
lvmthin: {{ item.lv_name }} | ||
thinpool {{ item.lv_name }} | ||
vgname {{ item.vg_name }} | ||
content rootdir,images | ||
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.