1.6 KiB
1.6 KiB
K3s Loadbalancer Ansible Role
This Ansible role configures a load balancer for a K3s cluster using Nginx.
Role Variables
k3s_loadbalancer_nginx_config_path: The path to the Nginx configuration file. Defaults to/etc/nginx/nginx.conf.domain: The domain name to use for the load balancer. Defaults to{{ internal_domain }}.k3s.loadbalancer.default_port: The default port for the K3s API server. Defaults to6443.k3s_server_ips: A list of IP addresses for the K3s server nodes. This variable is not defined in the role, so you must provide it.netcup_api_key: Your Netcup API key.netcup_api_password: Your Netcup API password.netcup_customer_id: Your Netcup customer ID.
Tasks
The role performs the following tasks:
- Installation:
- Updates the
aptcache. - Installs
qemu-guest-agent. - Installs
nginx-full.
- Updates the
- Configuration:
- Templates the Nginx configuration file with dynamic upstreams for the K3s servers.
- Enables and starts the Nginx service.
- DNS Setup:
- Sets up a DNS A record for the load balancer using the
community.general.netcup_dnsmodule.
- Sets up a DNS A record for the load balancer using the
Handlers
Restart nginx: Restarts the Nginx service when the configuration file is changed.
Example Usage
Here is an example of how to use this role in a playbook:
- hosts: k3s_loadbalancer
roles:
- role: k3s_loadbalancer
vars:
k3s_server_ips:
- 192.168.1.10
- 192.168.1.11
- 192.168.1.12
netcup_api_key: "your_api_key"
netcup_api_password: "your_api_password"
netcup_customer_id: "your_customer_id"
internal_domain: "example.com"