ubuntu16 kubernetes1.6安裝(3、etcd、flannel)

在配置k8s,過程當中用到flannel,發現其docker大部分文檔,啓動沒使用systemd的形式,故此完善了下,實際生產不須要證書,能夠去除。
軟件版本:
root@ubuntu132:~/scripts# etcd -version
etcd Version: 3.1.7
Git SHA: 43b7507
Go Version: go1.7.5
Go OS/Arch: linux/amd64
root@ubuntu132:~/scripts# flanneld -version
v0.6.2linux

一、下載etcd etcdctl flannel 二進制包,並放置到/usr/local/bin
二、設置etcd,systemd管理啓動,這裏使用了k8s的證書,可去除
root@ubuntu133:~# cat /etc/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd \
--name ${ETCD_NAME} \
--cert-file=/etc/kubernetes/ssl/kubernetes.pem \
--key-file=/etc/kubernetes/ssl/kubernetes-key.pem \
--peer-cert-file=/etc/kubernetes/ssl/kubernetes.pem \
--peer-key-file=/etc/kubernetes/ssl/kubernetes-key.pem \
--trusted-ca-file=/etc/kubernetes/ssl/ca.pem \
--peer-trusted-ca-file=/etc/kubernetes/ssl/ca.pem \
--initial-advertise-peer-urls ${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--listen-peer-urls ${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls ${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls ${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-cluster-token ${ETCD_INITIAL_CLUSTER_TOKEN} \
--initial-cluster infra1=https://192.168.15.132:2380,infra2=https://192.168.15.133:2380,infra3=https://192.168.15.134:2380 \
--initial-cluster-state new \
--data-dir=${ETCD_DATA_DIR}
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.targetgit

每一個etcd集羣節點按具體狀況配置
root@ubuntu133:~# cat /etc/etcd/etcd.conf github

ETCD_NAME=infra2
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.15.133:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.15.133:2379"
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.15.133:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.15.133:2379docker

systemctl daemon-reload
systemctl enable etcd
systemctl start etcdubuntu

設置etcd內容,同時設置flannel網絡
root@ubuntu132:~/scripts# cat etcdctl.sh
#!/bin/bashbash

etcdctl --endpoints=https://192.168.15.132:2379,https://192.168.15.133:2379,https://192.168.15.134:2379 \
--ca-file=/etc/kubernetes/ssl/ca.pem \
--cert-file=/etc/kubernetes/ssl/kubernetes.pem \
--key-file=/etc/kubernetes/ssl/kubernetes-key.pem \
set /coreos.com/network/config '{"Network":"10.253.0.0/16"}'網絡

三、flannel配置,可用systemd管理,也不使用,systemd配置
root@ubuntu133:~# cat flannelctl.sh
#!/bin/bash
flanneld -etcd-endpoints="https://192.168.15.132:2379,https://192.168.15.133:2379,https://192.168.15.134:2379" \
-etcd-prefix=/coreos.com/network \
-etcd-cafile=/etc/kubernetes/ssl/ca.pem \
-etcd-certfile=/etc/kubernetes/ssl/kubernetes.pem \
-etcd-keyfile=/etc/kubernetes/ssl/kubernetes-key.pem &
sleep 5
source /run/flannel/subnet.envsocket

./flannelctl.sh ide

四、docker網絡配置,這裏須要把flannel網絡中的環境變量添加到docker啓動環境變量中去,docker後啓動於flannel。
root@ubuntu133:~# cat /etc/systemd/system/multi-user.target.wants/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket firewalld.service
Requires=docker.socketui

[Service]
Type=notify

#ExecStart=/usr/bin/dockerd -H fd://
#ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576

LimitNPROC=infinity
LimitCORE=infinity

TasksMax=infinity
TimeoutStartSec=0

Delegate=yes

KillMode=process

EnvironmentFile=-/etc/default/docker
EnvironmentFile=-/run/flannel/subnet.env
ExecStart=/usr/bin/docker daemon --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} -H fd:// $DOCKER_OPTS

[Install]
WantedBy=multi-user.target

systemctl daemon-reloadsystemctl enable dockersystemctl restart docker

相關文章
相關標籤/搜索