k8s二进制部署(二)

举报
ming-1 发表于 2021/01/28 22:10:27 2021/01/28
【摘要】 安装flannel网络插件##设置网络模式/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://10.107.141.50:2379,https:...

安装flannel网络插件

##设置网络模式

/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52: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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" get /coreos.com/network/config


在三台主机上相同配置,可使用scp传输:

##创建目录

mkdir /opt/kubernetes_flannel/{cfg,ssl,bin} -p

##解压文件

tar -zxvf flannel-v0.11.0-linux-amd64.tar.gz

mv flanneld mk-docker-opts.sh /opt/kubernetes_flannel/bin/

##配置证书

cp /opt/k8s/etcd-cert/{ca.pem,server.pem,server-key.pem} /opt/kubernetes_flannel/ssl/

##创建config配置文件

cat > /opt/kubernetes_flannel/cfg/flanneld.conf << EOF
FLANNEL_ETCD="-etcd-endpoints=https://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379"
FLANNEL_ETCD_KEY="-etcd-prefix=/coreos.com/network"
FLANNEL_ETCD_CAFILE="--etcd-cafile=/opt/kubernetes_flannel/ssl/ca.pem"
FLANNEL_ETCD_CERTFILE="--etcd-certfile=/opt/kubernetes_flannel/ssl/server.pem"
FLANNEL_ETCD_KEYFILE="--etcd-keyfile=/opt/kubernetes_flannel/ssl/server-key.pem"
EOF

##创建flannel的service文件

cat > /usr/lib/systemd/system/flanneld.service << EOF
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
Before=docker.service

[Service]
Type=notify
EnvironmentFile=-/opt/kubernetes_flannel/cfg/flanneld.conf
ExecStart=/opt/kubernetes_flannel/bin/flanneld ${FLANNEL_ETCD} ${FLANNEL_ETCD_KEY} ${FLANNEL_ETCD_CAFILE} ${FLANNEL_ETCD_CERTFILE} ${FLANNEL_ETCD_KEYFILE}
ExecStartPost=/opt/kubernetes_flannel/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure

[Install]
WantedBy=multi-user.target
RequiredBy=docker.service

EOF

##修改docker的service文件使其使用flannel网络

cat > /usr/lib/systemd/system/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

##启动flannel

systemctl daemon-reload

systemctl start flanneld

##重新启动docker

systemctl restart docker

##查看flannel,docker的启动和etcd里存储的信息

ps -ef | grep flanneld

ps -ef | grep docker

/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" ls /coreos.com/network/subnets/

/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" get /coreos.com/network/subnets/ip

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。