上傳二進制文件node
tar -zxvf flannel-v0.8.0-rc1-linux-amd64.tar.gz cp flanneld /usr/bin/ cp mk-docker-opts.sh /usr/bin/
清除網絡中遺留的docker 網絡 (docker0, flannel0 等)mysql
ifconfig
linux
若是存在 請刪除,以避免發生沒必要要的未知錯誤nginx
ip link delete docker0
sql
使用動態CA配置update-ca-trust force-enable
docker
拷貝ca根證書到指定目錄cp /etc/kubernetes/ssl/ca.pem /etc/pki/ca-trust/source/anchors/
centos
生效update-ca-trust extract
網絡
etcd節點執行tcp
etcdctl --endpoint https://192.168.116.123:2379 set /flannel/network/config '{"Network":"10.254.0.0/16"}'
設置flanneld.service優化
vi /usr/lib/systemd/system/flanneld.service [Unit] Description=Flanneld overlay address etcd agent After=network.target After=network-online.target Wants=network-online.target After=etcd.service Before=docker.service [Service] Type=notify EnvironmentFile=/etc/sysconfig/flanneld EnvironmentFile=-/etc/sysconfig/docker-network ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS ExecStartPost=/usr/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker Restart=on-failure [Install] WantedBy=multi-user.target RequiredBy=docker.service
vi /etc/sysconfig/flanneld
修改以下信息:
FLANNEL_ETCD_ENDPOINTS="https://192.168.116.123:2379" FLANNEL_ETCD_PREFIX="/flannel/network" FLANNEL_OPTIONS="--iface=eno1"
eno1爲物理網卡的網卡名
vi /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS=
能夠爲空
vi /usr/bin/flanneld-start
#!/bin/sh exec /usr/bin/flanneld \ -etcd-endpoints=${FLANNEL_ETCD_ENDPOINTS:-${FLANNEL_ETCD}} \ -etcd-prefix=${FLANNEL_ETCD_PREFIX:-${FLANNEL_ETCD_KEY}} \ "$@"
賦執行權限
chmod +x /usr/bin/flanneld-start
確保docker已中止
systemctl stop docker
啓動flanneld服務
systemctl daemon-reload systemctl enable flanneld systemctl start flanneld
查看flannel
ip a
docker0應該和flannel0在同一ip段,且兩臺機器間的docker0地址能夠相互ping通。
上傳
docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
安裝
rpm -ivh docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
若是缺乏依賴,
yum localinstall docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
vi /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 ExecStart=/usr/bin/dockerd --insecure-registry=192.168.116.123:80 $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
註解:--insecure-registry=192.168.116.123:80 是因爲Harbor沒使用https,因此必須在docker裏配置這個參數,才能訪問Harbor。
mkdir –p /usr/lib/systemd/system/docker.service.d cd /usr/lib/systemd/system/docker.service.d mk-docker-opts.sh -i source /run/flannel/subnet.env vi /usr/lib/systemd/system/docker.service.d/flannel.conf [Service] EnvironmentFile=-/run/flannel/docker
systemctl daemon-reload systemctl enable docker systemctl start docker
docker-compose-Linux-x86_64 harbor-offline-installer-v1.1.1.tgz pod-infrastructure.tar cp docker-compose-Linux-x86_64 /usr/bin/docker-compose chmod +x /usr/bin/docker-compose tar -xzvf harbor-offline-installer-v1.1.1.tgz
cd harbor vi harbor.cfg
我這裏Harbor沒有配置Https,因此只須要修改 hostname爲Harbor所在主機的ip便可,我Harbor是裝在master上,因此hostname=192.168.116.123
cd /root/harbor ./install.sh
cd /root/harbor/ docker-compose stop docker-compose up –d
查看docker-compose ps
[root@master-123 harbor]# docker-compose ps
Name Command State Ports ------------------------------------------------------------------------------------------------------------------------------ harbor-adminserver /harbor/harbor_adminserver Up harbor-db docker-entrypoint.sh mysqld Up 3306/tcp harbor-jobservice /harbor/harbor_jobservice Up harbor-log /bin/sh -c crond && rm -f ... Up 127.0.0.1:1514->514/tcp harbor-ui /harbor/harbor_ui Up nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp registry /entrypoint.sh serve /etc/ ... Up 5000/tcp
我對flannel在kubernetes中的簡單理解就是,flannel將原本2個宿主機中不能夠相互通訊的pod放到了一個虛擬網絡內,使得kubernetes集羣內全部pod彷彿是在同一個內網,能夠相互通訊。
Harbor做爲一個私有倉庫,首先自己的做用確定是存儲鏡像,也就是docker裏的image,在kubernetes中,咱們在配置pod時,都會爲pod指定image的地址,當建立pod的時候,node會自動將image拉取下來,而後本地運行,造成pod。可是因爲國內對國外網絡訪問的不可靠以及爲了速度上的優化和管理上的方便,咱們選擇本身搭建一個私有的倉庫,也就是Harbor。在有了Harbor之後,咱們能夠本身上傳鏡像到Harbor,而後pod就只用拉取Harbor裏的鏡像,而且Harbor還提供同步複製的功能,很容易就能實現高可用配置。