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

add kube-vip as a service load balancer #432

Merged
merged 10 commits into from
Jan 29, 2024
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ extra_agent_args: ""

kube_vip_tag_version: ""

service_lb_type: ""
kube_vip_cloud_provider_tag_version: ""
kube_vip_lb_ip_range: ""

metal_lb_speaker_tag_version: ""
metal_lb_controller_tag_version: ""

Expand Down
9 changes: 9 additions & 0 deletions inventory/sample/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ extra_agent_args: >-
# image tag for kube-vip
kube_vip_tag_version: "v0.6.4"

# loadbalancer to use for services: "kube-vip" or "metallb"
service_lb_type: "metallb"

# tag for kube-vip-cloud-provider manifest
kube_vip_cloud_provider_tag_version: "main"

# kube-vip ip range for load balancer
kube_vip_lb_ip_range: "192.168.30.80-192.168.30.90"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking instead of having service_lb_type we could just check to see if kube_vip_lb_ip_range had values or metal_lb_ip_range had values and infer which one to use based on that?
e.g. in this scenario kube-vip would be used.

# metallb ip range for load balancer
#metal_lb_ip_range: "192.168.30.80-192.168.30.90"

# kube-vip ip range for load balancer
kube_vip_lb_ip_range: "192.168.30.80-192.168.30.90"

Then the default group vars could be:

# metallb ip range for load balancer
metal_lb_ip_range: "192.168.30.80-192.168.30.90"

# kube-vip ip range for load balancer
#kube_vip_lb_ip_range: "192.168.30.80-192.168.30.90"

This way someone would only need to uncomment kube-vip and comment metal lb and everything would work, we don't break the contract, and we don't need a type. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the configuration according to your suggestion


# metallb type frr or native
metal_lb_type: "native"

Expand Down
27 changes: 27 additions & 0 deletions roles/k3s_server/tasks/kube-vip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- 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 }}/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']
6 changes: 6 additions & 0 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
- name: Deploy metallb manifest
include_tasks: metallb.yml
tags: metallb
when: service_lb_type | default('metallb') == 'metallb'

- name: Deploy kube-vip manifest
include_tasks: kube-vip.yml
tags: kubevip
when: service_lb_type | default('metallb') == 'kube-vip'

- name: Init cluster inside the transient k3s-init service
command:
Expand Down
13 changes: 13 additions & 0 deletions roles/k3s_server/templates/kubevip.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
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(',') }}
2 changes: 1 addition & 1 deletion roles/k3s_server/templates/vip.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
- name: vip_ddns
value: "false"
- name: svc_enable
value: "false"
value: "{{ 'true' if service_lb_type == 'kube-vip' else 'false' }}"
- name: vip_leaderelection
value: "true"
- name: vip_leaseduration
Expand Down
1 change: 1 addition & 0 deletions roles/k3s_server_post/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- name: Deploy metallb pool
include_tasks: metallb.yml
tags: metallb
when: service_lb_type | default('metallb') == 'metallb'

- name: Remove tmp directory used for manifests
file:
Expand Down