Finished lb and db
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
6
roles/loadbalancer/handlers/main.yml
Normal file
6
roles/loadbalancer/handlers/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Restart nginx
|
||||
systemd:
|
||||
name: nginx
|
||||
state: restarted
|
||||
become: true
|
||||
20
roles/loadbalancer/tasks/configuration.yml
Normal file
20
roles/loadbalancer/tasks/configuration.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- name: Template the nginx config file with dynamic upstreams
|
||||
template:
|
||||
src: templates/nginx.conf.j2
|
||||
dest: "{{ nginx_config_path }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
become: true
|
||||
notify:
|
||||
- Restart nginx
|
||||
vars:
|
||||
k3s_server_ips: "{{ k3s.server.ips }}"
|
||||
|
||||
- name: Enable nginx
|
||||
systemd:
|
||||
name: nginx
|
||||
daemon_reload: true
|
||||
enabled: true
|
||||
become: true
|
||||
12
roles/loadbalancer/tasks/installation.yml
Normal file
12
roles/loadbalancer/tasks/installation.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
become: true
|
||||
|
||||
- name: Install Nginx
|
||||
apt:
|
||||
name:
|
||||
- nginx-full
|
||||
state: present
|
||||
become: true
|
||||
3
roles/loadbalancer/tasks/main.yml
Normal file
3
roles/loadbalancer/tasks/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- include_tasks: installation.yml
|
||||
- include_tasks: configuration.yml
|
||||
16
roles/loadbalancer/templates/nginx.conf.j2
Normal file
16
roles/loadbalancer/templates/nginx.conf.j2
Normal file
@@ -0,0 +1,16 @@
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {}
|
||||
|
||||
stream {
|
||||
upstream k3s_servers {
|
||||
{% for ip in k3s_server_ips %}
|
||||
server {{ ip }}:6443;
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 6443;
|
||||
proxy_pass k3s_servers;
|
||||
}
|
||||
}
|
||||
1
roles/loadbalancer/vars/main.yml
Normal file
1
roles/loadbalancer/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
nginx_config_path: "/etc/nginx/nginx.conf"
|
||||
Reference in New Issue
Block a user