Move infra-setup and k3s-setup into dedicated directories

This changes makes it easier to differentiate and understand the
different parts of the kubernetes setup. On one hand we have the bare
infrastructure (servers, network, etc), on the other hand we have the
software (k3s in this case).

In the future we'll have a few more parts, like the minimal
configuration of the kubernetes cluster, e.g. with a cert-manager. This
is easier to manage with helm or terraform than with ansible. Therefore
it makes even more sense to split the responsibilities into dedicated
directories.
This commit is contained in:
2025-09-15 12:45:50 +02:00
parent dfcdc9797a
commit d96523a071
24 changed files with 89 additions and 59 deletions

26
k3s/README.adoc Normal file
View File

@@ -0,0 +1,26 @@
= k3s
:icons: font
This project is responsible for setting up a k3s installation.
== 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 k3s.orchestration.site -i inventory.ini # <2>
ansible-playbook download-kube-config.yml -i inventory.ini # <3>
ansible-playbook k3s.orchestration.upgrade -i inventory.ini # <4>
----
<1> Install required ansible collections to create a k3s-cluster (can be omitted in subsequent runs)
<2> Install k3s
<3> Download the kube-config to .kube/config
<4> Update k3s when necessary
[IMPORTANT]
Step 3 will override any existing kube config this might destroy any existing settings!
// end::setup[]

View File

@@ -0,0 +1,15 @@
- hosts: server[0]
tasks:
- name: Download kube-config
fetch:
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ lookup('env', 'HOME') }}/.kube/config"
flat: true
- hosts: localhost
tasks:
- name: Use correct ip-address for k8s-cluster
lineinfile:
path: "{{ lookup('env', 'HOME') }}/.kube/config"
regexp: '^(\s*server: https://).*(:\d+)$'
line: \g<1>{{ hostvars[groups['server'][0]]['api_endpoint'] }}\g<2>
backrefs: yes

View File

@@ -0,0 +1,2 @@
ansible_ssh_common_args: '-o StrictHostKeyChecking=accept-new -o ProxyCommand="ssh -p 22 -W %h:%p -q root@188.245.199.197"'
k3s_version: v1.31.6+k3s1

View File

@@ -0,0 +1,3 @@
ansible_user: root
api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"

View File

@@ -0,0 +1,2 @@
ansible_ssh_common_args: '-o StrictHostKeyChecking=accept-new'
k3s_version: v1.31.6+k3s1

4
k3s/requirements.yml Normal file
View File

@@ -0,0 +1,4 @@
collections:
- name: https://github.com/k3s-io/k3s-ansible.git
type: git
version: 1.0.1