Skip to content

Commit

Permalink
Makefile: create bgp HA environment with clab
Browse files Browse the repository at this point in the history
Signed-off-by: 张祖建 <[email protected]>
  • Loading branch information
zhangzujian committed Oct 7, 2023
1 parent 7bd415c commit b6f4464
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 42 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
98 changes: 98 additions & 0 deletions yamls/clab-bgp-ha.yaml.j2
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit b6f4464

Please sign in to comment.