-
Notifications
You must be signed in to change notification settings - Fork 37
Use bootstrap tokens provisioned by ansible for K3s instead of persistent tokens in cloud-init metadata #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0b69d4b
now uses bootstrap tokens instead of cloud-init metadata
wtripp180901 bfe9caf
bumped token timeout
wtripp180901 28b4205
fixed assuming default route
wtripp180901 aeeca4c
bump image
wtripp180901 e4ff694
refactored to separate agent and server runtimes + fixes + review com…
wtripp180901 178f853
removed inventory_secrets from ci
wtripp180901 7bb9920
Merge branch 'main' into feat/k3s-bootstrap
wtripp180901 3cc46b8
image bump
wtripp180901 5e9541e
testing moving agent runtime after nfs
wtripp180901 3508ebd
changed k3s conditionals to host patterns + server tweaks
wtripp180901 bd71974
comment suggestions
wtripp180901 19da5d5
k3s agent no longer uses task vars
wtripp180901 33b84bc
added comment for moving k3s
wtripp180901 051ca04
Explicitly settings empty string default for bootstrap token
wtripp180901 5fb1d33
secure pems for agent environment file
wtripp180901 1b83232
Merge branch 'main' into feat/k3s-bootstrap
wtripp180901 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- name: Check if k3s agents are already connected | ||
service_facts: | ||
register: services_state | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: Initialise and authenticate k3s server and agents | ||
vars: | ||
k3s_server_name: "{{ hostvars[groups['k3s_server'].0].ansible_host }}" | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
access_ip: "{{ ansible_host }}" | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
services_states: > # getting list of all unique agent service states | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
groups['k3s_agent'] | ||
| map('extract', hostvars, ['services', 'k3s-agent.service', 'state']) | ||
| unique | ||
when: not (services_state | length == 1 and services_state[0] == 'running') | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
block: | ||
- name: Initialise server and generate bootstrap tokens | ||
when: inventory_hostname in groups['k3s_server'] | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
block: | ||
- name: Template k3s env file | ||
ansible.builtin.template: | ||
dest: /etc/systemd/system/k3s.service.env | ||
src: k3s.service.env.j2 | ||
|
||
- name: Start k3s server | ||
ansible.builtin.systemd: | ||
name: k3s | ||
daemon_reload: true | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
state: started | ||
enabled: true | ||
|
||
- name: Generate bootstrap token | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
no_log: true | ||
shell: | ||
cmd: "k3s token create --ttl {{ k3s_bootstrap_token_expiry }}" | ||
register: _token_output | ||
|
||
- name: Initialise agents | ||
when: inventory_hostname in groups['k3s_agent'] | ||
block: | ||
- name: Template k3s agent env file | ||
ansible.builtin.template: | ||
dest: /etc/systemd/system/k3s-agent.service.env | ||
src: k3s-agent.service.env.j2 | ||
|
||
- name: Ensure password directory exists | ||
ansible.builtin.file: | ||
path: "/etc/rancher/node" | ||
state: directory | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: Write node password | ||
ansible.builtin.copy: | ||
dest: /etc/rancher/node/password | ||
content: "{{ vault_k3s_node_password }}" | ||
owner: root | ||
group: root | ||
mode: 640 # normal k3s install is 644 but that doesn't feel right | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: Start k3s agent | ||
ansible.builtin.systemd: | ||
name: k3s-agent | ||
daemon_reload: true | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
state: started | ||
enabled: true | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
K3S_NODE_IP={{ access_ip }} | ||
K3S_TOKEN={{ hostvars[groups['control'] | first]._token_output.stdout }} | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
K3S_URL=https://{{ k3s_server_name }}:6443 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
K3S_NODE_IP={{ access_ip }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
ansible/roles/passwords/templates/k3s-token.auto.tfvars.json.j2
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wtripp180901 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.