mirror of
https://github.com/techno-tim/k3s-ansible.git
synced 2026-09-17 09:23:19 +02:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bbfe399878 | |||
| 565270a55a | |||
| 3b87add6ad | |||
| cd06c1c8b6 | |||
| f769461fb1 | |||
| dc3d420173 | |||
| b7582f9e4c | |||
| 68f1674b50 | |||
| e1b34d2395 | |||
| 0cdf21b819 | |||
| 93fbea38dd | |||
| c86cbb9fbc | |||
| f3b88a7ea4 | |||
| 18044d23a4 | |||
| 2cd03f38f2 | |||
| 8e1265fbae | |||
| f6ee0c72ef | |||
| e7ba494a00 |
@@ -51,9 +51,6 @@ extra_agent_args: ""
|
|||||||
|
|
||||||
kube_vip_tag_version: ""
|
kube_vip_tag_version: ""
|
||||||
|
|
||||||
kube_vip_cloud_provider_tag_version: ""
|
|
||||||
kube_vip_lb_ip_range: ""
|
|
||||||
|
|
||||||
metal_lb_speaker_tag_version: ""
|
metal_lb_speaker_tag_version: ""
|
||||||
metal_lb_controller_tag_version: ""
|
metal_lb_controller_tag_version: ""
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the codebase
|
- name: Check out the codebase
|
||||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 4.1.1
|
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v3 2.5.0
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # 5.0.0
|
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # 2.3.3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip' # caching pip dependencies
|
cache: 'pip' # caching pip dependencies
|
||||||
|
|||||||
@@ -2,20 +2,11 @@
|
|||||||
name: "CI"
|
name: "CI"
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types:
|
push:
|
||||||
- opened
|
branches:
|
||||||
- synchronize
|
- master
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**/.gitignore'
|
- '**/README.md'
|
||||||
- '**/FUNDING.yml'
|
|
||||||
- '**/host.ini'
|
|
||||||
- '**/*.md'
|
|
||||||
- '**/.editorconfig'
|
|
||||||
- '**/ansible.example.cfg'
|
|
||||||
- '**/deploy.sh'
|
|
||||||
- '**/LICENSE'
|
|
||||||
- '**/reboot.sh'
|
|
||||||
- '**/reset.sh'
|
|
||||||
jobs:
|
jobs:
|
||||||
pre:
|
pre:
|
||||||
uses: ./.github/workflows/cache.yml
|
uses: ./.github/workflows/cache.yml
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the codebase
|
- name: Check out the codebase
|
||||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 4.1.1
|
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v3 2.5.0
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # 5.0.0
|
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # 2.3.3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip' # caching pip dependencies
|
cache: 'pip' # caching pip dependencies
|
||||||
@@ -45,9 +45,9 @@ jobs:
|
|||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 4.1.1
|
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v3 2.5.0
|
||||||
- name: Ensure SHA pinned actions
|
- name: Ensure SHA pinned actions
|
||||||
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@ba37328d4ea95eaf8b3bd6c6cef308f709a5f2ec # 3.0.3
|
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@af2eb3226618e2494e3d9084f515ad6dcf16e229 # 2.0.1
|
||||||
with:
|
with:
|
||||||
allowlist: |
|
allowlist: |
|
||||||
aws-actions/
|
aws-actions/
|
||||||
|
|||||||
@@ -13,42 +13,16 @@ jobs:
|
|||||||
- ipv6
|
- ipv6
|
||||||
- single_node
|
- single_node
|
||||||
- calico
|
- calico
|
||||||
- kube-vip
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
env:
|
env:
|
||||||
PYTHON_VERSION: "3.11"
|
PYTHON_VERSION: "3.11"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the codebase
|
- name: Check out the codebase
|
||||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 4.1.1
|
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v3 2.5.0
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
# these steps are necessary if not using ephemeral nodes
|
|
||||||
- name: Delete old Vagrant box versions
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: vagrant box prune --force
|
|
||||||
|
|
||||||
- name: Remove all local Vagrant boxes
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: if vagrant box list 2>/dev/null; then vagrant box list | cut -f 1 -d ' ' | xargs -L 1 vagrant box remove -f 2>/dev/null && echo "All Vagrant boxes removed." || echo "No Vagrant boxes found."; else echo "No Vagrant boxes found."; fi
|
|
||||||
|
|
||||||
- name: Remove all Virtualbox VMs
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: VBoxManage list vms | awk -F'"' '{print $2}' | xargs -I {} VBoxManage unregistervm --delete "{}"
|
|
||||||
|
|
||||||
- name: Remove all Virtualbox HDs
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: VBoxManage list hdds | awk -F':' '/^UUID:/ {print $2}' | xargs -I {} VBoxManage closemedium disk "{}" --delete
|
|
||||||
|
|
||||||
- name: Remove all Virtualbox Networks
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: VBoxManage list hostonlyifs | grep '^Name:' | awk '{print $2}' | grep '^vboxnet' | xargs -I {} VBoxManage hostonlyif remove {}
|
|
||||||
|
|
||||||
- name: Remove Virtualbox network config
|
|
||||||
if: always() # do this even if a step before has failed
|
|
||||||
run: sudo rm /etc/vbox/networks.conf || true
|
|
||||||
|
|
||||||
- name: Configure VirtualBox
|
- name: Configure VirtualBox
|
||||||
run: |-
|
run: |-
|
||||||
sudo mkdir -p /etc/vbox
|
sudo mkdir -p /etc/vbox
|
||||||
@@ -58,7 +32,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # 5.0.0
|
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # 2.3.3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip' # caching pip dependencies
|
cache: 'pip' # caching pip dependencies
|
||||||
@@ -97,7 +71,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Remove all local Vagrant boxes
|
- name: Remove all local Vagrant boxes
|
||||||
if: always() # do this even if a step before has failed
|
if: always() # do this even if a step before has failed
|
||||||
run: if vagrant box list 2>/dev/null; then vagrant box list | cut -f 1 -d ' ' | xargs -L 1 vagrant box remove -f 2>/dev/null && echo "All Vagrant boxes removed." || echo "No Vagrant boxes found."; else echo "No Vagrant boxes found."; fi
|
run: vagrant box list | cut -f 1 -d ' ' | xargs -L 1 vagrant box remove -f
|
||||||
|
|
||||||
- name: Remove all Virtualbox VMs
|
- name: Remove all Virtualbox VMs
|
||||||
if: always() # do this even if a step before has failed
|
if: always() # do this even if a step before has failed
|
||||||
@@ -113,13 +87,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Remove Virtualbox network config
|
- name: Remove Virtualbox network config
|
||||||
if: always() # do this even if a step before has failed
|
if: always() # do this even if a step before has failed
|
||||||
run: sudo rm /etc/vbox/networks.conf || true
|
run: sudo rm /etc/vbox/networks.conf
|
||||||
|
|
||||||
- name: Upload log files
|
- name: Upload log files
|
||||||
if: always() # do this even if a step before has failed
|
if: always() # do this even if a step before has failed
|
||||||
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # 4.3.0
|
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # 3.1.1
|
||||||
with:
|
with:
|
||||||
name: logs
|
name: logs
|
||||||
path: |
|
path: |
|
||||||
${{ runner.temp }}/logs
|
${{ runner.temp }}/logs
|
||||||
overwrite: true
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
.env/
|
.env/
|
||||||
*.log
|
*.log
|
||||||
ansible.cfg
|
ansible.cfg
|
||||||
kubeconfig
|
|
||||||
|
|||||||
@@ -56,13 +56,6 @@ extra_agent_args: >-
|
|||||||
# image tag for kube-vip
|
# image tag for kube-vip
|
||||||
kube_vip_tag_version: "v0.6.4"
|
kube_vip_tag_version: "v0.6.4"
|
||||||
|
|
||||||
# tag for kube-vip-cloud-provider manifest
|
|
||||||
# kube_vip_cloud_provider_tag_version: "main"
|
|
||||||
|
|
||||||
# kube-vip ip range for load balancer
|
|
||||||
# (uncomment to use kube-vip for services instead of MetalLB)
|
|
||||||
# kube_vip_lb_ip_range: "192.168.30.80-192.168.30.90"
|
|
||||||
|
|
||||||
# metallb type frr or native
|
# metallb type frr or native
|
||||||
metal_lb_type: "native"
|
metal_lb_type: "native"
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ We have these scenarios:
|
|||||||
Very similar to the default scenario, but uses only a single node for all cluster functionality.
|
Very similar to the default scenario, but uses only a single node for all cluster functionality.
|
||||||
- **calico**:
|
- **calico**:
|
||||||
The same as single node, but uses calico cni instead of flannel.
|
The same as single node, but uses calico cni instead of flannel.
|
||||||
- **kube-vip**
|
|
||||||
The same as single node, but uses kube-vip as service loadbalancer instead of MetalLB
|
|
||||||
|
|
||||||
## How to execute
|
## How to execute
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
---
|
|
||||||
dependency:
|
|
||||||
name: galaxy
|
|
||||||
driver:
|
|
||||||
name: vagrant
|
|
||||||
platforms:
|
|
||||||
- name: control1
|
|
||||||
box: generic/ubuntu2204
|
|
||||||
memory: 4096
|
|
||||||
cpus: 4
|
|
||||||
config_options:
|
|
||||||
# We currently can not use public-key based authentication on Ubuntu 22.04,
|
|
||||||
# see: https://github.com/chef/bento/issues/1405
|
|
||||||
ssh.username: "vagrant"
|
|
||||||
ssh.password: "vagrant"
|
|
||||||
groups:
|
|
||||||
- k3s_cluster
|
|
||||||
- master
|
|
||||||
interfaces:
|
|
||||||
- network_name: private_network
|
|
||||||
ip: 192.168.30.62
|
|
||||||
provisioner:
|
|
||||||
name: ansible
|
|
||||||
env:
|
|
||||||
ANSIBLE_VERBOSITY: 1
|
|
||||||
playbooks:
|
|
||||||
converge: ../resources/converge.yml
|
|
||||||
side_effect: ../resources/reset.yml
|
|
||||||
verify: ../resources/verify.yml
|
|
||||||
inventory:
|
|
||||||
links:
|
|
||||||
group_vars: ../../inventory/sample/group_vars
|
|
||||||
scenario:
|
|
||||||
test_sequence:
|
|
||||||
- dependency
|
|
||||||
- cleanup
|
|
||||||
- destroy
|
|
||||||
- syntax
|
|
||||||
- create
|
|
||||||
- prepare
|
|
||||||
- converge
|
|
||||||
# idempotence is not possible with the playbook in its current form.
|
|
||||||
- verify
|
|
||||||
# We are repurposing side_effect here to test the reset playbook.
|
|
||||||
# This is why we do not run it before verify (which tests the cluster),
|
|
||||||
# but after the verify step.
|
|
||||||
- side_effect
|
|
||||||
- cleanup
|
|
||||||
- destroy
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Apply overrides
|
|
||||||
hosts: all
|
|
||||||
tasks:
|
|
||||||
- name: Override host variables
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
# See:
|
|
||||||
# https://github.com/flannel-io/flannel/blob/67d603aaf45ef80f5dd39f43714fc5e6f8a637eb/Documentation/troubleshooting.md#Vagrant
|
|
||||||
flannel_iface: eth1
|
|
||||||
|
|
||||||
# The test VMs might be a bit slow, so we give them more time to join the cluster:
|
|
||||||
retry_count: 45
|
|
||||||
|
|
||||||
# Make sure that our IP ranges do not collide with those of the other scenarios
|
|
||||||
apiserver_endpoint: "192.168.30.225"
|
|
||||||
# Use kube-vip instead of MetalLB
|
|
||||||
kube_vip_lb_ip_range: "192.168.30.110-192.168.30.119"
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Create manifests directory on first master
|
|
||||||
file:
|
|
||||||
path: /var/lib/rancher/k3s/server/manifests
|
|
||||||
state: directory
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0644
|
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
|
||||||
|
|
||||||
- name: Download vip cloud provider manifest to first master
|
|
||||||
ansible.builtin.get_url:
|
|
||||||
url: "https://raw.githubusercontent.com/kube-vip/kube-vip-cloud-provider/{{ kube_vip_cloud_provider_tag_version | default('main') }}/manifest/kube-vip-cloud-controller.yaml" # noqa yaml[line-length]
|
|
||||||
dest: "/var/lib/rancher/k3s/server/manifests/kube-vip-cloud-controller.yaml"
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0644
|
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
|
||||||
|
|
||||||
- name: Copy kubevip configMap manifest to first master
|
|
||||||
template:
|
|
||||||
src: "kubevip.yaml.j2"
|
|
||||||
dest: "/var/lib/rancher/k3s/server/manifests/kubevip.yaml"
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0644
|
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
|
||||||
@@ -29,12 +29,6 @@
|
|||||||
- name: Deploy metallb manifest
|
- name: Deploy metallb manifest
|
||||||
include_tasks: metallb.yml
|
include_tasks: metallb.yml
|
||||||
tags: metallb
|
tags: metallb
|
||||||
when: kube_vip_lb_ip_range is not defined
|
|
||||||
|
|
||||||
- name: Deploy kube-vip manifest
|
|
||||||
include_tasks: kube-vip.yml
|
|
||||||
tags: kubevip
|
|
||||||
when: kube_vip_lb_ip_range is defined
|
|
||||||
|
|
||||||
- name: Init cluster inside the transient k3s-init service
|
- name: Init cluster inside the transient k3s-init service
|
||||||
command:
|
command:
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: ConfigMap
|
|
||||||
metadata:
|
|
||||||
name: kubevip
|
|
||||||
namespace: kube-system
|
|
||||||
data:
|
|
||||||
{% if kube_vip_lb_ip_range is string %}
|
|
||||||
{# kube_vip_lb_ip_range was used in the legacy way: single string instead of a list #}
|
|
||||||
{# => transform to list with single element #}
|
|
||||||
{% set kube_vip_lb_ip_range = [kube_vip_lb_ip_range] %}
|
|
||||||
{% endif %}
|
|
||||||
range-global: {{ kube_vip_lb_ip_range | join(',') }}
|
|
||||||
@@ -43,7 +43,7 @@ spec:
|
|||||||
- name: vip_ddns
|
- name: vip_ddns
|
||||||
value: "false"
|
value: "false"
|
||||||
- name: svc_enable
|
- name: svc_enable
|
||||||
value: "{{ 'true' if kube_vip_lb_ip_range is defined else 'false' }}"
|
value: "false"
|
||||||
- name: vip_leaderelection
|
- name: vip_leaderelection
|
||||||
value: "true"
|
value: "true"
|
||||||
- name: vip_leaseduration
|
- name: vip_leaseduration
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
- name: Deploy metallb pool
|
- name: Deploy metallb pool
|
||||||
include_tasks: metallb.yml
|
include_tasks: metallb.yml
|
||||||
tags: metallb
|
tags: metallb
|
||||||
when: kube_vip_lb_ip_range is not defined
|
|
||||||
|
|
||||||
- name: Remove tmp directory used for manifests
|
- name: Remove tmp directory used for manifests
|
||||||
file:
|
file:
|
||||||
|
|||||||
@@ -8,27 +8,6 @@
|
|||||||
with_items: "{{ groups[group_name_master | default('master')] }}"
|
with_items: "{{ groups[group_name_master | default('master')] }}"
|
||||||
run_once: true
|
run_once: true
|
||||||
|
|
||||||
- name: Delete outdated metallb replicas
|
|
||||||
shell: |-
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
REPLICAS=$(k3s kubectl --namespace='metallb-system' get replicasets \
|
|
||||||
-l 'component=controller,app=metallb' \
|
|
||||||
-o jsonpath='{.items[0].spec.template.spec.containers[0].image}, {.items[0].metadata.name}' 2>/dev/null || true)
|
|
||||||
REPLICAS_SETS=$(echo ${REPLICAS} | grep -v '{{ metal_lb_controller_tag_version }}' | sed -e "s/^.*\s//g")
|
|
||||||
if [ -n "${REPLICAS_SETS}" ] ; then
|
|
||||||
for REPLICAS in "${REPLICAS_SETS}"
|
|
||||||
do
|
|
||||||
k3s kubectl --namespace='metallb-system' \
|
|
||||||
delete rs "${REPLICAS}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
||||||
changed_when: false
|
|
||||||
run_once: true
|
|
||||||
with_items: "{{ groups[group_name_master | default('master')] }}"
|
|
||||||
|
|
||||||
- name: Copy metallb CRs manifest to first master
|
- name: Copy metallb CRs manifest to first master
|
||||||
template:
|
template:
|
||||||
src: "metallb.crs.j2"
|
src: "metallb.crs.j2"
|
||||||
|
|||||||
@@ -46,14 +46,3 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: k3s_server_post
|
- role: k3s_server_post
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Storing kubeconfig in the playbook directory
|
|
||||||
hosts: master
|
|
||||||
environment: "{{ proxy_env | default({}) }}"
|
|
||||||
tasks:
|
|
||||||
- name: Copying kubeconfig from {{ hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] }}
|
|
||||||
ansible.builtin.fetch:
|
|
||||||
src: "{{ ansible_user_dir }}/.kube/config"
|
|
||||||
dest: ./kubeconfig
|
|
||||||
flat: true
|
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
|
||||||
|
|||||||
Reference in New Issue
Block a user