diff --git a/infra/.terraform.lock.hcl b/.terraform.lock.hcl similarity index 100% rename from infra/.terraform.lock.hcl rename to .terraform.lock.hcl diff --git a/README.adoc b/README.adoc index 33528de..4071512 100644 --- a/README.adoc +++ b/README.adoc @@ -11,11 +11,9 @@ The setup is split into 2 dedicated parts: [source,bash] ---- -cd infra terraform init terraform apply sleep 300 # Wait 5 minutes since the machines start _slow_ sometimes -cd ../k3s ansible-galaxy install -r requirements.yml ansible-playbook site.yml ---- @@ -27,26 +25,82 @@ ansible-playbook site.yml == Setup -The project is split into different directories, 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. +The project is split into different steps, each responsible for another task. -=== 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] -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. -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 @@ -68,7 +122,7 @@ Instead proceed as the following: == Responsibilities -`infra/`:: +terraform:: * Creation of network for the kubernetes-cluster ** A public subnet exposed to the internet for the kubernetes-servers ** 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 DNS-records in Hetzer Cloud -`k3s/`:: +ansible:: * Setup SSH-connections * Setting up routing on all servers * Installing k3s * Keep the software up-to-date * Add foundational services to the cluster - - diff --git a/k3s/ansible.cfg b/ansible.cfg similarity index 100% rename from k3s/ansible.cfg rename to ansible.cfg diff --git a/k3s/config.yml b/config.yml similarity index 100% rename from k3s/config.yml rename to config.yml diff --git a/infra/README.adoc b/infra/README.adoc deleted file mode 100644 index 7142d81..0000000 --- a/infra/README.adoc +++ /dev/null @@ -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[] diff --git a/infra/inventory.ini.tftpl b/inventory.ini.tftpl similarity index 100% rename from infra/inventory.ini.tftpl rename to inventory.ini.tftpl diff --git a/k3s/README.adoc b/k3s/README.adoc deleted file mode 100644 index 4836d90..0000000 --- a/k3s/README.adoc +++ /dev/null @@ -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[] diff --git a/infra/main.tf b/main.tf similarity index 99% rename from infra/main.tf rename to main.tf index 30c7f3b..a9c2280 100644 --- a/infra/main.tf +++ b/main.tf @@ -58,7 +58,7 @@ module "k8s" { } resource "local_file" "ansible_inventory" { - filename = "${path.module}/../k3s/inventory.ini" + filename = "${path.module}/inventory.ini" content = templatefile("./inventory.ini.tftpl", { server_ips = module.k8s.server_ips_v4, agent_ips = module.k8s.agent_ips_v4, diff --git a/infra/modules/hetzner/dns/main.tf b/modules/hetzner/dns/main.tf similarity index 100% rename from infra/modules/hetzner/dns/main.tf rename to modules/hetzner/dns/main.tf diff --git a/infra/modules/hetzner/dns/outputs.tf b/modules/hetzner/dns/outputs.tf similarity index 100% rename from infra/modules/hetzner/dns/outputs.tf rename to modules/hetzner/dns/outputs.tf diff --git a/infra/modules/hetzner/dns/variables.tf b/modules/hetzner/dns/variables.tf similarity index 100% rename from infra/modules/hetzner/dns/variables.tf rename to modules/hetzner/dns/variables.tf diff --git a/infra/modules/hetzner/dns/versions.tf b/modules/hetzner/dns/versions.tf similarity index 100% rename from infra/modules/hetzner/dns/versions.tf rename to modules/hetzner/dns/versions.tf diff --git a/infra/modules/hetzner/kubernetes/main.tf b/modules/hetzner/kubernetes/main.tf similarity index 100% rename from infra/modules/hetzner/kubernetes/main.tf rename to modules/hetzner/kubernetes/main.tf diff --git a/infra/modules/hetzner/kubernetes/outputs.tf b/modules/hetzner/kubernetes/outputs.tf similarity index 100% rename from infra/modules/hetzner/kubernetes/outputs.tf rename to modules/hetzner/kubernetes/outputs.tf diff --git a/infra/modules/hetzner/kubernetes/variables.tf b/modules/hetzner/kubernetes/variables.tf similarity index 100% rename from infra/modules/hetzner/kubernetes/variables.tf rename to modules/hetzner/kubernetes/variables.tf diff --git a/infra/modules/hetzner/kubernetes/versions.tf b/modules/hetzner/kubernetes/versions.tf similarity index 100% rename from infra/modules/hetzner/kubernetes/versions.tf rename to modules/hetzner/kubernetes/versions.tf diff --git a/k3s/requirements.yml b/requirements.yml similarity index 100% rename from k3s/requirements.yml rename to requirements.yml diff --git a/k3s/roles/agent-setup/defaults/main.yml b/roles/agent-setup/defaults/main.yml similarity index 100% rename from k3s/roles/agent-setup/defaults/main.yml rename to roles/agent-setup/defaults/main.yml diff --git a/k3s/roles/agent-setup/handlers/main.yml b/roles/agent-setup/handlers/main.yml similarity index 100% rename from k3s/roles/agent-setup/handlers/main.yml rename to roles/agent-setup/handlers/main.yml diff --git a/k3s/roles/agent-setup/tasks/main.yml b/roles/agent-setup/tasks/main.yml similarity index 100% rename from k3s/roles/agent-setup/tasks/main.yml rename to roles/agent-setup/tasks/main.yml diff --git a/k3s/roles/agent-setup/templates/nic.network.j2 b/roles/agent-setup/templates/nic.network.j2 similarity index 100% rename from k3s/roles/agent-setup/templates/nic.network.j2 rename to roles/agent-setup/templates/nic.network.j2 diff --git a/k3s/roles/k8s-setup/defaults/main.yml b/roles/k8s-setup/defaults/main.yml similarity index 100% rename from k3s/roles/k8s-setup/defaults/main.yml rename to roles/k8s-setup/defaults/main.yml diff --git a/k3s/roles/k8s-setup/tasks/main.yml b/roles/k8s-setup/tasks/main.yml similarity index 100% rename from k3s/roles/k8s-setup/tasks/main.yml rename to roles/k8s-setup/tasks/main.yml diff --git a/k3s/roles/kube-config/tasks/main.yml b/roles/kube-config/tasks/main.yml similarity index 100% rename from k3s/roles/kube-config/tasks/main.yml rename to roles/kube-config/tasks/main.yml diff --git a/k3s/roles/server-setup/defaults/main.yml b/roles/server-setup/defaults/main.yml similarity index 100% rename from k3s/roles/server-setup/defaults/main.yml rename to roles/server-setup/defaults/main.yml diff --git a/k3s/roles/server-setup/handlers/main.yml b/roles/server-setup/handlers/main.yml similarity index 100% rename from k3s/roles/server-setup/handlers/main.yml rename to roles/server-setup/handlers/main.yml diff --git a/k3s/roles/server-setup/tasks/main.yml b/roles/server-setup/tasks/main.yml similarity index 100% rename from k3s/roles/server-setup/tasks/main.yml rename to roles/server-setup/tasks/main.yml diff --git a/k3s/roles/server-setup/templates/ip-masquerade.sh.j2 b/roles/server-setup/templates/ip-masquerade.sh.j2 similarity index 100% rename from k3s/roles/server-setup/templates/ip-masquerade.sh.j2 rename to roles/server-setup/templates/ip-masquerade.sh.j2 diff --git a/k3s/site.yml b/site.yml similarity index 100% rename from k3s/site.yml rename to site.yml diff --git a/infra/variables.tf b/variables.tf similarity index 100% rename from infra/variables.tf rename to variables.tf diff --git a/k3s/vault.yml b/vault.yml similarity index 100% rename from k3s/vault.yml rename to vault.yml diff --git a/infra/versions.tf b/versions.tf similarity index 100% rename from infra/versions.tf rename to versions.tf