From b6f4464b4cf611cb77c6339215147a3feda8962f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Sat, 7 Oct 2023 18:07:19 +0800 Subject: [PATCH] Makefile: create bgp HA environment with clab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张祖建 --- .gitignore | 1 + Makefile | 46 ++++++++++++++++-- yamls/clab-bgp-ha.yaml.j2 | 98 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 yamls/clab-bgp-ha.yaml.j2 diff --git a/.gitignore b/.gitignore index 3ec002f1f3b7..b2ef3ccdf845 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ broker-info.subm broker-info.subm.* broker-info-internal.subm yamls/clab-bgp.yaml +yamls/clab-bgp-ha.yaml kube-ovn.tar vpc-nat-gateway.tar image-amd64.tar diff --git a/Makefile b/Makefile index fc0895c92616..5c7c1ff43e24 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,19 @@ kind-init-bgp: kind-clean-bgp kind-init -v $(CURDIR)/yamls/clab-bgp.yaml:/clab.yaml \ $(CLAB_IMAGE) clab deploy -t /clab.yaml +.PHONY: kind-init-bgp-ha +kind-init-bgp-ha: kind-clean-bgp kind-init + kube_ovn_version=$(VERSION) j2 yamls/clab-bgp-ha.yaml.j2 -o yamls/clab-bgp-ha.yaml + docker run --rm --privileged \ + --name kube-ovn-bgp \ + --network host \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /var/run/netns:/var/run/netns \ + -v /var/lib/docker/containers:/var/lib/docker/containers \ + --pid=host \ + -v $(CURDIR)/yamls/clab-bgp-ha.yaml:/clab.yaml \ + $(CLAB_IMAGE) clab deploy -t /clab.yaml + .PHONY: kind-load-image kind-load-image: $(call kind_load_image,kube-ovn,$(REGISTRY)/kube-ovn:$(VERSION)) @@ -793,6 +806,17 @@ kind-install-bgp: kind-install kubectl apply -f - kubectl -n kube-system rollout status ds kube-ovn-speaker --timeout 60s +.PHONY: kind-install-bgp-ha +kind-install-bgp-ha: kind-install + kubectl label node --all ovn.kubernetes.io/bgp=true + kubectl annotate subnet ovn-default ovn.kubernetes.io/bgp=local + sed -e 's#image: .*#image: $(REGISTRY)/kube-ovn:$(VERSION)#' \ + -e 's/--neighbor-address=.*/--neighbor-address=10.0.1.1,10.0.1.2/' \ + -e 's/--neighbor-as=.*/--neighbor-as=65001/' \ + -e 's/--cluster-as=.*/--cluster-as=65002/' yamls/speaker.yaml | \ + kubectl apply -f - + kubectl -n kube-system rollout status ds kube-ovn-speaker --timeout 60s + .PHONY: kind-install-deepflow kind-install-deepflow: kind-install helm repo add deepflow $(DEEPFLOW_CHART_REPO) @@ -845,9 +869,8 @@ kind-clean-ovn-submariner: kind-clean kind delete cluster --name=kube-ovn1 .PHONY: kind-clean-bgp -kind-clean-bgp: - $(call docker_rm_container,kube-ovn-bgp) - kube_ovn_version=$(RELEASE_TAG) j2 yamls/clab-bgp.yaml.j2 -o yamls/clab-bgp.yaml +kind-clean-bgp: kind-clean-bgp-ha + kube_ovn_version=$(VERSION) j2 yamls/clab-bgp.yaml.j2 -o yamls/clab-bgp.yaml docker run --rm --privileged \ --name kube-ovn-bgp \ --network host \ @@ -859,6 +882,20 @@ kind-clean-bgp: $(CLAB_IMAGE) clab destroy -t /clab.yaml @$(MAKE) kind-clean +.PHONY: kind-clean-bgp-ha +kind-clean-bgp-ha: + kube_ovn_version=$(VERSION) j2 yamls/clab-bgp-ha.yaml.j2 -o yamls/clab-bgp-ha.yaml + docker run --rm --privileged \ + --name kube-ovn-bgp \ + --network host \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /var/run/netns:/var/run/netns \ + -v /var/lib/docker/containers:/var/lib/docker/containers \ + --pid=host \ + -v $(CURDIR)/yamls/clab-bgp-ha.yaml:/clab.yaml \ + $(CLAB_IMAGE) clab destroy -t /clab.yaml + @$(MAKE) kind-clean + .PHONY: uninstall uninstall: bash dist/images/cleanup.sh @@ -901,7 +938,8 @@ ipam-bench: .PHONY: clean clean: $(RM) dist/images/kube-ovn dist/images/kube-ovn-cmd - $(RM) yamls/kind.yaml yamls/clab-bgp.yaml + $(RM) yamls/kind.yaml + $(RM) yamls/clab-bgp.yaml yamls/clab-bgp-ha.yaml $(RM) ovn.yaml kube-ovn.yaml kube-ovn-crd.yaml $(RM) ovn-ic-0.yaml ovn-ic-1.yaml $(RM) kustomization.yaml kwok.yaml kwok-node.yaml diff --git a/yamls/clab-bgp-ha.yaml.j2 b/yamls/clab-bgp-ha.yaml.j2 new file mode 100644 index 000000000000..f225fc9919e9 --- /dev/null +++ b/yamls/clab-bgp-ha.yaml.j2 @@ -0,0 +1,98 @@ +name: bgp +topology: + kinds: + linux: + image: kubeovn/kube-ovn:{{ kube_ovn_version }} + cmd: bash + + nodes: + switch: + kind: linux + exec: + - ip link add br0 type bridge + - ip link set net1 master br0 + - ip link set net2 master br0 + - ip link set net3 master br0 + - ip link set net4 master br0 + - ip link set net5 master br0 + - ip link set net6 master br0 + - ip link set net7 master br0 + - ip link set br0 up + router-1: + kind: linux + image: frrouting/frr:v8.4.1 + labels: + app: frr + exec: + - ip link delete eth0 + - ip address add 10.0.1.1/24 dev net1 + - ip address add 10.0.2.1/24 dev net2 + - touch /etc/frr/vtysh.conf + - sed -i -e 's/bgpd=no/bgpd=yes/g' /etc/frr/daemons + - /usr/lib/frr/frrinit.sh start + - >- + vtysh -c 'conf t' + -c 'frr defaults datacenter' + -c 'router bgp 65001' + -c ' bgp router-id 10.0.1.1' + -c ' no bgp ebgp-requires-policy' + -c ' neighbor SERVERS peer-group' + -c ' neighbor SERVERS remote-as external' + -c ' neighbor 10.0.1.101 peer-group SERVERS' + -c ' neighbor 10.0.1.102 peer-group SERVERS' + -c ' address-family ipv4 unicast' + -c ' redistribute connected' + -c ' exit-address-family' + -c '!' + router-2: + kind: linux + image: frrouting/frr:v8.4.1 + labels: + app: frr + exec: + - ip link delete eth0 + - ip address add 10.0.1.2/24 dev net1 + - ip address add 10.0.2.2/24 dev net2 + - touch /etc/frr/vtysh.conf + - sed -i -e 's/bgpd=no/bgpd=yes/g' /etc/frr/daemons + - /usr/lib/frr/frrinit.sh start + - >- + vtysh -c 'conf t' + -c 'frr defaults datacenter' + -c 'router bgp 65001' + -c ' bgp router-id 10.0.1.2' + -c ' no bgp ebgp-requires-policy' + -c ' neighbor SERVERS peer-group' + -c ' neighbor SERVERS remote-as external' + -c ' neighbor 10.0.1.101 peer-group SERVERS' + -c ' neighbor 10.0.1.102 peer-group SERVERS' + -c ' address-family ipv4 unicast' + -c ' redistribute connected' + -c ' exit-address-family' + -c '!' + k8s-master: + kind: linux + network-mode: container:kube-ovn-control-plane + exec: + - ip address add 10.0.1.101/24 dev net1 + - ip route add 10.0.0.0/16 via 10.0.1.1 + k8s-worker: + kind: linux + network-mode: container:kube-ovn-worker + exec: + - ip address add 10.0.1.102/24 dev net1 + - ip route add 10.0.0.0/16 via 10.0.1.1 + ext: + kind: linux + exec: + - ip address add 10.0.2.101/24 dev net1 + - ip route replace default nexthop via 10.0.2.1 weight 1 nexthop via 10.0.2.2 weight 1 + + links: + - endpoints: ["switch:net1", "router-1:net1"] + - endpoints: ["switch:net2", "router-1:net2"] + - endpoints: ["switch:net3", "router-2:net1"] + - endpoints: ["switch:net4", "router-2:net2"] + - endpoints: ["switch:net5", "k8s-master:net1"] + - endpoints: ["switch:net6", "k8s-worker:net1"] + - endpoints: ["switch:net7", "ext:net1"]