2022-02-07 21:07:07 -06:00
|
|
|
# home-k8s-cluster
|
2022-02-01 17:05:06 -06:00
|
|
|
|
2022-02-07 21:07:07 -06:00
|
|
|
This repository contains the configuration, scripts, and other goodies for
|
|
|
|
building and managing my home cluster. I share the source with you so you can
|
|
|
|
make exactly the same mistakes as I do.
|
|
|
|
|
|
|
|
## Setup
|
|
|
|
|
|
|
|
Setup the pre-commit hooks before you change anything!
|
|
|
|
|
|
|
|
```
|
|
|
|
pip install pre-commit
|
|
|
|
pre-commit install --install-hooks
|
|
|
|
pre-commit autoupdate
|
|
|
|
```
|
|
|
|
|
|
|
|
## Provision Machines
|
|
|
|
|
|
|
|
Before we interact with the cluster, we have some manual work to do.
|
|
|
|
|
|
|
|
### Manual Preparation
|
|
|
|
|
|
|
|
- Currently, my nodes are Arch Linux machines on bare metal
|
2022-02-03 14:05:56 -06:00
|
|
|
- Nodes must be ready to be controlled via Ansible
|
2022-02-07 21:07:07 -06:00
|
|
|
- Have `python3` installed
|
|
|
|
- Need to be `ssh`-able from a controller (my workstation)
|
|
|
|
- `curl -L files.lyte.dev/key.pub >> ~/.ssh/authorized_keys`
|
|
|
|
|
|
|
|
**TODO**: script this? maybe custom ISO+PXEBoot? Talos+Sidero?
|
|
|
|
|
|
|
|
### Automated Provisioning
|
|
|
|
|
2022-02-03 14:05:56 -06:00
|
|
|
- Setup Ansible on the controller (from `./ansible`)
|
|
|
|
- `ansible-galaxy install -r requirements.yml --force`
|
|
|
|
- Verify Ansible can reach hosts (from `./ansible`)
|
|
|
|
- `ansible all -i inventory/hosts.yml --list-hosts`
|
|
|
|
- `ansible all -i inventory/hosts.yml -m ping`
|
2022-02-07 21:07:07 -06:00
|
|
|
- Use Ansible to build the cluster as configured on all nodes (from `./ansible`)
|
|
|
|
- `ansible-playbook -i inventory/hosts.yml ./build-k3s-cluster`
|
|
|
|
|
|
|
|
And the cluster is up! If you want to interact with it from your controller,
|
|
|
|
you can do this:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
ansible -i ansible/inventory/hosts.yml $REMOTE_HOST -m fetch \
|
|
|
|
-a "src=/etc/rancher/k3s/k3s.yaml dest=./k3s-cluster-config.kubeconfig.yaml flat=yes"
|
|
|
|
# TODO: this did not work for me
|
|
|
|
# env KUBECONFIG="~/.kube/config:./k3s-cluster-config.kubeconfig.yaml" \
|
|
|
|
# kubectl config view --flatten | sed "s/127.0.0.1/$REMOTE_HOST/" > ~/.kube/new-config
|
|
|
|
```
|
|
|
|
|
|
|
|
- Copy the cluster information from the `./k3s-cluster-config.kubeconfig.yaml` file into
|
|
|
|
your existing `~/.kube/config` (or just copy it there if it doesn't exist)
|
|
|
|
- You will need to edit the host from `localhost`/`127.0.0.1` to the correct host
|
|
|
|
|
|
|
|
### Automated Teardown
|
|
|
|
|
|
|
|
```bash
|
|
|
|
ansible-playbook -i inventory/hosts.yml ./nuke-k3s-cluster
|
|
|
|
```
|
|
|
|
|
|
|
|
## Setting up Flux
|
|
|
|
|
|
|
|
-
|