zoukankan      html  css  js  c++  java
  • k8s集群———flannel网络

    #master执行将内网通信地址写入etcd中,确保flannel能与etcd通信
    #添加
    /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.1.63:2379,https://192.168.1.65:2379,https://192.168.1.66:2379" set /coreos.com/network/config  '{ "Network": "172.17.0.0/16", "Backend": {"Type":"vxlan"}}'
    查看
    /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.1.63:2379,https://192.168.1.65:2379,https://192.168.1.66:2379" get  /coreos.com/network/config  
    
    
    node节点
    mkdir /opt/kubernetes/{bin,cfg,ssl} -p 
    tar zxvf flannel-v0.10.0-linux-amd64.tar.gz
    mv flanneld mk-docker-opts.sh  /opt/kubernetes/bin
    
    #执行脚本
    ./flannel  https://192.168.1.63:2379,https://192.168.1.65:2379,https://192.168.1.66:2379
    
    
    #脚本内容
    root@k8s-master: /opt 20:58:42
    $ cat flannel.sh 
    #!/bin/bash
    #定义传参https://192.168.1.63:2379,https://192.168.1.65:2379,https://192.168.1.66:2379
    ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}
    
    #flannel配置文件
    cat <<EOF >/opt/kubernetes/cfg/flanneld
    
    FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} 
    -etcd-cafile=/opt/etcd/ssl/ca.pem 
    -etcd-certfile=/opt/etcd/ssl/server.pem 
    -etcd-keyfile=/opt/etcd/ssl/server-key.pem"
    
    EOF
    #systemctl管理flannel模块
    cat <<EOF >/usr/lib/systemd/system/flanneld.service
    [Unit]
    Description=Flanneld overlay address etcd agent
    After=network-online.target network.target
    Before=docker.service
    
    [Service]
    Type=notify
    EnvironmentFile=/opt/kubernetes/cfg/flanneld
    ExecStart=/opt/kubernetes/bin/flanneld --ip-masq $FLANNEL_OPTIONS
    ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
    EOF
    ###docker配置文件
    cat <<EOF >/usr/lib/systemd/system/docker.service
    
    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network-online.target firewalld.service
    Wants=network-online.target
    
    [Service]
    Type=notify
    #########主要是加了这两行,docker是否引用flannel网络
    EnvironmentFile=/run/flannel/subnet.env
    ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS
    #########
    ExecReload=/bin/kill -s HUP $MAINPID
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    TimeoutStartSec=0
    Delegate=yes
    KillMode=process
    Restart=on-failure
    StartLimitBurst=3
    StartLimitInterval=60s
    
    [Install]
    WantedBy=multi-user.target
    
    EOF
    
    systemctl daemon-reload
    systemctl enable flanneld
    systemctl restart flanneld
    systemctl restart docker
    
    root@k8s-master: /opt 20:58:45
    $ 
    #ifconfig查看docker0的ip地址是与flannel.1的ip在一个网段
    root@k8s-node01: /opt/kubernetes/bin 21:18:25
    $ ifconfig docker0
    docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 172.17.94.1  netmask 255.255.255.0  broadcast 172.17.94.255
            inet6 fe80::42:83ff:fe96:f053  prefixlen 64  scopeid 0x20<link>
            ether 02:42:83:96:f0:53  txqueuelen 0  (Ethernet)
            RX packets 6  bytes 392 (392.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 14  bytes 1132 (1.1 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    root@k8s-node01: /opt/kubernetes/bin 21:18:28
    $ ifconfig flannel.1
    flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1450
            inet 172.17.94.0  netmask 255.255.255.255  broadcast 0.0.0.0
            inet6 fe80::5c8d:26ff:fe95:d0e8  prefixlen 64  scopeid 0x20<link>
            ether 5e:8d:26:95:d0:e8  txqueuelen 0  (Ethernet)
            RX packets 4  bytes 336 (336.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 4  bytes 336 (336.0 B)
            TX errors 0  dropped 8 overruns 0  carrier 0  collisions 0
    
    root@k8s-node01: /opt/kubernetes/bin 21:18:33
    $ 
    
    #查看docker是否引用flannel的ip
    root@k8s-node01: /opt/kubernetes/bin 21:19:21
    $ ps -ef|grep dockerd
    root     18060     1  0 20:52 ?        00:00:00 /usr/bin/dockerd --bip=172.17.94.1/24 --ip-masq=false --mtu=1450
    root     20537 16530  0 21:19 pts/0    00:00:00 grep --color=auto dockerd
    root@k8s-node01: /opt/kubernetes/bin 21:19:27
    $ cat /usr/lib/systemd/system/docker.service 
    
    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network-online.target firewalld.service
    Wants=network-online.target
    
    [Service]
    Type=notify
    EnvironmentFile=/run/flannel/subnet.env
    ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS
    ExecReload=/bin/kill -s HUP $MAINPID
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    TimeoutStartSec=0
    Delegate=yes
    KillMode=process
    Restart=on-failure
    StartLimitBurst=3
    StartLimitInterval=60s
    
    [Install]
    WantedBy=multi-user.target
    
    root@k8s-node01: /opt/kubernetes/bin 21:19:33
    $ cat /run/flannel/subnet.env
    DOCKER_OPT_BIP="--bip=172.17.94.1/24"
    DOCKER_OPT_IPMASQ="--ip-masq=false"
    DOCKER_OPT_MTU="--mtu=1450"
    DOCKER_NETWORK_OPTIONS=" --bip=172.17.94.1/24 --ip-masq=false --mtu=1450"
    root@k8s-node01: /opt/kubernetes/bin 21:19:37
    $ 
    完成
  • 相关阅读:
    C#函数复习
    ADO数据库访问类查询、属性扩展
    ADO.NET完整的删除与修改, 实体类和数据访问类
    ADO.NET增删改查
    类库、委托
    多态
    面向对象:封装、继承
    面向对象思想:对象和类
    sql 存储过程、事务、视图、触发器
    连接查询,结构、循环语句
  • 原文地址:https://www.cnblogs.com/Carr/p/10555234.html
Copyright © 2011-2022 走看看