A brief introduction to the CNI (Container Network Interface), the implementation of docker bridge network and the CNI usage, including why we develop the CNI, how to use the CNI and what is CNI.
We also introduction the pause container the kubernetes PoD and how to use the CNI in the kubernetes.
In the end, we use the flannel as an example to show how to install the CNI into your kubernetes cluster
5. Before that, we need to quick review
how Docker setup the network for its
container.
6.
7. How Docker Works
✖ Mount namespaces
✖ IPC namespaces
✖ PID namespaces
✖ Network namespaces
✖ User namespaces
✖ UTS namespaces
8. We use the default docker network,
Bridge Mode.
9. ✖ Docker run –p 12345:80 nginx
✖ You can access the nginx via
localhost:12345
✖ The nginx container has the network
connectivity
10. Linux Bridge Network
✖ Create a linux bridge
✖ Create a linux network namespace
✖ Create a veth pair
✖ Attach the veth pair into the
namespace and linux bridge
✖ Set the ip address
✖ Set the route rules
✖ Set the iptables
13. OVS Network
✖ Create a OVS bridge
✖ Create a linux network namespace
✖ Create a veth pair
✖ Attach the veth pair into the
namespace and linux bridge
✖ Set the ip address
✖ Set the route rules
✖ Set the OVS options
14. As a network plugin developer
✖ How many container system
✖ Docker
✖ Rkt
✖ LXC/LXD
✖ OpenVZ
✖ RunC
✖ ….
19. Container Network Interface
✖ Cloud Native Computing Foundation
Project
✖ Consists of a specification and
libraries.
✖ Configure network interfaces in Linux
containers
✖ Concerns itself only with network
connectivity of containers
○ Create/Remove
24. From the GITHUB
rkt - container engine
Kubernetes - a system to simplify container operations
OpenShift - Kubernetes with additional enterprise
features
Cloud Foundry - a platform for cloud applications
Apache Mesos - a distributed systems kernel
Amazon ECS - a highly scalable, high performance
container management service
27. CNI_COMMAND=ADD
CNI_CONTAINERID=ns1
CNI_NETNS=/var/run/netns/ns1
CNI_IFNAME=eth10
CNI_STDIN=….
Take the linux bridge as an example
✖ Create a linux network namespace
✖ Create a linux bridge
✖ Create a veth pair
✖ Attach the veth pair into the
namespace and linux bridge
✖ Set the ip address
✖ Set the route rules
✖ Set the iptables
IPAM
34. Hand by hand
✖ In the kubelet, we have the following
parameters for CNI.
✖ --cni-bin-dir
○ /opt/cni/bin
✖ --cni-conf-dir
○ /etc/cni/net.d/
✖ We should config the CNI for every
k8s nodes.
37. Steps
✖ Load the Pod config
○ Multiple containers
✖ Find a node to deploy the pod
✖ Create a Pause container
✖ Load the CNI config
✖ Execute the CNI
✖ Create target containers and attach to
Pause container
46. flannel
✖ Famous CNI
✖ Created by CoreOS
✖ Layer3 Network (VXLAN, UDP)
○ VXLAN >>>> UDP
○ Kernel Space >>>> User Space
✖ Easy to setup (one yaml)
✖ Centrally manage by etcd/k8s API.
○ For K8S API, we need to set –pod-cidr for
kubelet
47. What is VXLAN
✖ Virtual eXtensible LAN
✖ Overlay network
✖ Based on UDP
48.
49.
50.
51. How it works
192.168.78.2 -> 192.168.87.2Layer 2UDP/VXLAN138.197.204.124 -> 138.68.49.202
Original Packet HeaderAdditional Header
52. ✖ VTEP-1 should know that
that 192.1.87/24 should
forward to 138.68.49.202
✖ VTEP-2 should know that
that 192.1.78/24 should
forward to 138.197.204.124
How it works
53. How vetps knows that
✖ Multicast
✖ L3 Routing
○ BGP
✖ Unicast (Flannel)
○ Event-Driven
■ Listen netlink event
○ Static Setting
■ Just setting rules with timeout
54. Steps by steps about falnnel
✖ Install the kubernetes cluster
✖ Apply the Flannel YAML
○ Deploy a CNI config to all k8s nodes.
55. Before we start
✖ Config Map
○ A global config in whole k8s cluster
✖ DaemonSet
○ A container running on all nodes.
56. ✖ Create a k8s-config-map
✖ cni-conf -> for CNI
✖ net-conf -> for Flanneld
step1
60. step3
✖ Daemon load the net-
conf.json
✖ Get the IP subnet via
etcd/API
✖ Output the file into
/run/flannel/subnet.env
Subnet.env
FLANNEL_NETWORK=10.1.0.0/16
FLANNEL_SUBNET=10.1.17.1/24
FLANNEL_MTU=1472
FLANNEL_IPMASQ=true
61. step4
✖ Fetch the vxlan infor from etcd/API
✖ Create an VXLAN interface
✖ Set the VXLAN routing rules
62. step5
✖ When k8s decides to deploy a POD on this node.
✖ Call the flannel CNI
○ Load the config from the /etc/cni/net.d
○ We copy that files in the daemon set.
✖ The flannel CNI
○ Load the /fun/flannel/subnet.env
○ Get one available IP address and assign to the
PoD
Hung-Wei Chiu (邱宏瑋)
hwchiu@linkernetworks.com
Blog: hwchiu.com
Experience
Software Engineer at Linker Networks
Co-Founder of SDNDS-TW (Software Defined Network)
Co-Found of CUTNG(Cloud Native Taiwan User Group)
Open Source Experience
SDN Related Projects (ONOS/Mininet/Floodlight)
OVS-CNI