Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ab65245
added k3s installation to bootstrap
wtripp180901 Sep 10, 2024
321fdb4
added k3ds token to terraform
wtripp180901 Sep 10, 2024
915c4dd
added role to install playbooks for ansible-init
wtripp180901 Sep 11, 2024
824e117
Refactored so that agent or server is determined by metadata
wtripp180901 Sep 12, 2024
b49b22c
Added (very hacky) k3s token generation
wtripp180901 Sep 12, 2024
99c0028
Added k9s role
wtripp180901 Sep 13, 2024
68feb76
Moved k3s install to after network setup
wtripp180901 Sep 13, 2024
90c7a78
Added seperate k3s group
wtripp180901 Sep 16, 2024
cbcf762
Added helm
wtripp180901 Sep 16, 2024
370b188
Fixed ansible-init sentinel being created in packer build
wtripp180901 Sep 17, 2024
df02a66
Moved helm install
wtripp180901 Sep 17, 2024
327c645
Added kube roles to gitignore
wtripp180901 Sep 17, 2024
ce82f59
moved installs to usr/bin
wtripp180901 Sep 17, 2024
250b4c7
remove local DNS as a dependency for k3s
sjpb Sep 19, 2024
2f26fa1
agent/server config now based on if server name defined
wtripp180901 Sep 19, 2024
a8d4e17
k3s token now templated into terraform vars
wtripp180901 Sep 19, 2024
510115f
Name and label suggestions from review
wtripp180901 Sep 19, 2024
56c0d67
Refactor + group changes
wtripp180901 Sep 19, 2024
6d6bd2d
Refactored k9s install
wtripp180901 Sep 19, 2024
2b4f1f6
Removed server from control terraform and changed ansible-init file t…
wtripp180901 Sep 19, 2024
132e49e
Fixed merge conflicts
wtripp180901 Sep 20, 2024
1952797
more merge conflicts
wtripp180901 Sep 20, 2024
c642866
name update
wtripp180901 Sep 20, 2024
0975257
Updated .stackhpc env with k3s token
wtripp180901 Sep 20, 2024
22a4e6d
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 Sep 20, 2024
79383fe
added k3s readme
wtripp180901 Sep 20, 2024
fa955dd
bump images
wtripp180901 Sep 20, 2024
a8569da
Disabled traefik for non-server nodes
wtripp180901 Sep 30, 2024
8250483
Revert images for clean build
wtripp180901 Sep 30, 2024
46401bf
bump images
wtripp180901 Oct 1, 2024
15d3514
Apply suggestions from code review
wtripp180901 Oct 2, 2024
bc37064
Code review tweaks
wtripp180901 Oct 2, 2024
2ab8e52
Moved k3s token to be with rest of appliance secrets
wtripp180901 Oct 2, 2024
26a0f89
bump images
wtripp180901 Oct 2, 2024
8f0923c
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 Oct 3, 2024
cfb5514
updated caas for k3s
wtripp180901 Oct 4, 2024
8b7941d
fixed k3s install overwriting ansible-init changes
wtripp180901 Oct 4, 2024
5dfec0d
bump images
wtripp180901 Oct 4, 2024
1035460
removed k3s ingress
wtripp180901 Oct 8, 2024
7eb4821
added k3s docs
wtripp180901 Oct 8, 2024
9f00f11
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 Oct 8, 2024
2861edb
merge conflict fixes
wtripp180901 Oct 8, 2024
e6dd871
bump images
wtripp180901 Oct 9, 2024
7b3b115
Fixed node passwords changing on reimage
wtripp180901 Oct 10, 2024
d95037b
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 Oct 10, 2024
a0d947b
fixed missing directory
wtripp180901 Oct 11, 2024
1d1e777
typo
wtripp180901 Oct 11, 2024
3be011c
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 Oct 11, 2024
440f20c
moved CI image definition
wtripp180901 Oct 11, 2024
d69033a
bump images
wtripp180901 Oct 11, 2024
3d2e2cd
added cuda image for ci
wtripp180901 Oct 11, 2024
2efa193
typo
wtripp180901 Oct 11, 2024
ba1d212
corrected docs
wtripp180901 Oct 14, 2024
904df8a
k3s install now air-gapped
wtripp180901 Oct 22, 2024
a67ffd3
bump images
wtripp180901 Oct 23, 2024
04db97d
merge from main
wtripp180901 Oct 25, 2024
7008500
ci images bumped up to date with main
wtripp180901 Oct 25, 2024
79433b8
fixed k3s token idempotency issues
wtripp180901 Nov 4, 2024
bba95bb
Comment + doc changes from review
wtripp180901 Nov 4, 2024
3f599c6
play rename
wtripp180901 Nov 4, 2024
a6f0137
removed sentinel cleanup
wtripp180901 Nov 4, 2024
03fe568
k3s role refactor
wtripp180901 Nov 4, 2024
d96eddd
updated k3s docs
wtripp180901 Nov 4, 2024
21b7081
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 Nov 4, 2024
4f45701
merge conflicts
wtripp180901 Nov 4, 2024
bf47035
bumped images up to date with main
wtripp180901 Nov 4, 2024
ad84877
fixed k3s token generation
wtripp180901 Nov 4, 2024
54910a1
Merge branch 'feature/k3s-ansible-init' of github.com:stackhpc/ansibl…
wtripp180901 Nov 4, 2024
8ab12e9
Passwords role now reads variables into top level vars
wtripp180901 Nov 12, 2024
bf16547
moved k3s plays to install script
wtripp180901 Nov 12, 2024
5e3927b
reverted caas changes
wtripp180901 Nov 12, 2024
98f5b79
Merge branch 'main' into feature/k3s-ansible-init
wtripp180901 Nov 12, 2024
20a8a62
re-enabled caas access_network
wtripp180901 Nov 12, 2024
5b43d0e
bump images
wtripp180901 Nov 13, 2024
4538c6d
merge
wtripp180901 Nov 15, 2024
100632f
bump
wtripp180901 Nov 18, 2024
0c17410
k9s tags and variable renames
wtripp180901 Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ansible/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ roles/*
!roles/squid/**
!roles/tuned/
!roles/tuned/**

!roles/k3s/
!roles/k3s/**
!roles/k9s/
!roles/k9s/**
6 changes: 6 additions & 0 deletions ansible/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,9 @@
tasks:
- include_role:
name: azimuth_cloud.image_utils.linux_ansible_init

- hosts: k3s
become: yes
tasks:
- ansible.builtin.include_role:
name: k3s
5 changes: 5 additions & 0 deletions ansible/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@

- name: Cleanup /tmp
command : rm -rf /tmp/*

- name: Delete ansible-init sentintel file created during build
ansible.builtin.file:
path: /var/lib/ansible-init.done
state: absent
28 changes: 28 additions & 0 deletions ansible/roles/k3s/files/start_k3s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- 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 }}"
k3s_node_type: "{{ os_metadata.meta.k3s_node_type }}"
service_name: "{{ 'k3s-agent' if k3s_node_type == 'agent' else 'k3s' }}"
tasks:
- name: Add the token for joining the cluster to the environment
no_log: false # 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_node_type == "agent"

- name: Start k3s service
ansible.builtin.systemd:
name: "{{ service_name }}"
daemon_reload: true
state: started
enabled: true
when: k3s_node_type != "none"
43 changes: 43 additions & 0 deletions ansible/roles/k3s/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

- 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: "v1.31.0+k3s1"
INSTALL_K3S_EXEC: "{{ item }}"
INSTALL_K3S_SKIP_START: "true"
INSTALL_K3S_SKIP_ENABLE: "true"
INSTALL_K3S_BIN_DIR: "/usr/bin"
changed_when: true
with_items:
- server
- agent

- name: Installing helm
unarchive:
src: https://get.helm.sh/helm-v3.11.0-linux-amd64.tar.gz
dest: /usr/bin
extra_opts: "--strip-components=1"
owner: root
group: root
mode: 0755
remote_src: true

- name: k9s install
ansible.builtin.include_role:
name: k9s

- name: Install k3s server ansible-init playbook
copy:
src: start_k3s.yml
dest: /etc/ansible-init/playbooks/0-start-k3s.yml
33 changes: 33 additions & 0 deletions ansible/roles/k9s/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Create install directory
ansible.builtin.file:
path: /root/k9s-temp
state: directory

- name: Download k9s
ansible.builtin.get_url:
url: https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz
dest: /root/k9s-temp/k9s_Linux_amd64.tar.gz

- name: Unpack k9s binary
ansible.builtin.unarchive:
src: /root/k9s-temp/k9s_Linux_amd64.tar.gz
dest: /root/k9s-temp
remote_src: yes

- name: Add k9s to root path
ansible.builtin.copy:
src: /root/k9s-temp/k9s
dest: /usr/bin/k9s
mode: u+rwx
remote_src: yes

- name: Add k3s kubeconfig as environment variable
ansible.builtin.lineinfile:
path: /etc/environment
line: "KUBECONFIG=/etc/rancher/k3s/k3s.yaml"

- name: Cleanup k9s install directory
ansible.builtin.file:
path: /root/k9s-temp
state: absent
15 changes: 14 additions & 1 deletion ansible/roles/passwords/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
delegate_to: localhost
run_once: true

- name: Generate k3s token
ansible.builtin.set_fact:
k3s_token_secret: ""

- name: Generate k3s token and add to terraform
vars:
token: "{{ lookup('ansible.builtin.password', '/dev/null', length=64) }}"
replace:
path: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}/terraform/variables.tf"
regexp: "k3s_token_replace_me"
replace: "{{ token }}"


# - name: Ensure munge key directory exists
# file:
# state: directory
Expand All @@ -17,4 +30,4 @@
# copy:
# content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}"
# dest: "{{ openhpc_passwords_mungekey_output_path }}"
# force: false
# force: false
5 changes: 4 additions & 1 deletion environments/common/inventory/groups
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ freeipa_client
# Hosts to run TuneD configuration

[ansible_init]
# Hosts to run linux-anisble-init
# Hosts to run linux-anisble-init

[k3s]
# Hosts to run k3s server/agent
6 changes: 5 additions & 1 deletion environments/common/layouts/everything
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ openhpc

[ansible_init:children]
# Hosts to run ansible-init
cluster
cluster

[k3s:children]
# Hosts to run k3s server/agent
cluster
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module "compute" {
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
key_pair = var.key_pair
environment_root = var.environment_root
k3s_token = var.k3s_token
security_group_ids = [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id]
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ resource "openstack_compute_instance_v2" "compute" {

metadata = {
environment_root = var.environment_root
k3s_token = var.k3s_token
k3s_server = "${var.cluster_name}-control"
k3s_node_type = "agent"
}

user_data = <<-EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ variable "root_volume_size" {
variable "security_group_ids" {
type = list
}

variable "k3s_token" {
description = "Random cryptographically secure string for K3s token (must be set by ../compute.tf)"
type = string
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ resource "openstack_compute_instance_v2" "control" {

metadata = {
environment_root = var.environment_root
k3s_token = var.k3s_token
k3s_server = "${var.cluster_name}-control"
k3s_node_type = "server"
}

user_data = <<-EOF
Expand Down Expand Up @@ -124,6 +127,9 @@ resource "openstack_compute_instance_v2" "login" {

metadata = {
environment_root = var.environment_root
k3s_token = var.k3s_token
k3s_server = "${var.cluster_name}-control"
k3s_node_type = "agent"
}

user_data = <<-EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ variable "root_volume_size" {
type = number
default = 40
}

variable "k3s_token" {
description = "Random cryptographically secure string for K3s token"
type = string
default = "k3s_token_replace_me"
}
Loading