Code Monkey home page Code Monkey logo

cni-terway's Introduction

cni-terway

此插件借助kubernetescni插件中的bridgedhcp, 实现了类似于虚拟机的桥接模式网络.

在此网络模型下创建的Pod可以获得宿主机网络的IP, Pod与宿主机网络中的主机可以直接通信.

此插件的工作流程十分简单, 只有如下两步:

  1. 创建bridge接口, 连接物理网卡与bridge, 然后修改路由(从物理网卡改为通过bridge设备);
  2. 启动dhcp服务守护进程(其实dhcp插件在工程代码中就给出了.service服务脚本, 本来建议使用systemctl将其作为服务启动的, 但是我更希望在Pod中集成这样的功能, 减少多余的操作).

使用方法

修改kube-cni.yaml文件中的--iface选项为宿主机的主网卡名称(一般是eth0), 然后使用kubectl apply -f kube-cni.yaml即可.

适用环境

本插件应该算是Underlay L2的解决方案, 不适用于各种云环境, 而适用于自建IDC, Esxi虚拟机集群(需要交换机开启混杂模式), 本地Vmware虚拟机等场景.

网络拓扑变化

1.

+-----------------------------------------------------------+
|  +-----------------------------------------------------+  |
|  |                 Newwork Protocol Stack              |  |
|  +------↑-----------------------↑-------------------↑--+  |
|         |                       |                   |     |
|.........|.......................|...................|.....|
|         |                       |                   |     |
|         |         +--------+    |    +--------+     |     |
|         |         |  pod1  |    |    |  pod2  |     |     |
|         |         +----↑---+    |    +---↑----+     |     |
|         |              └─────┐  |  ┌─────┘          |     |
| +-------↓-------+         +--↓--↓--↓--+          ***↓**** |
| |      eth0     |         |   mybr0   |          * dhcp * |
| |192.168.0.10/24|         +-----------+          ***↓**** |
| +-------↑-------+                                         |
+---------|-------------------------------------------------+
          ↓

2.

+-----------------------------------------------------------+
|  +-----------------------------------------------------+  |
|  |                 Newwork Protocol Stack              |  |
|  +------------------------------↑-------------------↑--+  |
|                                 |                   |     |
|.................................|...................|.....|
|                                 |                   |     |
|                   +--------+    |    +--------+     |     |
|                   |  pod1  |    |    |  pod2  |     |     |
|                   +----↑---+    |    +---↑----+     |     |
|                        └─────┐  |  ┌─────┘          |     |
|                         +----↓--↓--↓----+           |     |
|   +-----------+         |     mybr0     |        ***↓**** |
|   |   eth0    |<------->|192.168.0.10/24|        * dhcp * |
|   +-----↑-----+         +---------------+        ******** |
+---------|-------------------------------------------------+
          ↓

在此网络模式中, 物理网卡eth0退化为一条网线, 由mybr0接管其原有IP, 对外连接物理网络, 各节点之间相当于通过交换机直接相连.

注意

由于此插件使用桥接网络, 所以会使kubeadm --config配置文件中的networking.podSubnet字段(或是--pod-network-cidr选项)失效.

在这种模式下, ServiceIP就会变得没有意义(虽然仍然有效).

开发流程

编译

$ go build -o terway main.go
$ go build -o cni-terway ./cni/main.go

cni-terway's People

Contributors

generals-space avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.