flannel 概述
flannel 是 CoreOS 开发的容器网络解决方案。
flannel 为每个 host 分配一个 subnet,容器从此 subnet 中分配 IP,这些 IP 可以在 host 间路由,容器间无需 NAT 和 port mapping 就可以跨主机通信。
每个 subnet 都是从一个更大的 IP 池中划分的,flannel 会在每个主机上运行一个叫 flanneld 的 agent,其职责就是从池子中分配 subnet。
为了在各个主机间共享信息,flannel 用 etcd(与 consul 类似的 key-value 分布式数据库)存放网络配置、已分配的 subnet、host 的 IP 等信息。
数据包如何在主机间转发是由 backend 实现的。
flannel 提供了多种 backend,最常用的有 vxlan 和 host-gw。(其他 backend 请参考 。)
flannel实验环境描述如图:
etcd 部署在 10.12.31.21上,host1(10.12.31.22) 和 host2(10.12.31.23) 上运行 flanneld,首先安装配置 etcd。
1)安装配置 etcd
1 [root@ubuntu ~]$cat etcd_install.sh2 ETCD_VER=v2.3.73 DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download4 curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz5 mkdir -p /tmp/test-etcd && tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/test-etcd --strip-components=16 cp /tmp/test-etcd/etcd* /usr/local/bin/
1 [root@ubuntu ~]$sh etcd_install.sh 2 % Total % Received % Xferd Average Speed Time Time Time Current 3 Dload Upload Total Spent Left Speed 4 100 153 0 153 0 0 141 0 --:--:-- 0:00:01 --:--:-- 141 5 100 620 0 620 0 0 405 0 --:--:-- 0:00:01 --:--:-- 100k 6 100 8347k 100 8347k 0 0 222k 0 0:00:37 0:00:37 --:--:-- 250k 7 etcd-v2.3.7-linux-amd64/Documentation/ 8 etcd-v2.3.7-linux-amd64/Documentation/runtime-configuration.md 9 etcd-v2.3.7-linux-amd64/Documentation/admin_guide.md10 etcd-v2.3.7-linux-amd64/Documentation/tuning.md11 etcd-v2.3.7-linux-amd64/Documentation/glossary.md12 etcd-v2.3.7-linux-amd64/Documentation/rfc/13 etcd-v2.3.7-linux-amd64/Documentation/rfc/v3api.md14 etcd-v2.3.7-linux-amd64/Documentation/discovery_protocol.md15 etcd-v2.3.7-linux-amd64/Documentation/errorcode.md16 etcd-v2.3.7-linux-amd64/Documentation/metrics.md17 etcd-v2.3.7-linux-amd64/Documentation/security.md18 etcd-v2.3.7-linux-amd64/Documentation/configuration.md19 etcd-v2.3.7-linux-amd64/Documentation/docker_guide.md20 etcd-v2.3.7-linux-amd64/Documentation/dev/21 etcd-v2.3.7-linux-amd64/Documentation/dev/release.md22 etcd-v2.3.7-linux-amd64/Documentation/members_api.md23 etcd-v2.3.7-linux-amd64/Documentation/auth_api.md24 etcd-v2.3.7-linux-amd64/Documentation/backward_compatibility.md25 etcd-v2.3.7-linux-amd64/Documentation/platforms/26 etcd-v2.3.7-linux-amd64/Documentation/platforms/freebsd.md27 etcd-v2.3.7-linux-amd64/Documentation/libraries-and-tools.md28 etcd-v2.3.7-linux-amd64/Documentation/implementation-faq.md29 etcd-v2.3.7-linux-amd64/Documentation/reporting_bugs.md30 etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_2.md31 etcd-v2.3.7-linux-amd64/Documentation/internal-protocol-versioning.md32 etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_1.md33 etcd-v2.3.7-linux-amd64/Documentation/faq.md34 etcd-v2.3.7-linux-amd64/Documentation/api_v3.md35 etcd-v2.3.7-linux-amd64/Documentation/runtime-reconf-design.md36 etcd-v2.3.7-linux-amd64/Documentation/clustering.md37 etcd-v2.3.7-linux-amd64/Documentation/proxy.md38 etcd-v2.3.7-linux-amd64/Documentation/branch_management.md39 etcd-v2.3.7-linux-amd64/Documentation/other_apis.md40 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/41 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-rc-memory-benchmarks.md42 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-3-demo-benchmarks.md43 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-benchmarks.md44 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-1-0-alpha-benchmarks.md45 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-storage-memory-benchmark.md46 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/README.md47 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-rc-benchmarks.md48 etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-3-watch-memory-benchmark.md49 etcd-v2.3.7-linux-amd64/Documentation/api.md50 etcd-v2.3.7-linux-amd64/Documentation/authentication.md51 etcd-v2.3.7-linux-amd64/Documentation/04_to_2_snapshot_migration.md52 etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_3.md53 etcd-v2.3.7-linux-amd64/Documentation/production-users.md54 etcd-v2.3.7-linux-amd64/README-etcdctl.md55 etcd-v2.3.7-linux-amd64/etcdctl56 etcd-v2.3.7-linux-amd64/etcd57 etcd-v2.3.7-linux-amd64/README.md58 [root@ubuntu ~]$
该脚本从 github 上下载 etcd 的可执行文件并保存到 /usr/local/bin/,启动 etcd 并打开 2379 监听端口。
etcd -listen-client-urls -advertise-client-urls
1 [root@ubuntu ~]$etcd -listen-client-urls http://10.12.31.21:2379 -advertise-client-urls http://10.12.31.21:2379 2 2019-03-27 23:22:33.110359 I | etcdmain: etcd Version: 2.3.7 3 2019-03-27 23:22:33.110422 I | etcdmain: Git SHA: fd17c91 4 2019-03-27 23:22:33.110430 I | etcdmain: Go Version: go1.6.2 5 2019-03-27 23:22:33.110437 I | etcdmain: Go OS/Arch: linux/amd64 6 2019-03-27 23:22:33.110444 I | etcdmain: setting maximum number of CPUs to 2, total number of available CPUs is 2 7 2019-03-27 23:22:33.110451 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd 8 2019-03-27 23:22:33.110705 I | etcdmain: listening for peers on http://localhost:2380 9 2019-03-27 23:22:33.110802 I | etcdmain: listening for peers on http://localhost:700110 2019-03-27 23:22:33.110840 I | etcdmain: listening for client requests on http://10.12.31.21:237911 2019-03-27 23:22:33.114237 I | etcdserver: name = default12 2019-03-27 23:22:33.114254 I | etcdserver: data dir = default.etcd13 2019-03-27 23:22:33.114259 I | etcdserver: member dir = default.etcd/member14 2019-03-27 23:22:33.114264 I | etcdserver: heartbeat = 100ms15 2019-03-27 23:22:33.114271 I | etcdserver: election = 1000ms16 2019-03-27 23:22:33.114278 I | etcdserver: snapshot count = 1000017 2019-03-27 23:22:33.114288 I | etcdserver: advertise client URLs = http://10.12.31.21:237918 2019-03-27 23:22:33.114297 I | etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:700119 2019-03-27 23:22:33.114310 I | etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:700120 2019-03-27 23:22:33.141747 I | etcdserver: starting member ce2a822cea30bfca in cluster 7e27652122e8b2ae21 2019-03-27 23:22:33.141853 I | raft: ce2a822cea30bfca became follower at term 022 2019-03-27 23:22:33.141900 I | raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]23 2019-03-27 23:22:33.141915 I | raft: ce2a822cea30bfca became follower at term 124 2019-03-27 23:22:33.142350 I | etcdserver: starting server... [version: 2.3.7, cluster version: to_be_decided]25 2019-03-27 23:22:33.143380 N | etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae26 2019-03-27 23:22:33.143968 E | etcdmain: failed to notify systemd for readiness: No socket27 2019-03-27 23:22:33.144218 E | etcdmain: forgot to set Type=notify in systemd service file?28 2019-03-27 23:22:33.542474 I | raft: ce2a822cea30bfca is starting a new election at term 129 2019-03-27 23:22:33.542972 I | raft: ce2a822cea30bfca became candidate at term 230 2019-03-27 23:22:33.543300 I | raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 231 2019-03-27 23:22:33.543575 I | raft: ce2a822cea30bfca became leader at term 232 2019-03-27 23:22:33.543814 I | raft: raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 233 2019-03-27 23:22:33.544664 I | etcdserver: published {Name:default ClientURLs:[http://10.12.31.21:2379]} to cluster 7e27652122e8b2ae34 2019-03-27 23:22:33.544753 I | etcdserver: setting up the initial cluster version to 2.335 2019-03-27 23:22:33.557561 N | etcdserver: set the initial cluster version to 2.3
测试 etcd 是否可用:
etcdctl --endpoints=10.12.31.21:2379 set foo "bar"
etcdctl --endpoints=10.12.31.21:2379 get foo
可以正常在 etcd 中存取数据了。
-----------------------------引用来自--------------------------------------
https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587799&idx=1&sn=a26c6c4a9681997031cd346224d01822&chksm=8d30814eba47085870ac9695411bc1943ee054baeb6920094256215112f5817b7a3874388c89&scene=21#wechat_redirect