Byeo

OvS를 이용한 namespace간 VxLAN 통신 본문

프로그래밍 (Programming)/컴퓨터 네트워크 - 학부 외

OvS를 이용한 namespace간 VxLAN 통신

BKlee 2023. 10. 14. 14:35
반응형

구조

 

 

VM에 OvS 설치

- 두 개의 instance내에 각각 생성된 namespace를 서로 OvS의 VxLAN 기능을 이용해 통신을 시키는 실습을 수행해보려고 합니다.

- 환경은 NHN Cloud입니다.

1. Instance 2개에 각각 Open vSwitch 설치

 - 두 인스턴스에 각각 openvswitch-switch를 설치합니다.

 인스턴스 1: byeo-test, ip: 192.168.0.83

 인스턴스 2: byeo-test2, ip: 192.168.0.33

 

# 이후의 모든 명령어는 root 권한에서 실행
apt update
apt install openvswitch-switch

 

설치 확인

root@byeo-test:/home/ubuntu# ovs-vsctl show
c6c5d044-4a41-4f84-9c6e-2c755ebdf674
    ovs_version: "2.13.8"

 

2. Namespace 생성

- 두 인스턴스 내에 namespace를 생성하고, veth로 연결합니다.

* 인스턴스 1

ip netns add bkns0
ip link add veth0 type veth peer name veth1
ip link set veth1 netns bkns0

* 인스턴스 2

ip netns add bkns1
ip link add veth2 type veth peer name veth3
ip link set veth3 netns bkns1

* namespace link확인

root@byeo-test:/home/ubuntu# ip netns exec bkns0 ip link
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: veth1@if4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 5e:95:a0:66:1d:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0

 

3. IP address 할당

- namespace 내에 있는 veth link에 ip address를 부여합니다. 그 다음, namespace에서의 기본 라우팅테이블을 기존에 생성했던 veth로 지정합니다.

* 인스턴스 1

ip netns exec bkns0 ip addr add 172.16.100.11/24 dev veth1
ip netns exec bkns0 ip r add default dev veth1

* 인스턴스 2

ip netns exec bkns1 ip addr add 172.16.101.11/24 dev veth3
ip netns exec bkns1 ip r add default dev veth3


4. Link 활성화

- 모든 link를 활성화합니다.

* 인스턴스 1

ip link set dev veth0 up
ip netns exec bkns0 ip link set veth1 up

* 인스턴스 2

ip link set dev veth2 up
ip netns exec bkns1 ip link set veth3 up

 

5. OvS Bridge 생성

- 두 인스턴스에 namespace를 연결시켜 줄 bridge를 생성합니다.

* 인스턴스 1

ovs-vsctl add-br br0

* 인스턴스 2

ovs-vsctl add-br br1

 

6. OvS Port 추가

- 각 bridge에 port를 추가합니다.

* 인스턴스 1

ovs-vsctl add-port br0 veth0

 

* 인스턴스 2

ovs-vsctl add-port br1 veth2

 

7. Vxlan Port 추가

- 각 bridge에 서로의 인스턴스를 연결시켜 줄 vxlan port를 추가합니다. local_ip는 인스턴스의 private ip, remote_ip는 상대 인스턴스의 private ip, key는 vni (virtual network identifier)를 입력합니다.

* 인스턴스 1

ovs-vsctl add-port br0 vxlan0 -- set Interface vxlan0 type=vxlan options:local_ip=192.168.0.83 options:remote_ip=192.168.0.33 options:key=231014

* 인스턴스 2

ovs-vsctl add-port br1 vxlan1 -- set Interface vxlan1 type=vxlan options:local_ip=192.168.0.33 options:remote_ip=192.168.0.83 options:key=231014

 

8. Flow Table설정

- ovs flow table에서 packet이 어느 port로 들어왔냐에 따라 어디로 내보낼지 정하는 규칙을 추가합니다.

* 인스턴스 1

ovs-ofctl add-flow br0 table=0,in_port="veth0",priority=100,actions=output:"vxlan0"
ovs-ofctl add-flow br0 table=0,in_port="vxlan0",priority=100,actions=output:"veth0"

* 인스턴스 2

ovs-ofctl add-flow br1 table=0,in_port="veth2",priority=100,actions=output:"vxlan1"
ovs-ofctl add-flow br1 table=0,in_port="vxlan1",priority=100,actions=output:"veth2"

 

9. 확인

- Ovs 설정이 잘 되었는지 확인해봅니다.

* ovs-vsctl show

root@byeo-test:/home/ubuntu# ovs-vsctl show
c6c5d044-4a41-4f84-9c6e-2c755ebdf674
    Bridge br0
        Port vxlan0
            Interface vxlan0
                type: vxlan
                options: {key="231014", local_ip="192.168.0.83", remote_ip="192.168.0.33"}
        Port veth0
            Interface veth0
        Port br0
            Interface br0
                type: internal
    ovs_version: "2.13.8"

 

* ovs-ofctl dump-flows

root@byeo-test:/home/ubuntu# ovs-ofctl dump-flows br0
 cookie=0x0, duration=205.991s, table=0, n_packets=30, n_bytes=1260, in_port=veth0 actions=output:vxlan0
 cookie=0x0, duration=108.658s, table=0, n_packets=0, n_bytes=0, priority=100,in_port=vxlan0 actions=output:veth0
 cookie=0x0, duration=927.178s, table=0, n_packets=5, n_bytes=266, priority=0 actions=NORMAL

 

10. ping test

root@byeo-test:/home/ubuntu# ip netns exec bkns0 ping 172.16.101.11
PING 172.16.101.11 (172.16.101.11) 56(84) bytes of data.
64 bytes from 172.16.101.11: icmp_seq=1 ttl=64 time=3.01 ms
64 bytes from 172.16.101.11: icmp_seq=2 ttl=64 time=0.454 ms
64 bytes from 172.16.101.11: icmp_seq=3 ttl=64 time=0.490 ms
64 bytes from 172.16.101.11: icmp_seq=4 ttl=64 time=0.388 ms
64 bytes from 172.16.101.11: icmp_seq=5 ttl=64 time=0.538 ms
^C
--- 172.16.101.11 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4053ms
rtt min/avg/max/mdev = 0.388/0.975/3.009/1.017 ms

 

 

기타 확인 필요 사항

VxLAN은 UDP 4789 port를 사용합니다. 인스턴스의 security group에서 UDP 4789 port를 허용하고 있는지 확인합니다.






참고자료
https://www.44bits.io/ko/post/container-network-2-ip-command-and-network-namespace
https://atl.kr/dokuwiki/doku.php/openvswitch%EB%A5%BC_%ED%86%B5%ED%95%9C_vxlan_%EA%B5%AC%EC%84%B1

반응형
Comments