系统环境:CentOS Linux release 7.4.1708 (Core)
IP分布:
master:192.168.11.234
node1:192.168.11.226
node2:192.168.11.213
前言;
Flannel概述
Flannel 是 CoreOS 团队针对 Kubernetes 设计的一个网络规划服务,简单来说,它的功能是让集群中的不同节点主机创建的Docker 容器都具有全集群唯一的虚拟IP地址。但在默认的Docker配置中,每个节点上的 Docker 服务会分别负责所在节点容器的 IP 分配。这样导致的一个问题是,不同节点上容器可能获得相同的内外 IP 地址。并使这些容器之间能够之间通过 IP 地址相互找到,也就是相互 ping 通。
Flannel 的设计目的就是为集群中的所有节点重新规划IP地址的使用规则,从而使得不同节点上的容器能够获得“同属一个内网”且”不重复的”IP 地址,并让属于不同节点上的容器能够直接通过内网 IP 通信。
Flannel实质上是一种“覆盖网络(overlay network)”,也就是将 TCP 数据包装在另一种网络包里面进行路由转发和通信,目前已经支持UDP、VxLAN、AWS VPC和GCE路由等数据转发方式。
时间同步(重要)
详情请点击:时间同步
[root@node1 ~]# yum install ntp-server -y
[root@node1 ~]# systemctl start ntpd && systemctl enable ntpd
# yum install ntpdate -y
#重要:时间同步 (每个节点都要操作否则会有意想不到的惊喜)
# echo “*/5 * * * * /usr/sbin/ntpdate 192.168.31.221 > /dev/null 2>&1 &” >>/etc/crontab
# /usr/sbin/ntpdate 192.168.31.221 #手动同步一次
Docker部署
1.设置 yum 仓库
tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
2.执行安装
yum -y install docker-engine
3.设置开机启动
systemctl start docker && systemctl enable docker
4.添加 Docker Hub 国内镜像
如果没有此文件,则新建一个
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
5.重启 docker
systemctl restart docker #重启docker
6.设置 hosts 及 hostname
[root@node1 ~]# vi /etc/hosts
192.168.11.234 master master.example.com
192.168.11.226 node1 node1.example.com
192.168.11.213 node2 node2.example.com
[root@node1 ~]# hostnamectl set-hostname master.example.com
[root@node2~]# hostnamectl set-hostname node1.example.com
[root@node3 ~]# hostnamectl set-hostname node1.example.com
二.给 docker 配置 Flannel 网络
1.Master 节点 etcd 配置
Etcd 安装配置 (这里做的单节点 ETCD 只在 Master 节点安装)
[root@node1 ~]# yum install etcd -y
[root@node1 ~]# vi /etc/default/etcd
ETCD_DATA_DIR="/var/lib/etcd/default"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
[root@node1 ~]# sed -i 's/localhost/0.0.0.0/g' /etc/etcd/etcd.conf
[root@node1 k8s]# systemctl start etcd && systemctl enable etcd
etcd 创建 Flannel 网络
[root@node1 ~]# etcdctl --endpoints http://192.168.11.234:2379 \
set /coreos.com/network/config '{"NetWork":"10.0.0.0/16"}'
未完待续....
网友评论