Merge infra and k3 into one directory again

Since I don't have multiple terraform steps anymore it simply doesn't
make sense to me anymore to split all tasks into separate folders.
Instead I try to be as clear as possible in the README to make it easy
to follow the structure in the future without too much headache.
This commit is contained in:
2025-09-21 19:28:08 +02:00
parent fef383fed4
commit 7297892e18
32 changed files with 70 additions and 99 deletions

View File

@@ -11,11 +11,9 @@ The setup is split into 2 dedicated parts:
[source,bash] [source,bash]
---- ----
cd infra
terraform init terraform init
terraform apply terraform apply
sleep 300 # Wait 5 minutes since the machines start _slow_ sometimes sleep 300 # Wait 5 minutes since the machines start _slow_ sometimes
cd ../k3s
ansible-galaxy install -r requirements.yml ansible-galaxy install -r requirements.yml
ansible-playbook site.yml ansible-playbook site.yml
---- ----
@@ -27,26 +25,82 @@ ansible-playbook site.yml
== Setup == Setup
The project is split into different directories, each responsible for another task. The project is split into different steps, each responsible for another task.
For the initial setup it is mandatory to follow the instructions of each directory in the following order.
Subsequent changes may only require a subset of these instructions.
Though, it should be safe to run each step multiple times, they should all be indempotent.
=== infra === terraform
I use terraform to provide the required infrastructure to run a kubernetes-cluster.
Run this setup in the `infra/` directory. [WARNING]
Make sure `config.auto.tfvars` with all the needed configuration-secrets is present otherwise the module cannot be applied!
The file is savely stored in the password-manager.
include::./infra/README.adoc[tag=setup] [source,bash]
----
terraform init # <1>
terraform apply # <2>
----
=== k3s <1> Init the terraform modules if necessary
<2> Setup infrastructure and create/update inventory.ini
Run this setup in the `k3s/` directory. [WARNING]
The setup will take longer than just the `terraform apply`, since terraform returns as soon as the machine is provided.
Though it hasn't been started the machines, yet.
As a rule of thumb wait ca. 5 minutes after the apply to do other work.
=== ansible
Use ansible to setup a k3s installation and provide a set of foundational services in the cluster.
The provided services are:
https://cert-manager.io/docs/installation/helm[cert-manager]::
This allows issuing TLS certificates.
The certificates are issued via https://letsencrypt.org[let's encrypt] and can be issued for the staging and production stage of let's encrypt.
https://www.min.io[minio]::
Allow me to store data in an object storage.
+
TODO: Not setup yet!
https://concourse-ci.org[concourse-ci]::
A powerful CI-cervice which I like to use to automate all kind of workloads.
+
TODO: Not setup yet!
https://about.gitea.com[gitea]::
My personal favourite git-server.
+
TODO: Not setup yet!
https://github.com/pinterest/snappass[snappass]::
A secure and reliable tool to share password.
+
TODO: Not setup yet!
[NOTE] [NOTE]
The k3s-setup requires a `inventory.ini` which is automatically created by the infra. The k3s-setup requires a `inventory.ini` which is automatically created by terraform.
So, make sure to apply the infra at least once, before running these playbooks. So, make sure to apply the infra at least once, before running these playbooks.
include::./k3s/README.adoc[tag=setup] [source,bash]
----
ansible-galaxy install -r requirements.yml # <1>
ansible-playbook site.yml # <2>
----
<1> Install required ansible collections to create a k3s-cluster (can be omitted in subsequent runs)
<2> Install k3s and download kube-config to .kube/config
[IMPORTANT]
The second step will override any existing kube config, this might destroy any existing settings!
[NOTE]
--
To apply the playbook you may need to install additional packages:
* https://helm.sh/docs/intro/install/[helm]
* https://github.com/databus23/helm-diff?tab=readme-ov-file#install[helm-diff]
* python3-kubernetes (Debian/Ubuntu)
--
== Enlarge / Reduce size of cluster == Enlarge / Reduce size of cluster
@@ -68,7 +122,7 @@ Instead proceed as the following:
== Responsibilities == Responsibilities
`infra/`:: terraform::
* Creation of network for the kubernetes-cluster * Creation of network for the kubernetes-cluster
** A public subnet exposed to the internet for the kubernetes-servers ** A public subnet exposed to the internet for the kubernetes-servers
** A private subnet for the kubernetes-agents ** A private subnet for the kubernetes-agents
@@ -82,11 +136,9 @@ Instead proceed as the following:
* Creating the machines for kubernetes-agents in the private subnet * Creating the machines for kubernetes-agents in the private subnet
* Creating DNS-records in Hetzer Cloud * Creating DNS-records in Hetzer Cloud
`k3s/`:: ansible::
* Setup SSH-connections * Setup SSH-connections
* Setting up routing on all servers * Setting up routing on all servers
* Installing k3s * Installing k3s
* Keep the software up-to-date * Keep the software up-to-date
* Add foundational services to the cluster * Add foundational services to the cluster

View File

@@ -1,25 +0,0 @@
= infra
:icons: font
This project is responsible for providing the required infra to run a kubernetes-cluster.
== Setup
// tag::setup[]
[WARNING]
Make sure `config.auto.tfvars` with all the needed configuration-secrets is present otherwise the module cannot be applied!
The file is savely stored in the password-manager.
[source,bash]
----
terraform init # <1>
terraform apply # <2>
----
<1> Init the terraform modules if necessary
<2> Setup infrastructure and create/update inventory.ini
[WARNING]
The setup will take longer than just the `terraform apply`, since it will install some.
As a rule of thumb wait ca. 5 minutes after the apply to do other work.
// end::setup[]

View File

@@ -1,56 +0,0 @@
= k3s
:icons: font
This project is responsible for setting up a k3s installation and provide a set of foundational services in the cluster.
The provided services are:
cert-manager::
This allows issuing TLS certificates.
The certificates are issued via https://letsencrypt.org[let's encrypt] and can be issued for the staging and production stage of let's encrypt.
minio::
Allow me to store data in an object storage.
+
TODO: Not setup yet!
concourse-ci::
A powerful CI-cervice which I like to use to automate all kind of workloads.
+
TODO: Not setup yet!
gitea::
My personal favourite git-server.
+
TODO: Not setup yet!
snappass::
A secure and reliable tool to share password.
+
TODO: Not setup yet!
== Setup
The setup requires a `inventory.ini` this should be provided by a previous step.
// tag::setup[]
[source,bash]
----
ansible-galaxy install -r requirements.yml # <1>
ansible-playbook site.yml # <2>
----
<1> Install required ansible collections to create a k3s-cluster (can be omitted in subsequent runs)
<2> Install k3s and download kube-config to .kube/config
[IMPORTANT]
The second step will override any existing kube config, this might destroy any existing settings!
[NOTE]
--
To apply the playbook you may need to install additional packages:
* https://helm.sh/docs/intro/install/[helm]
* https://github.com/databus23/helm-diff?tab=readme-ov-file#install[helm-diff]
* python3-kubernetes (Debian/Ubuntu)
--
// end::setup[]

View File

@@ -58,7 +58,7 @@ module "k8s" {
} }
resource "local_file" "ansible_inventory" { resource "local_file" "ansible_inventory" {
filename = "${path.module}/../k3s/inventory.ini" filename = "${path.module}/inventory.ini"
content = templatefile("./inventory.ini.tftpl", { content = templatefile("./inventory.ini.tftpl", {
server_ips = module.k8s.server_ips_v4, server_ips = module.k8s.server_ips_v4,
agent_ips = module.k8s.agent_ips_v4, agent_ips = module.k8s.agent_ips_v4,