This is an example project for setting up your own K3s cluster at home.
This will spin up:
- 1 support vm with api loadbalancer and k3s database with 2 cores and 4Gb mem
- 2 master nodes with 2 cores and 4Gb mem
- 1 node pool with 2 worker nodes each having 2 cores and 4Gb mem
- The support VM will be spun up on
192.168.0.200
- The master VMs will be spun up on
192.168.0.201
and192.168.0.202
- The worker VMs will be spun up on
192.168.0.208
and192.168.0.209
Note: To eliminate potential IP clashing with existing computers on your network, it is STRONGLY recommended that you take IPs
192.168.0.200
-192.168.0.254
out of your DHCP server's rotation. Otherwise other computers in your network may already be using these IPs and that will create conflicts! Check your router's manual or google it for a step-by-step guide.
To run this example, make sure you cd
to this directory in your terminal,
then
- Copy your public key to the
authorized_keys
file. In most cases, you should be able to do this by runningcat ~/.ssh/id_rsa.pub > authorized_keys
. - Find your Proxmox API. It should look something like
https://192.168.0.25:8006/api2/json
. Once you found it, update the value in themain.tf
file marked asTODO
in theprovider proxmox
section. - Authenticate to the proxmox API for the current terminal session by setting the two variables:
# Update these to be your proxmox user/password.
# Note that you usually need to keep the @pam at the end of the user.
export PM_USER="terraform-prov@pve"
export PM_PASS="password"
Find other ways to auth to proxmox by reading the providor's docs.
- Run
terraform init
(only needs to be done the first time) - Run
terraform apply
- Review the plan. Make sure it is doing what you expect!
- Enter
yes
in the prompt and wait for your cluster to spin up. - Retrieve your kubecontext by running
terraform output -raw kubeconfig > config.yaml
- Make all your
kubectl
commands work with your cluster for your terminal session by runningexport KUBECONFIG="config.yaml"
. If you want to add the context more perminantly globaly, refer to the document on managing Kubernetes configs.