071、如何定制calico网络的IP池(2019-04-16 周二)
在前面的学习中,我们没有特别配置,calico会自动为网络分配subnet,当然我们也可以根据需求定制。
# 1、创建一个IP池的yaml文件
root@host1:~# cat subnet.yaml
- apiVersion: v1
kind: ipPool
metadata:
cidr: 172.2.0.0/16
# 2、使用步骤1中的配置文件创建一个IP池
root@host1:~# calicoctl create -f subnet.yaml
Successfully created 1 'ipPool' resource(s)
# 3、使用该IP池创建一个叫my_net的calico网络
root@host1:~# docker network create --driver calico --ipam-driver calico-ipam --subnet=172.2.0.0/16 my_net
5c07cb3bbdf279d73c4dfe63932775a4c194f5c1e3ab1a4e1bcf19feadcf7571
# 4、使用新创建的my_net网络运行容器,查看IP分配情况
root@host1:~# docker run -it --network my_net busybox
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
15: cali0@if16: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff
inet 172.2.119.0/32 brd 172.2.119.0 scope global cali0
valid_lft forever preferred_lft forever
/ # root@host1:~#
# 5、我们还以指定IP地址,该IP地址必须属于my_net对应的IP池
root@host1:~# docker run -it --network my_net --ip 172.2.9.9 busybox
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
17: cali0@if18: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff
inet 172.2.9.9/32 brd 172.2.9.9 scope global cali0
valid_lft forever preferred_lft forever
/ #