Name | Unity ID |
---|---|
Manoj Sharan Gunasegaran | mgunase |
Nivedita Natarajan | nnatara2 |
Pawash Ahuja | pahuja2 |
- Linux Containers
- Container in Bridged Mode
- Container Attached to an OVS Bridge
- Network Configuration
- Demo-App
- Demo-App Screencast
-
Install bridge-utils package.
sudo apt-get install bridge-utils
-
Install the lxc package.
sudo apt-get install lxc
This command creates a lxcbr0 bridge. To verify this, we can run the command:
brctl show
-
Creating a containe(priviliged).
sudo lxc-create –t ubuntu –n container1 r precise
This command creates the container, container1. The network mode by default is NAT. A veth interface will be created on the lxcbr0 bridge for the container. To verify this, we can run the command:
sudo lxc-ls --fancy
To get more information about the container, use the command:
sudo lxc--info –n container1
-
Start the container.
sudo lxc-start –n container1 –d
To verify this, we can run the command:
sudo lxc-ls --fancy
The veth interface is attached to the bridge after the container is started. This can be verified using the command:
brctl show
-
In order to enter the container, use the command:
sudo lxc-attach –n container1
-
Destroying the container can be done using:
sudo lxc-destroy -n container1
This can be verified using the command:
sudo lxc-ls --fancy
A bridge can be used so that many containers can be connected to this bridge. This can be done using the brctl commands.
sudo brctl addbr br0
In order to verify this, we can use the command:
sudo brctl show
- Install the OVS package.
sudo apt-get install openvswitch-switch
This can be verified using the command:
sudo ovs-vsctl show
This command will be able to show the version of OVS since no bridge has been created yet.
- Creating an OVS Bridge
sudo ovs-vsctl add-br ovsbr0
In order to verify this, use the command:
sudo ovs-vsctl show
- Creating the container.
sudo lxc-create –t ubuntu –n C3 r precise
In order to verify this, use the command:
sudo lxc-ls fancy
- Configuration changes
Open the config file for container C3 which is found at /var/lib/lxc/C3/config
and make the following changes:
- Comment out the lxc.network.link line, which is the configuration parameter that causes the container to attach to lxcbr0 bridge in NAT mode or the linux bridge in bridged mode.
# lxc.network.link = lxcbr0
- Next, add a line to run the script after the network interfaces are created. Suppose the script is in
/etc/lxc directory
and it is namedifup
, add the following line:
lxc.network.script.up = /var/lib/lxc/ifup
- Creating the Network Attachment script.
Create a file in /var/lib/lxc
directory named ifup
.
sudo nano /var/lib/lxc/ifup
Add the following lines to the file:
BRIDGE="ovsbr0"
ovs-vsctl --may-exist add-br $BRIDGE
ovs-vsctl --if-exists del-port $BRIDGE $5
ovs-vsctl --may-exist add-port $BRIDGE $5
Also, we must provide proper permissions to the script so that it can be executed when called while starting the container.
The command to give all permissions to the script:
sudo chmod 777 /etc/lxc/ifup
- Start the container.
sudo lxc-start –n C3 –d
In order to verify this, use the command:
sudo lxc-ls fancy
Now, we can see the veth interfaces created and attached to the OVS bridge.
- Add the interface
wlan0
to OpenvSwitch Bridgebr-int
and zero out the eth0 interface.
sudo ovs-vsctl add-port ovsbr0 eth0
sudo ifconfig eth0
- Assign IP to OpenvSwitch Bridge
ovsbr0
sudo ifconfig ovsbr0 10.0.6.1 netmask 255.255.255.0
-
Set up 3 LXC containers using the instructions shown above (including setting IP addresses as shwon below).
-
SSH into LXC container 1 (10.0.3.31) before continuing:
To install Redis Server,
sudo apt-get install redis-server
Then you will need to allow port 6379 used by Redis in the firewall.
sudo iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
Now install node, git & npm using this command,
sudo apt-get install node
(Ubuntu 14.0.4) orsudo apt-get install nodejs
(Ubuntu 16.0.4)sudo apt-get install npm
(if required)sudo apt-get install git
Then git clone this repository and run
npm install
to install all dependencies.Now run the load balancer using
node lxc_main.js
. -
SSH into LXC container 3 (10.0.3.32) and then,
Now install node, git & npm using this command,
sudo apt-get install node
(Ubuntu 14.0.4) orsudo apt-get install nodejs
(Ubuntu 16.0.4)sudo apt-get install npm
(if required)sudo apt-get install git
Then git clone this repository and run
npm install
to install all dependencies.Now run the simple server using
node lxc_container.js
. -
SSH into LXC container 2 (10.0.3.33) and then,
Now install node, git & npm using this command,
sudo apt-get install node
(Ubuntu 14.0.4) orsudo apt-get install nodejs
(Ubuntu 16.0.4)sudo apt-get install npm
(if required)sudo apt-get install git
sudo apt-get install redis-server
Then git clone this repository and run
npm install
to install all dependencies.Next, open up a separate Terminal window and run the redis server using
redis-server
.Now run the simple server using
node lxc_container.js
on containers 2 and 3.Switch to container 1 and then run the proxy server using
node lxc_main.js
.
Note: You can change the predefined output (console.log statement) in lxc_container.js
as needed, to differentiate between Containers 2 and 3.
Please click here to watch the screencast.