fix: bootstrap k3s HA on private network with dual SANs
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
k3s_version: latest
|
||||
k3s_token: ""
|
||||
k3s_node_ip: ""
|
||||
k3s_primary_public_ip: ""
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
environment:
|
||||
INSTALL_K3S_VERSION: "{{ k3s_version if k3s_version != 'latest' else '' }}"
|
||||
K3S_TOKEN: "{{ k3s_token }}"
|
||||
command: /tmp/install-k3s.sh server --cluster-init --advertise-address={{ k3s_primary_ip }} --node-ip={{ k3s_node_ip }} --tls-san={{ k3s_primary_ip }}
|
||||
command: /tmp/install-k3s.sh server --cluster-init --advertise-address={{ k3s_primary_ip }} --node-ip={{ k3s_node_ip }} --tls-san={{ k3s_primary_ip }} --tls-san={{ k3s_primary_public_ip }}
|
||||
when:
|
||||
- k3s_install_needed
|
||||
- k3s_primary | default(false)
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
vars:
|
||||
k3s_primary: true
|
||||
k3s_token: "{{ lookup('password', '/dev/null length=32 chars=ascii_letters,digits') }}"
|
||||
k3s_primary_ip: "{{ ansible_default_ipv4.address }}"
|
||||
k3s_primary_private_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
k3s_primary_public_ip: "{{ ansible_default_ipv4.address }}"
|
||||
k3s_primary_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
k3s_node_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
|
||||
roles:
|
||||
@@ -38,7 +40,8 @@
|
||||
- name: Set join token fact
|
||||
set_fact:
|
||||
k3s_token: "{{ node_token.stdout }}"
|
||||
k3s_primary_ip: "{{ ansible_default_ipv4.address }}"
|
||||
k3s_primary_private_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
k3s_primary_public_ip: "{{ ansible_default_ipv4.address }}"
|
||||
|
||||
- name: Fetch kubeconfig
|
||||
fetch:
|
||||
@@ -53,7 +56,8 @@
|
||||
vars:
|
||||
k3s_primary: false
|
||||
k3s_token: "{{ hostvars[groups['control_plane'][0]]['k3s_token'] }}"
|
||||
k3s_primary_ip: "{{ hostvars[groups['control_plane'][0]]['k3s_primary_ip'] }}"
|
||||
k3s_primary_ip: "{{ hostvars[groups['control_plane'][0]]['k3s_primary_private_ip'] }}"
|
||||
k3s_primary_public_ip: "{{ hostvars[groups['control_plane'][0]]['k3s_primary_public_ip'] }}"
|
||||
k3s_node_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
|
||||
roles:
|
||||
@@ -65,7 +69,7 @@
|
||||
|
||||
vars:
|
||||
k3s_token: "{{ hostvars[groups['control_plane'][0]]['k3s_token'] }}"
|
||||
k3s_server_url: "https://{{ hostvars[groups['control_plane'][0]]['k3s_primary_ip'] }}:6443"
|
||||
k3s_server_url: "https://{{ hostvars[groups['control_plane'][0]]['k3s_primary_private_ip'] }}:6443"
|
||||
k3s_node_ip: "{{ ansible_all_ipv4_addresses | select('match', '^10\\.') | first }}"
|
||||
|
||||
roles:
|
||||
@@ -84,7 +88,7 @@
|
||||
tasks:
|
||||
- name: Update kubeconfig server address
|
||||
command: |
|
||||
sed -i 's/127.0.0.1/{{ hostvars[groups["control_plane"][0]]["ansible_default_ipv4"]["address"] }}/g' ../outputs/kubeconfig
|
||||
sed -i 's/127.0.0.1/{{ hostvars[groups["control_plane"][0]]["k3s_primary_public_ip"] }}/g' ../outputs/kubeconfig
|
||||
changed_when: true
|
||||
|
||||
- name: Display success message
|
||||
|
||||
Reference in New Issue
Block a user