码迷,mamicode.com
首页 > 其他好文 > 详细

(三)k8s之 flanned网络

时间:2019-03-05 11:07:33      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:int   环境变量   gen   lib   ini   ast   gate   master   emd   

#(1)在跳板机上生成flanneld证书

#cd /temp/ssl/
cat > flanneld-csr.json <<EOF
{
    "CN": "flanneld",
    "hosts": [],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "Hangzhou",
            "L": "Hangzhou",
            "O": "k8s",
            "OU": "System"
        }
    ]
}
EOF

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json  -profile=kubernetes flanneld-csr.json | cfssljson -bare flanneld

#(2)选择一台etcd集群节点机器, 向etcd注册flannel相关信息并验证

配置环境变量

export CLUSTER_CIDR="172.30.0.0/16"
export ETCD_ENDPOINTS="https://192.168.19.128:2379,https://192.168.19.129:2379,https://192.168.19.130:2379"
export FLANNEL_ETCD_PREFIX="/kubernetes/network"

向etcd注册flannel相关信息

etcdctl --endpoints=${ETCD_ENDPOINTS} --ca-file=/opt/kubernetes/ssl/ca.pem --cert-file=/opt/kubernetes/ssl/flanneld.pem --key-file=/opt/kubernetes/ssl/flanneld-key.pem set ${FLANNEL_ETCD_PREFIX}/config ‘{"Network":"‘${CLUSTER_CIDR}‘", "SubnetLen": 24, "Backend": {"Type": "vxlan"}}‘

验证

etcdctl --endpoints=${ETCD_ENDPOINTS} --ca-file=/opt/kubernetes/ssl/ca.pem --cert-file=/opt/kubernetes/ssl/flanneld.pem --key-file=/opt/kubernetes/ssl/flanneld-key.pem get ${FLANNEL_ETCD_PREFIX}/config

技术图片

#(3)在跳板机上下载flanneld

cd /tools
wget  https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz
tar xf flannel-v0.10.0-linux-amd64.tar.gz

#(4)在跳板机上准备flanneld配置文件

#cat  >/temp/ssl/flanneld<<EOF
FLANNEL_OPTIONS="-etcd-cafile=/opt/kubernetes/ssl/ca.pem   -etcd-certfile=/opt/kubernetes/ssl/flanneld.pem   -etcd-keyfile=/opt/kubernetes/ssl/flanneld-key.pem   -etcd-endpoints=https://192.168.19.128:2379,https://192.168.19.129:2379,https://192.168.19.130:2379   -etcd-prefix=/kubernetes/network"
EOF

#(5)在跳板机上准备flanneld启动脚本

cat >/temp/ssl/flanneld.service<<EOF
[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

#(6)在跳板机上准备docker启动脚本文件

cat > /temp/ssl/docker.service <<EOF

[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
EOF

#(7)在跳板机上把flanneld证书和私钥文件, flanneld配置文件, flanneld启动脚本文件, docker的启动配置文件发送给master和node节点

ansible k8s -m copy -a ‘src=/temp/ssl/flanneld-key.pem,dest=/opt/kubernetes/ssl/flanneld-key.pem‘ 
ansible k8s -m copy -a ‘src=/temp/ssl/flanneld.pem,dest=/opt/kubernetes/ssl/flanneld.pem‘ 
ansible k8s -m copy -a ‘src=/temp/ssl/flanneld dest=/opt/kubernetes/cfg/flanneld‘
ansible k8s -m copy -a ‘src=/temp/ssl/flanneld.service dest=/usr/lib/systemd/system/flanneld.service‘
ansible k8s -m copy -a ‘src=/temp/ssl/docker.service dest=/usr/lib/systemd/system/docker.service‘
ansible k8s -m copy -a ‘src=/tools/flanneld dest=/opt/kubernetes/bin/flanneld‘
ansible k8s -m copy -a ‘src=/tools/mk-docker-opts.sh dest=/opt/kubernetes/bin/mk-docker-opts.sh‘

#(8)在master和node节点重启flanend和docker服务

systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld
systemctl restart docker

#(9)验证

获取flannel在每个节点的网段信息

export CLUSTER_CIDR="172.30.0.0/16"
export ETCD_ENDPOINTS="https://192.168.19.128:2379,https://192.168.19.129:2379,https://192.168.19.130:2379"
export FLANNEL_ETCD_PREFIX="/kubernetes/network"
etcdctl    --endpoints=${ETCD_ENDPOINTS}    --ca-file=/opt/kubernetes/ssl/ca.pem    --cert-file=/opt/kubernetes/ssl/flanneld.pem    --key-file=/opt/kubernetes/ssl/flanneld-key.pem  ls ${FLANNEL_ETCD_PREFIX}/subnets

在master和node节点上查看路由表: 在每个节点上都能看到其他节点的路由

技术图片

master节点和node节点, docker0的ip地址使用的是flannel网段地址范围, 也是pod容器的网关
技术图片

master节点和node节点之间的flannel网段之间都能ping通, 说明flannel网络部署完成
技术图片

(三)k8s之 flanned网络

标签:int   环境变量   gen   lib   ini   ast   gate   master   emd   

原文地址:https://blog.51cto.com/1000682/2357989

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!