kubernetes-training

Process Namespace

Network Namespace

Create network namespace

Connect two interfaces

  1. Make the connection
    • The veth devices are virtual Ethernet devices
    • Add veth-blue interface and veth-red together
       ip link add veth-blue type veth peer name veth-red
      
    • The generic syntax would be:
       ip link add <p1-name> netns <p1-ns> type veth peer <p2-name> netns <p2-ns>
      
  2. Attach interfaces to the namespace they belong to
     ip link set veth-red net-ns red	
     ip link set veth-blue net-ns blue	
    
  3. Set ip addresses to each network interface
    • In red ns: .15.1 is its ip with veth-red interface
    • In blue ns: .15.2 is its ip with veth-blue interface
       ip -n red addr add 198.168.15.1 dev veth-red
       ip -n blue addr add 198.168.15.2 dev veth-blue 
      
  4. Bring the interfaces up
     ip -n red link set veth-red up
     ip -n blue link set veth-blue up
    

Virtual Network Switch

  1. Bring one end of the interface to the namespace, the other end to the virtual switch
    ip link set veth-red netns red
    ip link set veth-red-br master v-net-0
    

[!Note]
ip link set, when used with master, it associates a network device (like a virtual interface) with a bridge, effectively adding it to the bridge

  1. Add ip adresses associate with each network interface
    ip -n red addr add 192.168.15.1 dev veth-red
    ip -n blue addr add 192.168.15.2 dev veth-blue
    
  2. Bring the interfaces up
    ip -n red link set veth-red up
    ip -n blue link set veth-blue up
    

[!Important] The network that contains veth-red, veth-blue and v-net-0 for the virtual switch are isolated. That is, if the host try to ping one of the namespaces, it’s not reachable Nothing from the outside world can reach this namespace and vice versa

NAT

- Add destination ip to routing table of the network namespace: 
```bash
ip netns exec blue ip route add 192.168.1.0/24 via 192.168.15.5

[!Reminder] 192.168.15.5 is the ip address assigned to v-net-0 interface

Connect to the internet

ip netns exec blue ping 8.8.8.8

Hosts connect to network namespace