Verified Commit 7bd13e77 authored by Hugo's avatar Hugo
Browse files

k0sctl + ansible wrap everything

parent 109f2259
......@@ -3,4 +3,5 @@ terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.d
values.auto.tfvars
inventory.yaml
\ No newline at end of file
k0sctl.yaml
kubeconfig
\ No newline at end of file
- name: upgrades nodes
- name: provision infrastructure
hosts: localhost
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
tasks:
- import_tasks: "tasks/provision.yaml"
- name: setup nodes
hosts: all
remote_user: root
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
handlers:
- name: reboot
reboot: {}
tasks:
- name: update packages
ansible.builtin.apt:
update_cache: yes
upgrade: safe
notify: reboot
- name: update kernel
ansible.builtin.apt:
default_release: buster-backports
state: latest
name:
- linux-headers-amd64
- linux-image-amd64
notify: reboot
- import_tasks: "tasks/upgrade.yaml"
- import_tasks: "tasks/setup_worker.yaml"
when: '"worker" in group_names'
- name: prepare workers
hosts: workers
remote_user: root
handlers:
- name: reboot
reboot: {}
- name: deploy k8s
hosts: localhost
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
tasks:
- name: install wireguard
ansible.builtin.package:
name: wireguard
- name: copy modules.conf
ansible.builtin.copy:
src: modules.conf
dest: /etc/modules-load.d/modules.conf
notify: reboot
- import_tasks: "tasks/deploy.yaml"
- name: genreate k0sctl.yaml
template:
src: k0sctl.yaml.j2
dest: k0sctl.yaml
- name: run k0sctl
shell: k0sctl apply
- name: run terraform
community.general.terraform:
project_path: "terraform/"
state: present
register: tf
- name: register controller hosts
add_host:
name: "{{ item }}"
groups: "controller"
loop: "{{ tf.outputs.controller_ipv4.value }}"
- name: register worker hosts
add_host:
name: "{{ item }}"
groups: "worker"
loop: "{{ tf.outputs.worker_ipv4.value }}"
- name: register variables
set_fact:
control_plane_ipv4: "{{ tf.outputs.control_plane_ipv4.value }}"
ingress_ipv4: "{{ tf.outputs.ingress_ipv4.value }}"
- name: install wireguard
ansible.builtin.package:
name: wireguard
- name: copy modules.conf
ansible.builtin.copy:
src: modules.conf
dest: /etc/modules-load.d/modules.conf
notify: reboot
- name: update packages
ansible.builtin.apt:
update_cache: yes
upgrade: safe
notify: reboot
- name: update kernel
ansible.builtin.apt:
default_release: buster-backports
state: latest
name:
- linux-headers-amd64
- linux-image-amd64
notify: reboot
apiVersion: k0sctl.k0sproject.io/v1beta1
kind: Cluster
metadata:
name: k0s-cluster
spec:
hosts:
{%for ip in groups["controller"] %}
- ssh:
address: {{ip}}
port: 22
role: controller
{%endfor%}
{%for ip in groups["worker"] %}
- ssh:
address: {{ip}}
port: 22
role: worker
{%endfor%}
k0s:
version: 0.13.1
config:
apiVersion: k0s.k0sproject.io/v1beta1
kind: Cluster
metadata:
name: {{cluster_name}}
spec:
api:
externalAddress: {{control_plane_ipv4}}
sans:
- {{control_plane_ipv4}}
network:
provider: calico
calico:
mtu: 1440
wireguard: true
resource "local_file" "ansible_inventory" {
content = yamlencode({
all = {
children = {
controllers = {
hosts = { for ip in hcloud_server.controller.*.ipv4_address : ip => {} }
}
workers = {
hosts = { for ip in hcloud_server.worker.*.ipv4_address : ip => {} }
}
}
vars = {
control_plane_lb = hcloud_load_balancer.control_plane_load_balancer.ipv4
ingress_lb = hcloud_load_balancer.ingress_load_balancer.ipv4
}
}
})
filename = "${path.module}/../inventory.yaml"
}
cluster_name = "ada-lovelace"
controller_count = 3
controller_type = "ccx12"
worker_count = 0
worker_type = "ccx22"
volume_count = 0
control_plane_lb_type = "lb11"
ingress_lb_type = "lb21"
\ No newline at end of file
cluster_name = "ada-lovelace-testing"
controller_count = 3
controller_type = "cx11"
worker_count = 0
worker_type = "cx11"
volume_count = 2
control_plane_lb_type = "lb11"
ingress_lb_type = "lb11"
\ No newline at end of file
cluster_name: ada-lovelace
controller_count: 3
controller_type: cx11
worker_count: 0
worker_type: cx11
volume_count: 2
control_plane_lb_type: lb11
ingress_lb_type: lb11
controller_type: ccx12
worker_count: 0
volume_count: 0
control_plane_lb_type: lb11
ingress_lb_type: lb21
cluster_name: ada-lovelace-testing
controller_count: 3
controller_type: cx11
worker_count: 0
worker_type: cx11
volume_count: 2
control_plane_lb_type: lb11
ingress_lb_type: lb11
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment