-
Notifications
You must be signed in to change notification settings - Fork 34
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 all 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
|
||
- name: Template k3s agent env file | ||
when: k3s_bootstrap_token != '' | ||
ansible.builtin.template: | ||
dest: /etc/systemd/system/k3s-agent.service.env | ||
src: k3s-agent.service.env.j2 | ||
owner: root | ||
group: root | ||
mode: 0640 | ||
register: _k3s_agent_token_result | ||
|
||
- name: Ensure password directory exists | ||
ansible.builtin.file: | ||
path: "/etc/rancher/node" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0640 | ||
|
||
- name: Write node password | ||
ansible.builtin.copy: | ||
dest: /etc/rancher/node/password | ||
content: "{{ vault_k3s_node_password }}" | ||
owner: root | ||
group: root | ||
mode: 0640 # normal k3s install is 644 but that doesn't feel right | ||
|
||
- name: Start/restart k3s agent | ||
when: _k3s_agent_token_result.changed | ||
ansible.builtin.systemd: | ||
name: k3s-agent | ||
daemon_reload: true | ||
state: restarted | ||
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
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,34 @@ | ||
--- | ||
|
||
- name: Template k3s env file | ||
ansible.builtin.template: | ||
dest: /etc/systemd/system/k3s.service.env | ||
src: k3s.service.env.j2 | ||
register: _k3s_env_file_status | ||
|
||
- name: Start k3s server | ||
ansible.builtin.systemd: | ||
name: k3s | ||
daemon_reload: "{{ _k3s_env_file_status.changed }}" | ||
state: started | ||
enabled: true | ||
|
||
# Possible race here as there is a delay between agents disconnecting and being registered as down, probably won't be hit in general use though | ||
- name: Check which k3s agents are connected | ||
ansible.builtin.shell: | ||
cmd: kubectl get nodes --no-headers | grep -w Ready | ||
register: _k3s_connected_nodes | ||
retries: 6 # task may fail if server is not ready yet | ||
delay: 10 | ||
until: not _k3s_connected_nodes.failed | ||
|
||
- name: Generate new bootstrap token if not all agents are connected | ||
no_log: true | ||
when: _k3s_connected_nodes.stdout_lines | length != groups['k3s'] | length | ||
shell: | ||
cmd: "k3s token create --ttl {{ k3s_bootstrap_token_expiry }}" | ||
register: _k3s_token_output | ||
|
||
- name: Set bootstrap token as fact | ||
set_fact: | ||
k3s_bootstrap_token: "{{ _k3s_token_output.stdout }}" |
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={{ ansible_host }} | ||
K3S_TOKEN={{ k3s_bootstrap_token }} | ||
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={{ ansible_host }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"cluster_image": { | ||
"RL8": "openhpc-RL8-250211-1540-a0b4a57e", | ||
"RL9": "openhpc-RL9-250211-1540-a0b4a57e" | ||
"RL8": "openhpc-RL8-250221-0904-e4ff694e", | ||
"RL9": "openhpc-RL9-250221-0904-e4ff694e" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
k3s_bootstrap_token: "{{ hostvars[groups['k3s_server'] | first].k3s_bootstrap_token | default('') }}" |
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
8 changes: 0 additions & 8 deletions
8
environments/skeleton/{{cookiecutter.environment}}/tofu/data.tf
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
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.