CentOS环境Docker flannel网络方案实验

测试环境

环境IP信息

master:192.168.66.40,启动etcd服务
node1: 192.168.66.41,启动flannel服务
node2: 192.168.66.42,启动flannel服务

版本信息

flanneld -version
v0.13.0

etcd --version
etcd Version: 3.4.15
Git SHA: aa7126864
Go Version: go1.12.17
Go OS/Arch: linux/amd64

安装etcd

etcd版本:
ETCD_VER=v3.4.15
下载地址:
https://github.com/etcd-io/etcd/releases/download/v3.4.15/etcd-v3.4.15-linux-amd64.tar
解压到tmp文件下(也可以其他任意目录):
tar xvf etcd-v3.4.15-linux-amd64.tar -C /tmp/etcd-download-test --strip-components=1
把可执行文件复制到/usr/local/bin/目录下
cp /tmp/etcd-download-test/etcd* /usr/local/bin/
查看etcd版本是否正确:
etcd --version
etcdctl version
后台启动etcd服务
启动etcd服务并监听url
etcd --enable-v2 -listen-client-urls http://192.168.66.40:2379 -advertise-client-urls http://192.168.66.40:2379
测试etcd是否可用
etcdctl --endpoints=192.168.66.40:2379 put foo bar
V2版本格式:etcdctl --endpoints=http://192.168.66.40:2379 set foo bar
etcdctl --endpoints=192.168.66.40:2379 get foo
V2版本格式:etcdctl --endpoints=http://192.168.66.40:2379 get foo
在这里插入图片描述

Build flannel

1.下载flannel
wget https://github.com/coreos/flannel/releases/download/v0.13.0/flanneld-amd64 && chmod +x flanneld-amd64
2.添加到bin目录,并重命名
cp flanneld-amd64 /usr/local/bin/flannel

VxLAN模式

将flannel网络的配置信息保存到etcd

先将配置信息写到文件flannel-config.json中,内容为:

[root@docker-manager flannel]# cat flannel-config.json
{
   
    "Network": "192.168.88.0/16",
    "SubnetLen":24,
    "Backend": {
   
        "Type": "vxlan"
    }
}
  1. Network定义该网络的IP池为10.2.0.0/16
  2. SubnetLen指定每个主机分配到的subnet大小为24位
  3. Backend为vxlan

将配置保存到etcd
ETCDCTL_API=2 etcdctl --endpoints=http://192.168.66.40:2379 set /docker-test/network/config < flannel-config.json

[root@docker-manager flannel]#ETCDCTL_API=2  etcdctl --endpoints=http://192.168.66.40:2379 set /docker-test/network/config < flannel-config.json
OK

其中/docker-test/network/config是此etcd数据项的key,其value为flannel-config.json的内容。key可以任意指定,这个key后面会作为flanneld的一个启动参数。

确保执行成功
etcdctl --endpoints=http://192.168.66.40:2379 get /docker-test/network/config

[root@docker-manager flannel]#  etcdctl --endpoints=192.168.66.40:2379 get /docker-test/network/config
/docker-test/network/config
{
   
    "Network": "192.168.88.0/16",
    "SubnetLen":24,
    "Backend": {
   
        "Type": "vxlan"
    }
}

启动flannel

node1启动flannel

flanneld -etcd-endpoints=http://192.168.66.40:2379 -iface=ens38 -etcd-prefix=/docker-test/network

[root@docker1 home]# flanneld -etcd-endpoints=http://192.168.66.40:2379 -iface=ens38 -etcd-prefix=/docker-test/network
I0302 17:58:23.985522   17230 main.go:531] Using interface with name ens38 and address 192.168.66.41
I0302 17:58:23.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值