058、flannel概述(2019-03-27 周三)
flannel 是 CentOS开发的容器网络解决方案。flannel 为每个host分配一个subnet,容器从此subnet中分配IP,这些Ip可以在host间路由,容器间无需NAT和port mapping就可以跨主机通信
每个subnet都是从一个更大的IP池中划分的,flannel会在每个host上运行一个叫flanneld的agent,其职责就是从池子中分配subnet。为了在各个host间共享信息,flannel用etcd(与consul类似的key-value分布式数据库)存放网络配置、已分配的subnet、host的IP信息等
数据包如何在host间转发是由backend实现的。flannel提供了多种backend,最常用的有vxlan和host-gw,我们将在本章学习这两种backend。其他backend请参考https://github.com/coreos/flannel
安装etcd步骤
# 1、安装etcd
ETCD_VER=v2.3.7
DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
mkdir -p /tmp/test-etcd && tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/test-etcd --strip-components=1
cp /tmp/test-etcd/etcd* /usr/local/bin/
# 2、启动etcd
etcd -listen-client-urls http://10.12.31.213:2379 -advertise-client-urls http://10.12.31.213:2379
# 3、测试etcd
etcdctl --endpoints=10.12.31.213:2379 set foo "bar"
etcdctl --endpoints=10.12.31.213:2379 get foo
[root@docker-machine ~]# ETCD_VER=v2.3.7
[root@docker-machine ~]# DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download
[root@docker-machine ~]# curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 153 0 153 0 0 11 0 --:--:-- 0:00:13 --:--:-- 43
100 620 0 620 0 0 41 0 --:--:-- 0:00:14 --:--:-- 679
100 8347k 100 8347k 0 0 17858 0 0:07:58 0:07:58 --:--:-- 11273
[root@docker-machine ~]# mkdir -p /tmp/test-etcd && tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/test-etcd --strip-components=1
etcd-v2.3.7-linux-amd64/Documentation/
etcd-v2.3.7-linux-amd64/Documentation/runtime-configuration.md
etcd-v2.3.7-linux-amd64/Documentation/admin_guide.md
etcd-v2.3.7-linux-amd64/Documentation/tuning.md
etcd-v2.3.7-linux-amd64/Documentation/glossary.md
etcd-v2.3.7-linux-amd64/Documentation/rfc/
etcd-v2.3.7-linux-amd64/Documentation/rfc/v3api.md
etcd-v2.3.7-linux-amd64/Documentation/discovery_protocol.md
etcd-v2.3.7-linux-amd64/Documentation/errorcode.md
etcd-v2.3.7-linux-amd64/Documentation/metrics.md
etcd-v2.3.7-linux-amd64/Documentation/security.md
etcd-v2.3.7-linux-amd64/Documentation/configuration.md
etcd-v2.3.7-linux-amd64/Documentation/docker_guide.md
etcd-v2.3.7-linux-amd64/Documentation/dev/
etcd-v2.3.7-linux-amd64/Documentation/dev/release.md
etcd-v2.3.7-linux-amd64/Documentation/members_api.md
etcd-v2.3.7-linux-amd64/Documentation/auth_api.md
etcd-v2.3.7-linux-amd64/Documentation/backward_compatibility.md
etcd-v2.3.7-linux-amd64/Documentation/platforms/
etcd-v2.3.7-linux-amd64/Documentation/platforms/freebsd.md
etcd-v2.3.7-linux-amd64/Documentation/libraries-and-tools.md
etcd-v2.3.7-linux-amd64/Documentation/implementation-faq.md
etcd-v2.3.7-linux-amd64/Documentation/reporting_bugs.md
etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_2.md
etcd-v2.3.7-linux-amd64/Documentation/internal-protocol-versioning.md
etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_1.md
etcd-v2.3.7-linux-amd64/Documentation/faq.md
etcd-v2.3.7-linux-amd64/Documentation/api_v3.md
etcd-v2.3.7-linux-amd64/Documentation/runtime-reconf-design.md
etcd-v2.3.7-linux-amd64/Documentation/clustering.md
etcd-v2.3.7-linux-amd64/Documentation/proxy.md
etcd-v2.3.7-linux-amd64/Documentation/branch_management.md
etcd-v2.3.7-linux-amd64/Documentation/other_apis.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-rc-memory-benchmarks.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-3-demo-benchmarks.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-benchmarks.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-1-0-alpha-benchmarks.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-storage-memory-benchmark.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/README.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-2-2-0-rc-benchmarks.md
etcd-v2.3.7-linux-amd64/Documentation/benchmarks/etcd-3-watch-memory-benchmark.md
etcd-v2.3.7-linux-amd64/Documentation/api.md
etcd-v2.3.7-linux-amd64/Documentation/authentication.md
etcd-v2.3.7-linux-amd64/Documentation/04_to_2_snapshot_migration.md
etcd-v2.3.7-linux-amd64/Documentation/upgrade_2_3.md
etcd-v2.3.7-linux-amd64/Documentation/production-users.md
etcd-v2.3.7-linux-amd64/README-etcdctl.md
etcd-v2.3.7-linux-amd64/etcdctl
etcd-v2.3.7-linux-amd64/etcd
etcd-v2.3.7-linux-amd64/README.md
[root@docker-machine ~]# cp /tmp/test-etcd/etcd* /usr/local/bin/
[root@docker-machine ~]# etcd -listen-client-urls http://10.12.31.213:2379 -advertise-client-urls http://10.12.31.213:2379 &
2019-03-29 22:18:28.093120 I | etcdmain: etcd Version: 2.3.7
2019-03-29 22:18:28.093183 I | etcdmain: Git SHA: fd17c91
2019-03-29 22:18:28.093188 I | etcdmain: Go Version: go1.6.2
2019-03-29 22:18:28.093197 I | etcdmain: Go OS/Arch: linux/amd64
2019-03-29 22:18:28.093205 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4
2019-03-29 22:18:28.093210 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2019-03-29 22:18:28.093510 I | etcdmain: listening for peers on http://localhost:2380
2019-03-29 22:18:28.093595 I | etcdmain: listening for peers on http://localhost:7001
2019-03-29 22:18:28.093636 I | etcdmain: listening for client requests on http://10.12.31.213:2379
2019-03-29 22:18:28.104510 I | etcdserver: name = default
2019-03-29 22:18:28.104544 I | etcdserver: data dir = default.etcd
2019-03-29 22:18:28.104558 I | etcdserver: member dir = default.etcd/member
2019-03-29 22:18:28.104572 I | etcdserver: heartbeat = 100ms
2019-03-29 22:18:28.104586 I | etcdserver: election = 1000ms
2019-03-29 22:18:28.104595 I | etcdserver: snapshot count = 10000
2019-03-29 22:18:28.104628 I | etcdserver: advertise client URLs = http://10.12.31.213:2379
2019-03-29 22:18:28.104637 I | etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
2019-03-29 22:18:28.104653 I | etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
2019-03-29 22:18:28.125879 I | etcdserver: starting member ce2a822cea30bfca in cluster 7e27652122e8b2ae
2019-03-29 22:18:28.125934 I | raft: ce2a822cea30bfca became follower at term 0
2019-03-29 22:18:28.125955 I | raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2019-03-29 22:18:28.125964 I | raft: ce2a822cea30bfca became follower at term 1
2019-03-29 22:18:28.126235 I | etcdserver: starting server... [version: 2.3.7, cluster version: to_be_decided]
2019-03-29 22:18:28.126750 E | etcdmain: failed to notify systemd for readiness: No socket
2019-03-29 22:18:28.126769 E | etcdmain: forgot to set Type=notify in systemd service file?
2019-03-29 22:18:28.127383 N | etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae
2019-03-29 22:18:28.526326 I | raft: ce2a822cea30bfca is starting a new election at term 1
2019-03-29 22:18:28.526416 I | raft: ce2a822cea30bfca became candidate at term 2
2019-03-29 22:18:28.526428 I | raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 2
2019-03-29 22:18:28.526466 I | raft: ce2a822cea30bfca became leader at term 2
2019-03-29 22:18:28.526484 I | raft: raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 2
2019-03-29 22:18:28.526807 I | etcdserver: setting up the initial cluster version to 2.3
2019-03-29 22:18:28.531132 N | etcdserver: set the initial cluster version to 2.3
2019-03-29 22:18:28.531229 I | etcdserver: published {Name:default ClientURLs:[http://10.12.31.213:2379]} to cluster 7e27652122e8b2ae
[root@docker-machine ~]# etcdctl --endpoints=10.12.31.213:2379 set foo "bar"
bar
[root@docker-machine ~]# etcdctl --endpoints=10.12.31.213:2379 get foo
bar
至此,etcd数据库安装完毕