-
Notifications
You must be signed in to change notification settings - Fork 35
Install k3s cluster with ansible init #441
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 68 commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
ab65245
added k3s installation to bootstrap
wtripp180901 321fdb4
added k3ds token to terraform
wtripp180901 915c4dd
added role to install playbooks for ansible-init
wtripp180901 824e117
Refactored so that agent or server is determined by metadata
wtripp180901 b49b22c
Added (very hacky) k3s token generation
wtripp180901 99c0028
Added k9s role
wtripp180901 68feb76
Moved k3s install to after network setup
wtripp180901 90c7a78
Added seperate k3s group
wtripp180901 cbcf762
Added helm
wtripp180901 370b188
Fixed ansible-init sentinel being created in packer build
wtripp180901 df02a66
Moved helm install
wtripp180901 327c645
Added kube roles to gitignore
wtripp180901 ce82f59
moved installs to usr/bin
wtripp180901 250b4c7
remove local DNS as a dependency for k3s
sjpb 2f26fa1
agent/server config now based on if server name defined
wtripp180901 a8d4e17
k3s token now templated into terraform vars
wtripp180901 510115f
Name and label suggestions from review
wtripp180901 56c0d67
Refactor + group changes
wtripp180901 6d6bd2d
Refactored k9s install
wtripp180901 2b4f1f6
Removed server from control terraform and changed ansible-init file t…
wtripp180901 132e49e
Fixed merge conflicts
wtripp180901 1952797
more merge conflicts
wtripp180901 c642866
name update
wtripp180901 0975257
Updated .stackhpc env with k3s token
wtripp180901 22a4e6d
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 79383fe
added k3s readme
wtripp180901 fa955dd
bump images
wtripp180901 a8569da
Disabled traefik for non-server nodes
wtripp180901 8250483
Revert images for clean build
wtripp180901 46401bf
bump images
wtripp180901 15d3514
Apply suggestions from code review
wtripp180901 bc37064
Code review tweaks
wtripp180901 2ab8e52
Moved k3s token to be with rest of appliance secrets
wtripp180901 26a0f89
bump images
wtripp180901 8f0923c
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 cfb5514
updated caas for k3s
wtripp180901 8b7941d
fixed k3s install overwriting ansible-init changes
wtripp180901 5dfec0d
bump images
wtripp180901 1035460
removed k3s ingress
wtripp180901 7eb4821
added k3s docs
wtripp180901 9f00f11
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 2861edb
merge conflict fixes
wtripp180901 e6dd871
bump images
wtripp180901 7b3b115
Fixed node passwords changing on reimage
wtripp180901 d95037b
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 a0d947b
fixed missing directory
wtripp180901 1d1e777
typo
wtripp180901 3be011c
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 440f20c
moved CI image definition
wtripp180901 d69033a
bump images
wtripp180901 3d2e2cd
added cuda image for ci
wtripp180901 2efa193
typo
wtripp180901 ba1d212
corrected docs
wtripp180901 904df8a
k3s install now air-gapped
wtripp180901 a67ffd3
bump images
wtripp180901 04db97d
merge from main
wtripp180901 7008500
ci images bumped up to date with main
wtripp180901 79433b8
fixed k3s token idempotency issues
wtripp180901 bba95bb
Comment + doc changes from review
wtripp180901 3f599c6
play rename
wtripp180901 a6f0137
removed sentinel cleanup
wtripp180901 03fe568
k3s role refactor
wtripp180901 d96eddd
updated k3s docs
wtripp180901 21b7081
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 4f45701
merge conflicts
wtripp180901 bf47035
bumped images up to date with main
wtripp180901 ad84877
fixed k3s token generation
wtripp180901 54910a1
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 8ab12e9
Passwords role now reads variables into top level vars
wtripp180901 bf16547
moved k3s plays to install script
wtripp180901 5e3927b
reverted caas changes
wtripp180901 98f5b79
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 20a8a62
re-enabled caas access_network
wtripp180901 5b43d0e
bump images
wtripp180901 4538c6d
merge
wtripp180901 100632f
bump
wtripp180901 0c17410
k9s tags and variable renames
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
|
||
- name: Cleanup /tmp | ||
command : rm -rf /tmp/* | ||
|
||
- name: Get package facts | ||
package_facts: | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
k3s | ||
===== | ||
|
||
Installs k3s agent and server services on nodes and an ansible-init playbook to activate them. The service that each node will activate on init is determined by OpenStack metadata. Also includes Helm install. Currently only supports a single k3s-server | ||
(i.e one control node). Install based on the [official k3s ansible role](https://github.com/k3s-io/k3s-ansible). | ||
|
||
|
||
Requirements | ||
------------ | ||
|
||
`azimuth_cloud.image_utils.linux_ansible_init` must have been run previously on targeted nodes during image build. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
- `k3s_version`: Optional str. K3s version to install, see [official releases](https://github.com/k3s-io/k3s/releases/). |
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,5 @@ | ||
# Warning: changes to these variables won't be reflected in the cluster/image if k3s is already installed | ||
k3s_version: "v1.31.0+k3s1" | ||
k3s_selinux_release: v1.6.latest.1 | ||
k3s_selinux_rpm_version: 1.6-1 | ||
k3s_helm_version: v3.11.0 |
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,36 @@ | ||
- hosts: localhost | ||
become: true | ||
vars: | ||
os_metadata: "{{ lookup('url', 'http://169.254.169.254/openstack/latest/meta_data.json') | from_json }}" | ||
k3s_token: "{{ os_metadata.meta.k3s_token }}" | ||
k3s_server_name: "{{ os_metadata.meta.k3s_server }}" | ||
service_name: "{{ 'k3s-agent' if k3s_server_name is defined else 'k3s' }}" | ||
tasks: | ||
- name: Ensure password directory exists | ||
ansible.builtin.file: | ||
path: "/etc/rancher/node" | ||
state: directory | ||
|
||
- name: Set agent node password as token # uses token to keep password consistent between reimages | ||
ansible.builtin.copy: | ||
dest: /etc/rancher/node/password | ||
content: "{{ k3s_token }}" | ||
|
||
- name: Add the token for joining the cluster to the environment | ||
no_log: true # avoid logging the server token | ||
ansible.builtin.lineinfile: | ||
path: "/etc/systemd/system/{{ service_name }}.service.env" | ||
line: "K3S_TOKEN={{ k3s_token }}" | ||
|
||
- name: Add server url to agents | ||
ansible.builtin.lineinfile: | ||
path: "/etc/systemd/system/{{ service_name }}.service.env" | ||
line: "K3S_URL=https://{{ k3s_server_name }}:6443" | ||
when: k3s_server_name is defined | ||
|
||
- name: Start k3s service | ||
ansible.builtin.systemd: | ||
name: "{{ service_name }}" | ||
daemon_reload: true | ||
state: started | ||
enabled: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
|
||
- name: Check for existing k3s installation | ||
stat: | ||
path: /var/lib/rancher/k3s | ||
register: stat_result | ||
|
||
- name: Perform air-gapped installation of k3s | ||
# Using air-gapped install so containers are pre-installed to avoid rate-limiting from registries on cluster startup | ||
when: not stat_result.stat.exists | ||
block: | ||
|
||
- name: Download k3s binary | ||
ansible.builtin.get_url: | ||
url: "https://github.com/k3s-io/k3s/releases/download/{{ k3s_version | urlencode }}/k3s" | ||
dest: /usr/bin/k3s | ||
owner: root | ||
group: root | ||
mode: "0755" | ||
|
||
- name: Install k3s SELinux policy package | ||
yum: | ||
name: "https://github.com/k3s-io/k3s-selinux/releases/download/{{ k3s_selinux_release }}/k3s-selinux-{{ k3s_selinux_rpm_version }}.el{{ ansible_distribution_major_version }}.noarch.rpm" | ||
disable_gpg_check: true | ||
|
||
- name: Create image directory | ||
ansible.builtin.file: | ||
path: "/var/lib/rancher/k3s/agent/images" | ||
state: directory | ||
|
||
- name: Install k3s' internal images | ||
ansible.builtin.get_url: | ||
url: "https://github.com/k3s-io/k3s/releases/download/{{ k3s_version | urlencode }}/k3s-airgap-images-amd64.tar.zst" | ||
dest: /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst | ||
|
||
- name: Download k3s install script | ||
ansible.builtin.get_url: | ||
url: https://get.k3s.io/ | ||
timeout: 120 | ||
dest: /usr/bin/k3s-install.sh | ||
owner: root | ||
group: root | ||
mode: "0755" | ||
|
||
- name: Install k3s | ||
ansible.builtin.shell: | ||
cmd: /usr/bin/k3s-install.sh | ||
environment: | ||
INSTALL_K3S_VERSION: "{{ k3s_version }}" | ||
INSTALL_K3S_EXEC: "{{ item }}" | ||
INSTALL_K3S_SKIP_START: "true" | ||
INSTALL_K3S_SKIP_ENABLE: "true" | ||
INSTALL_K3S_BIN_DIR: "/usr/bin" | ||
INSTALL_K3S_SKIP_DOWNLOAD: "true" | ||
changed_when: true | ||
loop: | ||
- server --disable=traefik | ||
- agent | ||
|
||
- name: Install helm | ||
unarchive: | ||
src: "https://get.helm.sh/helm-{{ k3s_helm_version }}-linux-amd64.tar.gz" | ||
dest: /usr/bin | ||
extra_opts: "--strip-components=1" | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
remote_src: true | ||
|
||
- name: Add k3s kubeconfig as environment variable | ||
ansible.builtin.lineinfile: | ||
path: /etc/environment | ||
line: "KUBECONFIG=/etc/rancher/k3s/k3s.yaml" | ||
|
||
- name: Install ansible-init playbook for k3s agent or server activation | ||
copy: | ||
src: start_k3s.yml | ||
dest: /etc/ansible-init/playbooks/0-start-k3s.yml |
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,44 @@ | ||
--- | ||
|
||
- name: Check if k9s is installed | ||
ansible.builtin.stat: | ||
path: "/usr/bin/k9s" | ||
register: result | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: Install k9s and clean up temporary files | ||
block: | ||
- name: Create install directory | ||
ansible.builtin.file: | ||
path: /tmp/k9s | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: "744" | ||
when: not result.stat.exists | ||
wtripp180901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: Download k9s | ||
ansible.builtin.get_url: | ||
url: https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz | ||
dest: /tmp/k9s/k9s_Linux_amd64.tar.gz | ||
owner: root | ||
group: root | ||
mode: "744" | ||
|
||
- name: Unpack k9s binary | ||
ansible.builtin.unarchive: | ||
src: /tmp/k9s/k9s_Linux_amd64.tar.gz | ||
dest: /tmp/k9s | ||
remote_src: yes | ||
|
||
- name: Add k9s to root path | ||
ansible.builtin.copy: | ||
src: /tmp/k9s/k9s | ||
dest: /usr/bin/k9s | ||
mode: u+rwx | ||
remote_src: yes | ||
|
||
- name: Cleanup k9s install directory | ||
ansible.builtin.file: | ||
path: /tmp/k9s | ||
state: absent | ||
when: not result.stat.exists | ||
wtripp180901 marked this conversation as resolved.
Outdated
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
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: 3 additions & 0 deletions
3
ansible/roles/passwords/templates/k3s-token.auto.tfvars.json.j2
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_token": "{{ templated_secrets.vault_k3s_token }}" | ||
wtripp180901 marked this conversation as resolved.
Outdated
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Overview | ||
A K3s cluster is deployed with the Slurm cluster. Both an agent and server instance of K3s is installed during image build and the correct service (determined by OpenStack metadata) will be | ||
enabled during boot. Nodes with the `k3s_server` metadata field defined will be configured as K3s agents (this field gives them the address of the server). The Slurm control node is currently configured as a server while all other nodes are configured as agents. Using multiple K3s servers isn't supported. Currently only the root user on the control node has | ||
access to the Kubernetes API. The `k3s` role installs Helm for package management. K9s is also installed in the image and can be used by the root user. | ||
|
||
# Idempotency | ||
K3s is intended to only be installed during image build as it is configured by the appliance on first boot with `azimuth_cloud.image_utils.linux_ansible_init`. Therefore, the `k3s` role isn't | ||
idempotent and changes to variables will not be reflected in the image when running `site.yml`. |
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: 4 additions & 4 deletions
8
environments/.stackhpc/terraform/cluster_image.auto.tfvars.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"cluster_image": { | ||
"RL8": "openhpc-RL8-241024-1439-177083b1", | ||
"RL9": "openhpc-RL9-241024-1438-177083b1", | ||
"RL9-cuda": "openhpc-cuda-RL9-241024-1628-177083b1" | ||
"RL8": "openhpc-RL8-241104-1102-4f457012", | ||
"RL9": "openhpc-RL9-241104-1102-4f457012", | ||
"RL9-cuda": "openhpc-cuda-RL9-241104-1102-4f457012" | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.