內(nèi)容要點(diǎn):
在咸陽等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),成都營銷網(wǎng)站建設(shè),外貿(mào)網(wǎng)站建設(shè),咸陽網(wǎng)站建設(shè)費(fèi)用合理。1、環(huán)境包準(zhǔn)備
2、部署etcd存儲(chǔ)
3、部署flannel網(wǎng)絡(luò)組件
一、環(huán)境準(zhǔn)備:
主機(jī) | 需要安裝的軟件 |
master(192.168.109.138) | kube-apiserver、kube-controller-manager、kube-scheduler、etcd |
node02(192.168.109.131) | kubelet、kube-proxy、docker 、flannel 、etcd |
node02(192.168.109.132) | kubelet、kube-proxy、docker 、flannel 、etcd |
以下是官方源碼包下載地址:https://github.com/kubernetes/kubernetes/releases?after=v1.13.1
etcd二進(jìn)制包地址:https://github.com/etcd-io/etcd/releases
二、部署 etcd 存儲(chǔ):
第一步:部署?master 先準(zhǔn)備好兩個(gè)腳本文件: 第一個(gè)腳本: vim?etcd-cert.sh ##定義ca證書: cat?>?ca-config.json?<?ca-csr.json?< ?server-csr.json?< $WORK_DIR/cfg/etcd #[Member] ETCD_NAME="${ETCD_NAME}" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://${ETCD_IP}:2380" ETCD_LISTEN_CLIENT_URLS="https://${ETCD_IP}:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://${ETCD_IP}:2380" ETCD_ADVERTISE_CLIENT_URLS="https://${ETCD_IP}:2379" ETCD_INITIAL_CLUSTER="etcd01=https://${ETCD_IP}:2380,${ETCD_CLUSTER}" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" EOF cat?< /usr/lib/systemd/system/etcd.service [Unit] Description=Etcd?Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify EnvironmentFile=${WORK_DIR}/cfg/etcd ExecStart=${WORK_DIR}/bin/etcd?\ --name=\${ETCD_NAME}?\ --data-dir=\${ETCD_DATA_DIR}?\ --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-advertise-peer-urls=\${ETCD_INITIAL_ADVERTISE_PEER_URLS}?\ --initial-cluster=\${ETCD_INITIAL_CLUSTER}?\ --initial-cluster-token=\${ETCD_INITIAL_CLUSTER_TOKEN}?\ --initial-cluster-state=new?\ --cert-file=${WORK_DIR}/ssl/server.pem?\ --key-file=${WORK_DIR}/ssl/server-key.pem?\ --peer-cert-file=${WORK_DIR}/ssl/server.pem?\ --peer-key-file=${WORK_DIR}/ssl/server-key.pem?\ --trusted-ca-file=${WORK_DIR}/ssl/ca.pem?\ --peer-trusted-ca-file=${WORK_DIR}/ssl/ca.pem Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF systemctl?daemon-reload systemctl?enable?etcd systemctl?restart?etcd
[root@master?~]#?mkdir?k8s [root@master?~]#?cd?k8s/ [root@master?k8s]#?ls etcd-cert.sh??etcd.sh [root@master?k8s]#?mkdir?etcd-cert [root@master?k8s]#?mv?etcd-cert.sh?etcd-cert [root@master?k8s]#?ls etcd-cert??etcd.sh [root@master?k8s]#?vim?cfssl.sh curl?-L?https://pkg.cfssl.org/R1.2/cfssl_linux-amd64?-o?/usr/local/bin/cfssl curl?-L?https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64?-o?/usr/local/bin/cfssljson curl?-L?https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64?-o?/usr/local/bin/cfssl-certinfo chmod?+x?/usr/local/bin/cfssl?/usr/local/bin/cfssljson?/usr/local/bin/cfssl-certinfo //下載cfssl官方包: [root@master?k8s]#?bash?cfssl.sh [root@master?k8s]#?ls?/usr/local/bin/ cfssl??cfssl-certinfo??cfssljson //cfssl:生成證書工具; ??cfssl-certinfo:查看證書信息; ??cfssljson:通過傳入json文件生成證書
[root@localhost?etcd-cert]#?cd?/usr/local/bin/ [root@localhost?bin]#?ls cfssl??cfssl-certinfo??cfssljson //cfssl:是生成證書工具; ??cfssljson:通過傳入json文件生成證書; ??cfssl-certinfo:是查看證書信息。 ?? [root@localhost?bin]#?chmod?777?cfssl?cfssl-certinfo?cfssljson???//添加權(quán)限 接下來是定義生成?ca?證書: [root@localhost?bin]#?cd?/root/k8s/etcd-cert/ cat?>?ca-config.json?<?ca-csr.json?< ?server-csr.json?< 第二步:將下載好的軟件包放到 /root/k8s/etcd-cert 目錄下
[root@master?etcd-cert]#?mv?*.tar.gz?../ [root@master?k8s]#?ls cfssl.sh??etcd-cert??etcd.sh??etcd-v3.3.10-linux-amd64.tar.gz??flannel-v0.10.0-linux-amd64.tar.gz??kubernetes-server-linux-amd64.tar.gz [root@master?k8s]#?tar?zvxf?etcd-v3.3.10-linux-amd64.tar.gz??//解壓 [root@master?k8s]#?ls?etcd-v3.3.10-linux-amd64 Documentation??etcd??etcdctl??README-etcdctl.md??README.md??READMEv2-etcdctl.md //配置文件、命令文件、證書: [root@master?k8s]#?mkdir?/opt/etcd/{cfg,bin,ssl}?-p [root@master?k8s]#?mv?etcd-v3.3.10-linux-amd64/etcd?etcd-v3.3.10-linux-amd64/etcdctl?/opt/etcd/bin/ //證書拷貝: [root@master?k8s]#?cp?etcd-cert/*.pem?/opt/etcd/ssl/ //進(jìn)入卡住狀態(tài)等待其他節(jié)點(diǎn)加入: [root@master?k8s]#?bash?etcd.sh?etcd01?192.168.109.138?etcd02=https://192.168.109.131:2380,etcd03=https://192.168.109.132:2380 //此時(shí),我們可以再開啟一個(gè)終端,就會(huì)發(fā)現(xiàn)?etcd進(jìn)程已經(jīng)開啟: [root@master?~]#?ps?-ef?|?grep?etcd//將證書拷貝到其他節(jié)點(diǎn)(提高效率,無需在配置了) [root@master?k8s]#?scp?-r?/opt/etcd/?root@192.168.109.131:/opt/ [root@master?k8s]#?scp?-r?/opt/etcd/?root@192.168.109.132:/opt/ //啟動(dòng)腳本拷貝其他節(jié)點(diǎn): [root@master?k8s]#?scp?/usr/lib/systemd/system/etcd.service?root@192.168.109.131:/usr/lib/systemd/system/ [root@master?k8s]#?scp?/usr/lib/systemd/system/etcd.service?root@192.168.109.132:/usr/lib/systemd/system/第三步:部署 node
1、修改?node01: [root@node01?~]#?vim?/opt/etcd/cfg/etcd? #[Member] ETCD_NAME="etcd02" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.109.131:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.109.131:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.109.131:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.109.131:2379" ETCD_INITIAL_CLUSTER="etcd01=https://192.168.109.138:2380,etcd02=https://192.168.109.131:2380,etcd03=https://192.168.109.138:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" //啟動(dòng): [root@node01?~]#?systemctl?start?etcd.service? [root@node01?~]#?systemctl?status?etcd.service? 2、修改?node02: [root@node02?~]#?vim?/opt/etcd/cfg/etcd? #[Member] ETCD_NAME="etcd03" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.109.132:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.109.132:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.109.132:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.109.132:2379" ETCD_INITIAL_CLUSTER="etcd01=https://192.168.109.138:2380,etcd02=https://192.168.109.131:2380,etcd03=https://192.168.109.132:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" //啟動(dòng): [root@node02?~]#?systemctl?start?etcd.service? [root@node02?~]#?systemctl?status?etcd.service第四步:檢測(cè)
在 master 上:
[root@master?etcd-cert]#?/opt/etcd/bin/etcdctl?--ca-file=ca.pem?--cert-file=server.pem?--key-file=server-key.pem?--endpoints="https://192.168.220.131:2379,https://192.168.220.140:2379,https://192.168.220.136:2379"?cluster-health集群狀態(tài)健康!
二、部署 flannel 網(wǎng)絡(luò):
首先所有 node 節(jié)點(diǎn)需要部署安裝 docker 引擎
1、Flannel 介紹:是 Overlay 網(wǎng)絡(luò)的一種,也是將源數(shù)據(jù)包封裝在另一種網(wǎng)絡(luò)包里面進(jìn)行路由轉(zhuǎn)發(fā)和通信,目前已經(jīng)支持 UDP、VXLAN、AWX VPC 和 GCE 路由等數(shù)據(jù)轉(zhuǎn)發(fā)方式。
Overlay Network:覆蓋網(wǎng)絡(luò),在基礎(chǔ)網(wǎng)絡(luò)上疊加的一種虛擬網(wǎng)絡(luò)技術(shù)模式,該網(wǎng)絡(luò)中的主機(jī)通過虛擬鏈路連接起來。
VXLAN:將源數(shù)據(jù)包封裝到 UDP 中,并使用基礎(chǔ)網(wǎng)絡(luò)的 IP/MAC 作為外層報(bào)文頭進(jìn)行封裝,然后在以太網(wǎng)上傳輸,達(dá)到目的地后由隧道端點(diǎn)解封并將數(shù)據(jù)發(fā)給目標(biāo)地址。
2、flannel 網(wǎng)絡(luò)配置:
1、寫入分配的子網(wǎng)段到ETCD中,供flannel使用:
[root@localhost?etcd-cert]#?/opt/etcd/bin/etcdctl?--ca-file=ca.pem?--cert-file=server.pem?--key-file=server-key.pem?--endpoints="https://192.168.220.131:2379,https://192.168.220.140:2379,https://192.168.220.136:2379"?set?/coreos.com/network/config?'{?"Network":?"172.17.0.0/16",?"Backend":?{"Type":?"vxlan"}}'2、查看寫入的信息:
[root@localhost?etcd-cert]#?/opt/etcd/bin/etcdctl?--ca-file=ca.pem?--cert-file=server.pem?--key-file=server-key.pem?--endpoints="https://192.168.220.131:2379,https://192.168.220.140:2379,https://192.168.220.136:2379"?get?/coreos.com/network/config3、拷貝軟件包到所有的 node 節(jié)點(diǎn)(只需要部署在node節(jié)點(diǎn)上即可):
[root@localhost?k8s]#?scp?flannel-v0.10.0-linux-amd64.tar.gz?root@192.168.109.131:/root [root@localhost?k8s]#?scp?flannel-v0.10.0-linux-amd64.tar.gz?root@192.168.109.132:/root4、所有 node 節(jié)點(diǎn)將壓縮包解壓:
tar?zvxf?flannel-v0.10.0-linux-amd64.tar.gz5、在node節(jié)點(diǎn)上,先創(chuàng)建k8s工作工作目錄:
[root@localhost?~]#?mkdir?/opt/kubernetes/{cfg,bin,ssl}?-p [root@localhost?~]#?mv?mk-docker-opts.sh?flanneld?/opt/kubernetes/bin/ 創(chuàng)建flannel腳本: [root@localhost?~]#?vim?flannel.sh #!/bin/bash ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"} cat?</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 cat?< /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 systemctl?daemon-reload systemctl?enable?flanneld systemctl?restart?flanneld 6、開啟 flannel 網(wǎng)絡(luò)功能:
[root@localhost?~]#?bash?flannel.sh?https://192.168.109.138:2379,https://192.168.109.131:2379,https://192.168.109.132:23797、配置 docker 連接 flannel:
[root@localhost?~]#?vim?/usr/lib/systemd/system/docker.service 添加和插入以下代碼: EnvironmentFile=/run/flannel/subnet.env $DOCKER_NETWORK_OPTIONS[root@localhost?~]#?cat?/run/flannel/subnet.env? DOCKER_OPT_BIP="--bip=172.17.93.1/24" DOCKER_OPT_IPMASQ="--ip-masq=false" DOCKER_OPT_MTU="--mtu=1450" //說明:bip指定啟動(dòng)時(shí)的子網(wǎng) DOCKER_NETWORK_OPTIONS="?--bip=172.17.93.1/24?--ip-masq=false?--mtu=1450" //重啟docker [root@localhost?~]#?systemctl?daemon-reload? [root@localhost?~]#?systemctl?restart?docker可以用 ifconfig 命令,查看 flannel 網(wǎng)絡(luò):
接下來是,測(cè)試ping通對(duì)方docker0網(wǎng)卡 證明flannel起到路由作用:
[root@localhost?~]#?docker?run?-it?centos:7?/bin/bash [root@bad98ca4fe31?/]#?yum?install?-y?net-tools [root@bad98ca4fe31?/]#?ifconfig再在另外一個(gè) node 上做一樣的操作,測(cè)試是否可以 ping通 兩個(gè)node中的centos:7容器
通過下圖,我們可以發(fā)現(xiàn),在 node01 上的容器,是可以 ping 通 node02 上的容器的,代表 flannel 網(wǎng)絡(luò)起到了作用。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站欄目:kubeernetes二進(jìn)制集群部署一——etcd組件、f-創(chuàng)新互聯(lián)
本文來源:http://weahome.cn/article/jcehj.html