[docker] macvlan最佳实战
macvlan和ipvlan的对比
http://hicu.be/macvlan-vs-ipvlan
macvlan
ipvlan
参考:
https://yq.aliyun.com/articles/192998
http://hicu.be/docker-networking-macvlan-bridge-mode-configuration
https://sreeninet.wordpress.com/2016/05/29/docker-macvlan-and-ipvlan-network-plugins/
echo 1 > /proc/sys/net/ipv4/ip_forward
- 创建macvlan网络
docker network create -d macvlan \
--subnet=192.168.14.0/24 \
--gateway=192.168.14.2 \
-o parent=eth0 mac_net1
docker run -itd --name b1 --ip=192.168.14.11 --network mac_net1 busybox
docker run -itd --name b2 --ip=192.168.14.12 --network mac_net1 busybox
- b2 ping b1(外网)是通的
$ docker exec b2 ping 192.168.14.11
PING 192.168.14.11 (192.168.14.11): 56 data bytes
64 bytes from 192.168.14.11: seq=0 ttl=64 time=0.062 ms
- b2 ping 宿主机ip,不通
$ docker exec b2 ping 192.168.14.133
^C
- 未创建新的网桥
[root@n2 ~]# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.024243c0f3d5 no
- mac地址和ip均不同
$ docker exec b1 ip a
39: eth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:c0:a8:0e:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.14.11/24 scope global eth0
valid_lft forever preferred_lft forever
$ docker exec b2 ip a
40: eth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:c0:a8:0e:0c brd ff:ff:ff:ff:ff:ff
inet 192.168.14.12/24 scope global eth0
valid_lft forever preferred_lft forever
$ ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:50:56:33:13:b6 brd ff:ff:ff:ff:ff:ff
访问:
参考: http://hicu.be/docker-networking-macvlan-bridge-mode-configuration
总结
容器的 interface 直接与主机的网卡连接,这种方案使得容器无需通过 NAT 和端口映射就能与外网直接通信(只要有网关),在网络上与其他独立主机没有区别。
这里有个hairpin mode 模式,对比下bridge
参考: http://cizixs.com/2017/02/14/network-virtualization-macvlan
macvaln的几种模式,一般我们用桥接即可.
https://hicu.be/bridge-vs-macvlan
$ brctl add help
never heard of command [add]
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
hairpin <bridge> <port> {on|off} turn hairpin on/off
bridge
vepa(Virtual Ethernet Port Aggregator) mode: 需要主接口连接的交换机支持 VEPA/802.1Qbg 特性。所有发送出去的报文都会经过交换机,交换机作为再发送到对应的目标地址(即使目标地址就是主机上的其他 macvlan 接口),也就是 hairpin mode 模式,这个模式用在交互机上需要做过滤、统计等功能的场景。
Macvlan 802.1q Trunk Bridge 模式使用示例
参考: https://yq.aliyun.com/articles/192998
docker network create -d macvlan \
--subnet=192.168.14.0/24 \
--gateway=192.168.14.1 \
-o parent=eth0.50 macvlan50
docker rm -fv b1 b2
docker run --net=macvlan50 -itd --name b1 busybox
docker run --net=macvlan50 -itd --name b2 busybox
docker network create -d macvlan \
--subnet=192.168.15.0/24 \
--gateway=192.168.15.1 \
-o parent=eth0.60 macvlan60
docker rm -fv b3 b4
docker run --net=macvlan60 -itd --name b3 busybox
docker run --net=macvlan60 -itd --name b4 busybox
多个子网的 Macvlan 802.1q Trunking
docker network create -d ipvlan \
--subnet=192.168.210.0/24 \
--subnet=192.168.212.0/24 \
--gateway=192.168.210.254 \
--gateway=192.168.212.254 \
-o ipvlan_mode=l2 ipvlan210
# 测试 192.168.210.0/24 容器间连接性
docker run --net=ipvlan210 --ip=192.168.210.10 -itd alpine /bin/sh
docker run --net=ipvlan210 --ip=192.168.210.9 -it --rm alpine ping -c 2 192.168.210.10
# 测试 192.168.212.0/24 容器间连接性
docker run --net=ipvlan210 --ip=192.168.212.10 -itd alpine /bin/sh
docker run --net=ipvlan210 --ip=192.168.212.9 -it --rm alpine ping -c 2 192.168.212.10
创建多个子网网段的macvlan网络
docker network create -d macvlan \
--subnet=192.168.216.0/24 \
--gateway=192.168.216.1 \
--subnet=192.168.218.0/24 \
--gateway=192.168.218.1 \
-o parent=eth0.218 \
-o macvlan_mode=bridge macvlan216
# 在第一个192.168.216.0/24网段创建一个容器
docker run --net=macvlan216 --name=macnet216_test --ip=192.168.216.10 -itd busybox
# 在第二个192.168.218.0/24网段创建容器
docker run --net=macvlan216 --name=macnet218_test --ip=192.168.218.10 -itd busybox
# 通过192.168.216.0/24的网段的容器Ping 在192.168.216.0/24网段中的第一个容器
docker run --net=macvlan216 --ip=192.168.216.11 -it --rm busybox
ping 192.168.216.10
# 通过192.168.218.0/24的网段的容器Ping 在192.168.218.0/24网段中的第一个容器
docker run --net=macvlan216 --ip=192.168.218.11 -it --rm busybox
ping 192.168.218.10
[docker] macvlan最佳实战的更多相关文章
- 最佳实战Docker持续集成图文详解
最佳实战Docker持续集成图文详解 这是一种真正的容器级的实现,这个带来的好处,不仅仅是效率的提升,更是一种变革:开发人员第一次真正为自己的代码负责——终于可以跳过运维和测试部门,自主维护运行环境( ...
- k8s pod的4种网络模式最佳实战(externalIPs )
[k8s]k8s pod的4种网络模式最佳实战(externalIPs ) hostPort相当于docker run -p 8081:8080,不用创建svc,因此端口只在容器运行的vm ...
- Docker小白到实战之Docker网络简单了解一下
前言 现在对于Docker容器的隔离性都有所了解了,但对容器IP地址的分配.容器间的访问等还是有点小疑问,如果容器的IP由于新启动导致变动,那又怎么才能保证原有业务不会被影响,这就和网络有挂钩了,接下 ...
- 云计算Docker全面项目实战(Maven+Jenkins、日志管理ELK、WordPress博客镜像)
2013年,云计算领域从此多了一个名词“Docker”.以轻量著称,更好的去解决应用打包和部署.之前我们一直在构建Iaas,但通过Iaas去实现统一功 能还是相当复杂得,并且维护复杂.将特殊性封装到 ...
- Docker Macvlan 介绍 or 工作原理
Docker Macvlan Network Macvlan Network:属于Docker的网络驱动. Macvlan Network:Docker主机网卡接口逻辑上分为多个子接口,每个子接口标识 ...
- Docker Macvlan 应用部署
Docker Macvlan 应用部署 MacVLAN有两种桥接模式 Bridge模式:不创建子接口的情况下直接去桥接物理接口.直接桥接到与宿主级的同网段. VLAN Bridge模式:创建子接口去桥 ...
- [svc]NFS存储企业场景及nfs最佳实战探究
办公网络里人一般系统用共享,尤其是财务, 他们喜欢直接点开编辑. 而不喜欢ftp nfs在网站架构中的用途 注: 如果pv量少,则放在一台机器上速度更快,如果几千万pv,则存储分布式部署. 网站架构中 ...
- Docker Macvlan
参考博客:https://blog.csdn.net/daye5465/article/details/77412619 一.Macvlan 交换机的vlan是根据端口来划分的,如果一个PC接入vla ...
- vue2 入门 教程 单页应用最佳实战[*****]
推荐 vue2 入门 教程 -------- 看过其他的,再看作者的,很赞 vue2 入门 教程 单页应用最佳实战 : 具体在 https://github.com/MeCKodo/vue-tuto ...
随机推荐
- Android 之 tools:context和tools:ignore两个属性的作用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- centos7.2下安装Mysql笔记
centos7.2下安装Mysql笔记 安装 MySQL 适用于 CentOS 7.0 或以后版本: yum install mariadb mariadb-server 适用于 CentOS 6.8 ...
- web扫描工具-Nikto介绍与使用
Nikto Perl语言开发的开源Web安全扫描器 web扫描模式:截断代理主动扫描 可以扫描的方面:软件版本搜索存在安全隐患的文件服务器配置漏洞WEB Application层面的安全隐患避免404 ...
- internet连接共享
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_shai nternet连接共享 允许其他网络用户通过此计算机的internet连接来连接
- bootsrap中的输入框demo1
<!doctype html><html > <head> <meta charset="utf-8"> <link rel= ...
- BZOJ1166 : [Baltic2008]Magical Stones
考虑二分答案,转化为求有多少$\leq lim$的数满足条件. 从两侧往中间进行数位DP,设$f[l][r][j][x][y][z][pre][suf]$表示当前准备填的两个位置是$l$和$r$,已经 ...
- Centos7 MongoDB-3.4
MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的 关系型数据库遵循ACID规则 事务在英文中是transaction,和现实世界中的交易很类 ...
- oracle多个结果集拼接字符串;where id in 字符串 (转)
转自:http://blog.sina.com.cn/s/blog_af26e333010194ht.html 最近修改oracle触发器,在过程中遇到两个问题: select lastname fr ...
- JDBC(7)—DAO
介绍: DAO(Data Access Object):数据访问对象 1.what:访问数据信息的类,包含了对数据的CRUD(create read.update.delete),而不包含业务相关的信 ...
- 集合(2)—Collection之List的使用方法
声明集合变量 List list = new ArrayList(); 或者 : public LIst list: public 构造函数(){ this.list = new ArrayList( ...