Mininet + K3S

Based on nginx-rtmp docker and k3s, I write this lab.








This example shows how to create a simple network and

how to create docker containers (based on existing images)

to it.



from import Containernet

from mininet.node import Controller, Docker, OVSSwitch

from mininet.cli import CLI

from mininet.log import setLogLevel, info

from import TCLink, Link



def topology():


    "Create a network with some docker containers acting as hosts."


    net = Containernet(controller=Controller)


    info('*** Adding hosts\n')

    h1 = net.addHost('h1', ip="")

    h2 = net.addHost('h2', ip="")

    h3 = net.addHost('h3', ip="")


    info('*** Adding docker containers\n')

    d1 = net.addDocker('d1', dimage="busybox:v1")


    info('*** Creating links\n')

    net.addLink(h1, d1)

    net.addLink(h2, d1)

    net.addLink(h3, d1)

    info('*** Starting network\n')




    d1.cmd("ifconfig d1-eth0 0")

    d1.cmd("ifconfig d1-eth1 0")

    d1.cmd("ifconfig d1-eth2 0")

    d1.cmd("ip addr add brd + dev d1-eth0")

    d1.cmd("ip addr add brd + dev d1-eth1")

    d1.cmd("ip addr add brd + dev d1-eth2")

    d1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")

    h1.cmd("ip route add default via")

    h2.cmd("ip route add default via")

    h3.cmd("ip route add default via")

    info('*** Running CLI\n')



    info('*** Stopping network')



if __name__ == '__main__':





For k3s part


Routing should be set manually.



For mininet part (you need dockernet to run this example)


Open terminal for h1, h2, h3


Prepare a test.mp4 for h1 and streaming video (test.mp4) to nginx-rtmp server (


For h2, h3, use ffplay to play video



(one terminal is for h2 and the other one is for h3)


Dr. Chih-Heng Ke (

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.