CentOS7 install etcd and flannel

Start

When setting up a Kubernetes environment, you may encounter some problems, no! You will have many problems. For example, first of all you need to implement container access across physical machines - containers in different physical machines can access each other, not the messy port mapping you usually see. There are many solutions, such as OVS, flannel, socketplane, etc. The following is the process of building etcd and flannel. I hope it will help those who need such an environment and avoid detours. Again: direct access between containers across physical machines

Architecture

The architecture of the experiment is very simple. There are three machines. In order to simplify, I only set up one etcd without clustering. The three machines are installed with flannel and Docker.

  • 172.16.164.5 //etcd、flannel、docker
  • 172.16.164.6 //flannel、docker
  • 172.16.164.7 //flannel、docker

install etcd

  • The installation of 172.16.164.5
    etcd is especially easy - just download the binary and run it if you have it, here I set up a new cluster.
    #也许你需要,github使用的是amazon的s3存储
    wget https://github.com/coreos/etcd/releases/download/v2.3.2/etcd-v2.3.2-linux-amd64.tar.gz
    tar xvf etcd-v2.3.2-linux-amd64.tar.gz 
    cd etcd-v2.3.2-linux-amd64
    mv etcd* /usr/bin
    The binary program can be started directly. For convenience, we add it to Systemd management, and for future expansion, I also set up a cluster, so you don't need to add cluster settings.
    cat /usr/lib/systemd/system/etcd.service
    [Unit]
    Description=etcd
    [Service]
    Environment=ETCD_NAME=kubernetes
    Environment=ETCD_DATA_DIR=/var/lib/etcd
    Environment=ETCD_LISTEN_CLIENT_URLS=http://172.16.164.5:4001,http://localhost:4001
    Environment=ETCD_LISTEN_PEER_URLS=http://172.16.164.5:7001,http://localhost:7001
    Environment=ETCD_INITIAL_ADVERTISE_PEER_URLS=http://172.16.164.5:7001,http://localhost:7001
    Environment=ETCD_ADVERTISE_CLIENT_URLS=http://172.16.164.5:4001,http://localhost:4001
    Environment=ETCD_INITIAL_CLUSTER_STATE=new
    Environment=ETCD_INITIAL_CLUSTER_TOKEN=Kubernetes
    Environment=ETCD_INITIAL_CLUSTER=kubernetes=http://172.16.164.5:7001,kubernetes=http://localhost:7001
    ExecStart=/usr/bin/etcd
    [Install]
    WantedBy=multi-user.target
    After adding, execute systemctl start etcdetcd to start, you can pass etcdctl ls /or etcdctl mkdir /testtest etcd availability.
    Add network segment
    After confirming that etcd can be used, we need to set the network segment assigned to the docker network
    etcdctl mk /coreos.com/network/config '{"Network":"172.17.0.0/16", "SubnetMin": "172.17.1.0", "SubnetMax": "172.17.254.0"}'

    install flannel

    The following is the old content, please see the next blog post for updates

  • 172.16.164.5
  • 172.16.164.6
  • 172.16.164.7
    All three hosts need to be executed.
    In fact, flannel is also the same as etcd. It does not need to be installed. You can directly download the binary executable file from the official website. Of course, you can also compile it yourself.
    wget https://github.com/coreos/flannel/releases/download/v0.5.5/flannel-0.5.5-linux-amd64.tar.gz
    tar xvf flannel-0.5.5-linux-amd64.tar.gz
    mv flannel-0.5.5-linux-amd64 /opt/flannel
    Similarly, we add a System unit of the flannel service, which is simple.
    cat /usr/lib/systemd/system/flanneld.service 
    [Unit]
    Description=flannel
    [Service]
    ExecStart=/opt/flannel/flanneld \
    -etcd-endpoints=http://172.16.164.5:4001
    [Install]
    WantedBy=multi-user.target
    通过systemctl start flanneld启动服务,正常情况下,你执行ip a已经可以看到flannel0桥接网卡了,etcd上执行etcdctl ls /coreos.com/network/subnets也能够看到flannel申请的网段。
    修改Docker参数
    要像使docker使用flannel的网络传递数据,要修改一些启动参数。
    cd /opt/flannel/
    ./mk-docker-opts.sh -i
    通过mk-docker-opts.sh --help可一直到这个脚本会生成一些docker参数,放到/run/docker_opts.env文件中,我们只需要将这些参数,加入到docker的启动参数
    cat /etc/sysconfig/docker | grep OPT
    OPTIONS='--selinux-enabled --bip=172.17.64.1/24 --ip-masq=true --mtu=1472'

Paste_Image.png


配置完毕后,便可以启动docker了。

sytemctl stop docker
ifconfig down docker0
systemctl start docker
ip a s docker0
#可以看到docker0已经获取了flannel网段的地址

Paste_Image.png

最后

三台机器都配置好了之后,我们在三台机器上分别开启一个docker容器,测试它们的网络是不是通的。

docker run -ti centos bash
#一次查看容器IP
cat /etc/hosts
172.17.97.2     334cec104721
#测试连通性,都成功就OK了
#到跨物理机容器
ping -c 1 172.16.164.7
ping -c 1 172.17.67.1
#到宿主机
ping -c 1 172.16.164.7
#到别的物理机
ping -c 1 172.16.164.6

Paste_Image.png

很多东西还需要继续学(zhe)习(teng),本文就到此结束了,如果你什么建议或者意见,可以评论留言,如果对你能产生帮助,欢迎打赏●v●



文/岦_(简书作者)
原文链接:http://www.jianshu.com/p/a2039a8855ec
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
 
http://www.iyunv.com/thread-58817-1-1.html
http://blog.liuker.cn/index.php/docker/30.html
 
http://www.cnblogs.com/xuxinkun/p/5696031.html
 
http://www.dataguru.cn/thread-581573-1-1.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326789369&siteId=291194637