Skip to content
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

feat: add documentation and configuration for deploying SC4S on RKE2 with ansible #2635

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-lite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
type=ref,event=tag
- name: matrix
id: matrix
uses: splunk/[email protected].8
uses: splunk/[email protected].9

security-fossa-scan:
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
type=ref,event=tag
- name: matrix
id: matrix
uses: splunk/[email protected].8
uses: splunk/[email protected].9

security-fossa-scan:
continue-on-error: true
Expand Down
5 changes: 5 additions & 0 deletions ansible/inventory/inventory_rke2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
control_nodes:
hosts:
token_node:
ansible_host:
config_file:
23 changes: 23 additions & 0 deletions ansible/inventory/inventory_rke2_ha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
control_nodes:
hosts:
token_node:
ansible_host:
config_file:
optional_control_node_1:
ansible_host:
config_file:
optional_control_node_2:
ansible_host:
config_file:

agent_nodes:
hosts:
optional_agent_1:
ansible_host:
config_file:
optional_agent_2:
ansible_host:
config_file:
optional_agent_3:
ansible_host:
config_file:
65 changes: 65 additions & 0 deletions ansible/playbooks/rke2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- name: Copy rke2 configuration files
hosts: all
become: true
tasks:
- include_tasks: ../tasks/rke2/copy_config.yml

- name: Install and run rke2-server.service on first control node
hosts: control_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/install_first_server.yml

- name: Get node-token from a control node
hosts: control_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/get_registration_token.yml

- name: Add node-token to other control nodes and agent nodes configuration
hosts: control_nodes:agent_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/add_token_to_config.yml

- name: Install and run rke2-server.service on rest of the control nodes
hosts: control_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/install_other_servers.yml

- name: Install and run rke2-agent.service on agent nodes
hosts: agent_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/install_agents.yml

- name: Make kubectl executable available for ansible_user
hosts: control_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/provide_kubectl.yml

- name: Deploy k8s secrets
hosts: control_nodes
become: true
tasks:
- include_tasks: ../tasks/rke2/deploy_secrets.yml

- name: Install metallb
hosts: control_nodes
tasks:
- include_tasks: ../tasks/rke2/install_metallb.yml

- name: Install SC4S helm repo
hosts: control_nodes
tasks:
- include_tasks: ../tasks/rke2/install_helm_repo.yml

- name: Deploy SC4S app
hosts: control_nodes
tasks:
- include_tasks: ../tasks/rke2/deploy_app.yml


15 changes: 15 additions & 0 deletions ansible/resources/metallb-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
namespace: metallb
name: my-ip-pool
spec:
addresses:
# Configure address pool for metallb
#- 1.2.3.4/32
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
namespace: metallb
name: l2-advertisement
8 changes: 8 additions & 0 deletions ansible/tasks/rke2/add_token_to_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Add rke2 token to config
lineinfile:
path: /etc/rancher/rke2/config.yaml
regexp: '^token:'
line: "token: {{ hostvars['token_node'].rke2_token }}"
create: yes
when: inventory_hostname != "token_node"
14 changes: 14 additions & 0 deletions ansible/tasks/rke2/copy_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Create /etc/rancher/rke2 directory
file:
path: /etc/rancher/rke2
state: directory
mode: u=rw,g=rw,o=r

- name: Copy the configuration file to the remote location
copy:
src: "{{ config_file }}"
dest: /etc/rancher/rke2/config.yaml
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: u=rw,g=rw,o=r
21 changes: 21 additions & 0 deletions ansible/tasks/rke2/deploy_app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Copying values.yml file on the server
copy:
src: /opt/charts/splunk-connect-for-syslog/values.yaml
dest: "/home/{{ ansible_user }}/values.yaml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: u=rw,g=rw,o=r

- name: Deploy app or update it with new values if already deployed
block:
- name: Deploy sc4s app from templates with overwrites from values.yml
ansible.builtin.shell: helm install sc4s splunk-connect-for-syslog/splunk-connect-for-syslog -f values.yaml
args:
chdir: "/home/{{ ansible_user }}/"
rescue:
- name: Update app with new values.yml
ansible.builtin.shell: helm upgrade sc4s splunk-connect-for-syslog/splunk-connect-for-syslog -f values.yaml
args:
chdir: "/home/{{ ansible_user }}/"
when: inventory_hostname == "token_node"
29 changes: 29 additions & 0 deletions ansible/tasks/rke2/deploy_secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Load k8s secrets
include_vars:
file: "{{ item }}"
with_first_found:
- files:
- /opt/ansible/resources/k8s_secrets.yaml
- /opt/charts/splunk-connect-for-syslog/secrets.yaml

- name: Export kubectl bin path
shell: export PATH=$PATH:/var/lib/rancher/rke2/bin/

- name: Create mTLS secret
ansible.builtin.shell: |
/var/lib/rancher/rke2/bin/kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: {{ hec_tls.secret }}
type: Opaque
data:
key.pem: {{ hec_tls.value.key | b64encode }}
cert.pem: {{ hec_tls.value.cert | b64encode }}
ca_cert.pem: {{ hec_tls.value.ca | b64encode }}
EOF
when:
- hec_tls is defined
- ('secret' in hec_tls) and ('value' in hec_tls)
- inventory_hostname == "token_node"
16 changes: 16 additions & 0 deletions ansible/tasks/rke2/get_registration_token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Wait for rke2 token to be ready
wait_for:
path: /var/lib/rancher/rke2/server/node-token
timeout: 60
when: inventory_hostname == "token_node"

- name: Retrieve the rke2 node token
shell: cat /var/lib/rancher/rke2/server/node-token
register: node_token
when: inventory_hostname == "token_node"

- name: Set the node token as a fact for worker nodes
set_fact:
rke2_token: "{{ node_token.stdout }}"
when: inventory_hostname == "token_node"
9 changes: 9 additions & 0 deletions ansible/tasks/rke2/install_agents.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Run the installer
shell: curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -

- name: Enable and start rke2-agent.service
service:
name: rke2-agent.service
enabled: yes
state: started
11 changes: 11 additions & 0 deletions ansible/tasks/rke2/install_first_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Run the installer
shell: curl -sfL https://get.rke2.io | sh -
when: inventory_hostname == "token_node"

- name: Enable and start rke2-server.service
service:
name: rke2-server.service
enabled: yes
state: started
when: inventory_hostname == "token_node"
6 changes: 6 additions & 0 deletions ansible/tasks/rke2/install_helm_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Add sc4s helm repository
shell: helm repo add splunk-connect-for-syslog https://splunk.github.io/splunk-connect-for-syslog

- name: Separately update the repository cache
shell: helm repo update
27 changes: 27 additions & 0 deletions ansible/tasks/rke2/install_metallb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Add metallb helm repository
shell: helm repo add metallb https://metallb.github.io/metallb

- name: Create metallb namespace
shell: /var/lib/rancher/rke2/bin/kubectl create namespace metallb
when: inventory_hostname == "token_node"

- name: Install metallb
shell: helm install metallb metallb/metallb -n metallb
when: inventory_hostname == "token_node"

- name: Copy metallb-config.yaml file on the server
copy:
src: /opt/ansible/resources/metallb-config.yaml
dest: "/home/{{ ansible_user }}/metallb-config.yaml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: u=rw,g=rw,o=r

- name: Apply metallb config
shell: /var/lib/rancher/rke2/bin/kubectl apply -f metallb-config.yaml
register: result
retries: 10
delay: 60
until: result.stderr == ""
when: inventory_hostname == "token_node"
11 changes: 11 additions & 0 deletions ansible/tasks/rke2/install_other_servers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Run the installer
shell: curl -sfL https://get.rke2.io | sh -
when: inventory_hostname != "token_node"

- name: Enable and start rke2-server.service
service:
name: rke2-server.service
enabled: yes
state: started
when: inventory_hostname != "token_node"
14 changes: 14 additions & 0 deletions ansible/tasks/rke2/provide_kubectl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Copy kubectl config to ~/.kube/config
shell: |
mkdir -p /home/{{ ansible_user }}/.kube && \
cp /etc/rancher/rke2/rke2.yaml /home/{{ ansible_user }}/.kube/config && \
chown {{ ansible_user }} /home/{{ ansible_user }}/.kube/config

- name: Add rke2 bin path to .bashrc
lineinfile:
path: "/home/{{ ansible_user }}/.bashrc"
line: 'export PATH=$PATH:/var/lib/rancher/rke2/bin/'
create: yes
state: present
insertafter: EOF
Loading
Loading