Skip to content

Commit

Permalink
feat: IPv6 support 🚀 (#855)
Browse files Browse the repository at this point in the history
Co-authored-by: Devin Buhl <[email protected]>
  • Loading branch information
samip5 and onedr0p authored Jul 17, 2023
1 parent 6c8b9a4 commit 1d911f6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
56 changes: 48 additions & 8 deletions bootstrap/tasks/validation/net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,47 @@
success_msg: "Node CIDR {{ bootstrap_node_cidr }} is valid."
fail_msg: "Node CIDR {{ bootstrap_node_cidr }} is invalid."

- name: Verify cluster CIDR
- name: Verify cluster CIDR is ipv4 OR ipv6
when: not bootstrap_ipv6_enabled | default(false)
ansible.builtin.assert:
that: ["{{ bootstrap_cluster_cidr is ansible.utils.ipv4 }}"]
success_msg: "Cluster CIDR {{ bootstrap_cluster_cidr }} is valid."
fail_msg: "Cluster CIDR {{ bootstrap_cluster_cidr }} is invalid."
that: bootstrap_cluster_cidr is ansible.utils.ipv4 or bootstrap_cluster_cidr is ansible.utils.ipv6
success_msg: Cluster CIDR {{ bootstrap_cluster_cidr }} is valid.
fail_msg: Cluster CIDR {{ bootstrap_cluster_cidr }} is invalid.

- name: Verify service CIDR
- name: Verify service CIDR is ipv4 OR ipv6
when: not bootstrap_ipv6_enabled | default(false)
ansible.builtin.assert:
that: ["{{ bootstrap_service_cidr is ansible.utils.ipv4 }}"]
success_msg: "Service CIDR {{ bootstrap_service_cidr }} is valid."
fail_msg: "Service CIDR {{ bootstrap_service_cidr }} is invalid."
that: bootstrap_service_cidr is ansible.utils.ipv4 or bootstrap_service_cidr is ansible.utils.ipv6
success_msg: Service CIDR {{ bootstrap_service_cidr }} is valid.
fail_msg: Service CIDR {{ bootstrap_service_cidr }} is invalid.

- name: Verify cluster CIDR is ipv4 AND ipv6
when: bootstrap_ipv6_enabled | default(false)
ansible.builtin.assert:
that: >
(
bootstrap_cluster_cidr.split(',')[0] is ansible.utils.ipv4 or
bootstrap_cluster_cidr.split(',')[1] is ansible.utils.ipv4
) and (
bootstrap_cluster_cidr.split(',')[1] is ansible.utils.ipv6 or
bootstrap_cluster_cidr.split(',')[0] is ansible.utils.ipv6
)
success_msg: Cluster CIDR {{ bootstrap_cluster_cidr }} is valid.
fail_msg: Cluster CIDR {{ bootstrap_cluster_cidr }} is invalid.

- name: Verify service CIDR is ipv4 AND ipv6
when: bootstrap_ipv6_enabled | default(false)
ansible.builtin.assert:
that: >
(
bootstrap_service_cidr.split(',')[0] is ansible.utils.ipv4 or
bootstrap_service_cidr.split(',')[1] is ansible.utils.ipv4
) and (
bootstrap_service_cidr.split(',')[1] is ansible.utils.ipv6 or
bootstrap_service_cidr.split(',')[0] is ansible.utils.ipv6
)
success_msg: Service CIDR {{ bootstrap_service_cidr }} is valid.
fail_msg: Service CIDR {{ bootstrap_service_cidr }} is invalid.

- name: Verify k8s_gateway
ansible.builtin.assert:
Expand Down Expand Up @@ -72,6 +102,16 @@
loop_control:
label: "{{ item.address }}"

- name: Verify nodes are ipv4
ansible.builtin.assert:
that: item.address is ansible.utils.ipv4
success_msg: Node address {{ item.address }} is valid.
fail_msg: Node address {{ item.address }} is invalid.
quiet: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"

- name: Verify nodes are in node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(item.address) }}"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
---
# https://rancher.com/docs/k3s/latest/en/installation/install-options/server-config/
# https://github.com/PyratLabs/ansible-role-k3s

k3s_control_node: true
k3s_server:
{% if bootstrap_ipv6_enabled | default(false) %}
node-ip: "{% raw %}{{ ansible_host }},{{ ansible_default_ipv6.address }}{% endraw %}"
{% else %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %}"
{% endif %}
tls-san:
- "{% raw %}{{ kube_vip_addr }}{% endraw %}"
docker: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
---
# https://rancher.com/docs/k3s/latest/en/installation/install-options/agent-config/
# https://github.com/PyratLabs/ansible-role-k3s

k3s_control_node: false
k3s_agent:
{% if bootstrap_ipv6_enabled | default(false) %}
node-ip: "{% raw %}{{ ansible_host }},{{ ansible_default_ipv6.address }}{% endraw %}"
{% else %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %}"
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
---
# https://docs.k3s.io/helm
apiVersion: helm.cattle.io/v1
Expand Down Expand Up @@ -30,17 +31,29 @@ spec:
enabled: false
ipam:
mode: kubernetes
{% if bootstrap_ipv6_enabled | default(false) %}
ipv4NativeRoutingCIDR: "{% raw %}{{ k3s_server['cluster-cidr'].split(',')[0] }}{% endraw %}"
ipv6NativeRoutingCIDR: "{% raw %}{{ k3s_server['cluster-cidr'].split(',')[1] }}{% endraw %}"
ipv6:
enabled: true
{% else %}
ipv4NativeRoutingCIDR: "{% raw %}{{ k3s_server['cluster-cidr'] }}{% endraw %}"
{% endif %}
k8sServiceHost: "{% raw %}{{ kube_vip_addr }}{% endraw %}"
k8sServicePort: 6443
kubeProxyReplacement: strict
kubeProxyReplacementHealthzBindAddr: 0.0.0.0:10256
{% if bootstrap_ipv6_enabled | default(false) %}
l2announcements:
enabled: false
{% else %}
# https://github.com/cilium/cilium/issues/26586
l2announcements:
enabled: true
leaseDuration: 120s
leaseRenewDeadline: 60s
leaseRetryPeriod: 1s
{% endif %}
loadBalancer:
algorithm: maglev
mode: dsr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ spec:
service:
name: kube-dns
# Choose the 10th IP address from the start of the service-cidr
{% if bootstrap_ipv6_enabled | default(false) %}
clusterIP: "{% raw %}{{ k3s_server['service-cidr'].split(',')[0] | ansible.utils.nthhost(10) }}{% endraw %}"
{% else %}
clusterIP: "{% raw %}{{ k3s_server['service-cidr'] | ansible.utils.nthhost(10) }}{% endraw %}"
{% endif %}
serviceAccount:
create: true
deployment:
Expand Down
9 changes: 8 additions & 1 deletion bootstrap/vars/config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ bootstrap_kube_vip_addr:
bootstrap_k8s_gateway_addr:
# The Load balancer IP for ingress-nginx, choose an available IP in your nodes network that is not being used
bootstrap_ingress_nginx_addr:
# Choose your cluster and service cidrs, leave these unchanged unless you know what you are doing

# Keep the next three options default unless you know what you are doing
# (Advanced) Enable ipv6
bootstrap_ipv6_enabled: false
# (Advanced) For ipv6 use format 10.42.0.0/16,fd78:c889:47fb:10::/60
# /60 IPv6 block is enough for 16 nodes
bootstrap_cluster_cidr: 10.42.0.0/16
# (Advanced) For ipv6 use format 10.43.0.0/16,fd78:c889:47fb:e0::/112
bootstrap_service_cidr: 10.43.0.0/16


# Node information
bootstrap_nodes:
# Use only 1, 3 or more odd master nodes, recommended is 3
Expand Down

0 comments on commit 1d911f6

Please sign in to comment.