func (i IpamDriver) RequestPool(request *ipam.RequestPoolRequest) (*ipam.RequestPoolResponse, error) {
logutils.JSONMessage("RequestPool", request)
// Calico IPAM does not allow you to request a SubPool.
if request.SubPool != "" {
err := errors.New(
"Calico IPAM does not support sub pool configuration " +
"on 'docker create network'. Calico IP Pools " +
"should be configured first and IP assignment is " +
"from those pre-configured pools.",
)
log.Errorln(err)
return nil, err
}
if len(request.Options) != 0 {
err := errors.New("Arbitrary options are not supported")
log.Errorln(err)
return nil, err
}
var poolID string
var pool string
var gateway string
if request.V6 {
// Default the poolID to the fixed value.
poolID = i.poolIDV6
pool = "::/0"
gateway = "::/0"
} else {
// Default the poolID to the fixed value.
poolID = i.poolIDV4
pool = "0.0.0.0/0"
gateway = "0.0.0.0/0"
}
// If a pool (subnet on the CLI) is specified, it must match one of the
// preconfigured Calico pools.
if request.Pool != "" {
poolsClient := i.client.IPPools()
_, ipNet, err := caliconet.ParseCIDR(request.Pool)
if err != nil {
err := errors.New("Invalid CIDR")
log.Errorln(err)
return nil, err
}
f := false
for _, p := range pools.Items {
if p.Spec.CIDR == ipNet.String() {
f = true
pool = p.Spec.CIDR
poolID = p.Name
break
}
}
if !f {
err := errors.New("The requested subnet must match the CIDR of a " +
"configured Calico IP Pool.",
)
log.Errorln(err)
return nil, err
}
}
// We use static pool ID and CIDR. We don't need to signal the
// The meta data includes a dummy gateway address. This prevents libnetwork
// from requesting a gateway address from the pool since for a Calico
// network our gateway is set to a special IP.
resp := &ipam.RequestPoolResponse{
PoolID: poolID,
Pool: pool,
Data: map[string]string{"com.docker.network.gateway": gateway},
}
1 个回复
nccloud
本文主要分析calico中的ipPool资源
关于calico的集群部署,可以参考文章:
https://www.jianshu.com/p/2f8d8b4d5296
一、环境介绍
物理环境介绍
服务部署介绍
二、calico支持的模式?
三、如何管理ipPool的生命周期?
3.1 如何创建ipPool 资源对象?
3.2 如何删除ipPool 资源对象?
3.3 如何更新ipPool 资源对象?
四、ipPool
4.1 默认ipPool
4.2 删除默认ipPool资源(选做)
删除
4.3 BGP模式
4.3.1 创建bgp模式下的ipPool资源对象
自定义bgp模式的ipPool资源对象
vim ipPool-bgp.yaml
创建ipPool资源
4.3.2 查看物理机网卡信息
4.3.3 查看物理机路由表信息
4.3.4 清理ipPool资源
4.3.5 BGP模式总结:
4.4 IPIP模式
4.4.1 如何设置成IPIP模式
4.4.2 纯ipip模式
4.4.2.1 创建纯ipip模式下的ipPool资源对象
vim ipPool-ipip-always.yaml
4.4.2.2 查看物理机网卡信息
4.4.2.3 查看物理机路由表信息
4.4.2.4 清理ipPool资源
calicoctl delete -f ipPool-ipip-always.yaml
4.4.2.5 总结:
ipip-always模式,
4.4.3 混合ipip-bgp模式
4.4.3.1 创建混合ipip-bgp模式下的ipPool资源对象
自定义混合ipip-bgp模式的ipPool资源对象
vim ipPool-ipip-cross-subnet.yaml
创建ipPool资源
4.4.3.2 查看物理机网卡信息
4.4.3.3 查看物理机路由表信息
4.4.3.4 清理ipPool资源
4.4.4 总结
4.5 总结整理:
五、如果calico集群里,存在多个bgp模式的ipPool资源对象的话,哪个生效?
简单的测试了几次,没发现什么规律。
肯定是测试不够充分。
查看calico源码:
其中,有一块代码逻辑是:
六、问题列表
查看libnetwork的日志:
或者说,没有定义ip 池,
解决措施,创建一个ipPool就可以了,