zoukankan      html  css  js  c++  java
  • Docker 网络 Flannel

    flannel 安装

    sudo yum install kernel-headers golang gcc
    yum install flannel

    flannel 配置

    在etcd中设置变量

    etcdctl set /coreos.com/network/config '{ "Network": "172.17.0.0/16" }'

    配置flannel

    vi /etc/sysconfig/flanneld

    # Flanneld configuration options
    
    # etcd url location.  Point this to the server where etcd runs
    FLANNEL_ETCD="http://10.1.99.13:2379,10.1.99.14:2379,10.1.99.15:2379"
    
    # etcd config key.  This is the configuration key that flannel queries
    # For address range assignment
    FLANNEL_ETCD_KEY="/coreos.com/network"
    
    # Any additional options that you want to pass
    #FLANNEL_OPTIONS=""

    重新启动flannel

    systemctl daemon-reload flanneld

    systemctl restart flanneld

    flannel服务启动

    flannel服务需要先于docker启动。flannel服务启动时主要做了以下几步的工作:

    • 从etcd中获取network的配置信息
    • 划分subnet,并在etcd中进行注册
    • 将子网信息记录到/run/flannel/subnet.env
    cat /run/flannel/subnet.env
    cat /run/flannel/subnet.env 
    FLANNEL_NETWORK=172.17.0.0/16
    FLANNEL_SUBNET=172.17.50.1/24
    FLANNEL_MTU=1472
    FLANNEL_IPMASQ=false
    • 之后将会有一个脚本将subnet.env转写成一个docker的环境变量文件/run/flannel/docker
    cat /run/flannel/docker 
    
    FLANNEL_NETWORK=172.17.0.0/16
    FLANNEL_SUBNET=172.17.50.1/24
    FLANNEL_MTU=1472
    FLANNEL_IPMASQ=false
    [root@v4 ~]# cat /run/flannel/docker 
    DOCKER_OPT_BIP="--bip=172.17.50.1/24"
    DOCKER_OPT_IPMASQ="--ip-masq=true"
    DOCKER_OPT_MTU="--mtu=1472"
    DOCKER_NETWORK_OPTIONS=" --bip=172.17.50.1/24 --ip-masq=true --mtu=1472 "

    配置docker

    systemctl show docker 将会发现 在安装flannel后自动生成配置

    DropInPaths=/usr/lib/systemd/system/docker.service.d/flannel.conf

    并引用/run/flannel/docker

    故在docker的systemd文件中应用对应变量 DOCKER_NETWORK_OPTIONS 即可

    vi /usr/lib/systemd/system/docker.service

    ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock $DOCKER_NETWORK_OPTIONS

    重新启动docker

    systemctl daemon-reload

    systemctl restart docker 

    测试

    分别在两台节点上启动测试容器

    docker run -d -it --name ip_test busybox

    后网络互通,测试通过




  • 相关阅读:
    kali 所有版本
    kali有关问题及kali2018.2安装
    python2
    burpsuite 破解教程
    python生成个性二维码
    万能密码
    python 1
    python
    python 第三方库安装
    Androidstdio 简单界面设计 登陆系统
  • 原文地址:https://www.cnblogs.com/zhangeamon/p/6140074.html
Copyright © 2011-2022 走看看