Skip to content

Commit

Permalink
Merge pull request #217 from ictsc/delete-router
Browse files Browse the repository at this point in the history
L2 Announcementを導入
  • Loading branch information
logica0419 authored Oct 21, 2024
2 parents bdc01f5 + 715f909 commit dfda30d
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 413 deletions.
2 changes: 1 addition & 1 deletion ansible/inventory/group_vars/control_plane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ netplan_configuration:
ethernets:
eth1:
addresses:
- 192.168.100.2{{groups["control_plane"].index(inventory_hostname)}}/24
- 192.168.100.{{ groups["control_plane"].index(inventory_hostname) + 1 }}/24

# k8s_joinロール用
k8s_join_flag: --control-plane --certificate-key {{ hostvars[groups['control_plane'][0]]['certs'] }}
12 changes: 0 additions & 12 deletions ansible/inventory/group_vars/router.yaml

This file was deleted.

30 changes: 12 additions & 18 deletions ansible/inventory/inventory_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def main():
inventory = {
"control_plane": {"hosts": []},
"worker_node": {"hosts": []},
"router": {"hosts": []},
"_meta": {"hostvars": {}},
}
workspace = get_workspace()
Expand All @@ -50,15 +49,12 @@ def main():
#
# print(tfstate["outputs"])

router = 0
control_plane = 0
worker_node = 0
inventory_gp = {}

for output_key in tfstate["outputs"]:
match output_key:
case "k8s_router_ip_address":
inventory_gp = inventory["router"]
case "k8s_control_plane_ip_address":
inventory_gp = inventory["control_plane"]
case "k8s_worker_node_ip_address":
Expand All @@ -69,48 +65,46 @@ def main():
for ip_address in tfstate["outputs"][output_key]["value"]:
# not handle private ip address
if (
ip_address[:11] == "192.168.100"
and output_key != "k8s_worker_node_ip_address"
ip_address[:7] == "192.168"
and output_key == "k8s_control_plane_ip_address"
):
continue

inventory_gp["hosts"].append(ip_address)

match output_key:
case "k8s_router_ip_address":
inventory["_meta"]["hostvars"] = inventory["_meta"]["hostvars"] | {
ip_address: {"internal_ip": f"192.168.100.1{str(router)}"}
}
router += 1
case "k8s_control_plane_ip_address":
inventory["_meta"]["hostvars"] = inventory["_meta"]["hostvars"] | {
ip_address: {
"internal_ip": f"192.168.100.2{str(control_plane)}"
"internal_ip": f"192.168.100.{str(control_plane + 1)}"
}
}
control_plane += 1
case "k8s_worker_node_ip_address":
inventory["_meta"]["hostvars"] = inventory["_meta"]["hostvars"] | {
ip_address: {"internal_ip": f"192.168.100.3{str(worker_node)}"}
ip_address: {
"internal_ip": f"192.168.100.3{str(worker_node + 101)}"
}
}
worker_node += 1

inventory["router"]["vars"] = {
"bgp_address": tfstate["outputs"]["external_address_range"]["value"]
}
inventory["control_plane"]["vars"] = {
"VIP": tfstate["outputs"]["vip_address"]["value"]
}
inventory["worker_node"]["vars"] = {
"ansible_ssh_common_args": (
"-o ProxyCommand='ssh -o ControlMaster=auto -o ControlPersist=60s "
"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "
f"-i ../id_rsa -W %h:%p ubuntu@{inventory['router']['hosts'][0]}'"
f"-i ../id_rsa -W %h:%p ubuntu@{inventory['control_plane']['hosts'][0]}'"
)
}
inventory["delegate_plane"] = {
"hosts": [inventory["control_plane"]["hosts"][0]],
"vars": {"workspace": workspace},
"vars": {
"workspace": workspace,
"min_ip_address": tfstate["outputs"]["min_ip_address"]["value"],
"max_ip_address": tfstate["outputs"]["max_ip_address"]["value"],
},
}

print(json.dumps(inventory))
Expand Down
8 changes: 0 additions & 8 deletions ansible/roles/bird/handlers/main.yaml

This file was deleted.

47 changes: 0 additions & 47 deletions ansible/roles/bird/tasks/main.yaml

This file was deleted.

170 changes: 0 additions & 170 deletions ansible/roles/bird/templates/bird.conf.j2

This file was deleted.

4 changes: 0 additions & 4 deletions ansible/roles/bird/vars/main.yaml

This file was deleted.

15 changes: 8 additions & 7 deletions ansible/roles/components/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
- name: Deploy Cilium
ansible.builtin.shell: |
helm upgrade --install cilium cilium/cilium --namespace kube-system \
--set kubeProxyReplacement=true --set k8sServiceHost={{ VIP }} --set k8sServicePort=8443 --set bgpControlPlane.enabled=true
--set kubeProxyReplacement=true --set k8sServiceHost={{ VIP }} --set k8sServicePort=8443 \
--set l2announcements.enabled=true --set k8sClientRateLimit.qps=40 --set k8sClientRateLimit.burst=50
changed_when: false
- name: Restart pods
ansible.builtin.shell:
Expand All @@ -47,15 +48,15 @@
changed_when: false
failed_when: false

- name: Setup BGP
- name: Setup L2 announcement
block:
- name: Send bgp-config
- name: Send announcement config
ansible.builtin.template:
src: bgp-config.yaml.j2
dest: /tmp/bgp-config.yaml
src: announcement-config.yaml.j2
dest: /tmp/announcement-config.yaml
mode: "0644"
- name: Apply bgp-config
ansible.builtin.command: kubectl apply -f /tmp/bgp-config.yaml
- name: Apply announcement config
ansible.builtin.command: kubectl apply -f /tmp/announcement-config.yaml
register: ret
until: ret.rc == 0
retries: 12
Expand Down
22 changes: 22 additions & 0 deletions ansible/roles/components/templates/announcement-config.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: cilium.io/v2alpha1
kind: CiliumL2AnnouncementPolicy
metadata:
name: cilium-announcement
spec:
nodeSelector:
matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
interfaces:
- ^eth[0-9]+
loadBalancerIPs: true
---
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
name: default-pool
namespace: kube-system
spec:
blocks:
- start: {{ min_ip_address }}
stop: {{ max_ip_address }}
Loading

0 comments on commit dfda30d

Please sign in to comment.