成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Kubernetes多節(jié)點(diǎn)二進(jìn)制線網(wǎng)部署(實(shí)例!!!)-創(chuàng)新互聯(lián)

前情回顧

部署K8s多節(jié)點(diǎn),首先得署單節(jié)master的k8s群集
詳情參考:
blog.csdn.net/caozhengtao1213/article/details/103987039

本篇內(nèi)容

1.部署Master2
2.Nginx負(fù)載均衡部署-keeplived服務(wù)
3.node節(jié)點(diǎn)修改配置文件統(tǒng)一VIP
4.創(chuàng)建Pod
5.創(chuàng)建UI顯示界面

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),黃浦企業(yè)網(wǎng)站建設(shè),黃浦品牌網(wǎng)站建設(shè),網(wǎng)站定制,黃浦網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,黃浦網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

環(huán)境準(zhǔn)備

角色 地址 安裝組件
master192.168.142.129kube-apiserver kube-controller-manager kube-scheduler etcd
master2192.168.142.120kube-apiserver kube-controller-manager kube-scheduler
node1192.168.142.130kubelet kube-proxy docker flannel etcd
node2192.168.142.131kubelet kube-proxy docker flannel etcd
nginx1(lbm)192.168.142.140nginx keepalived
nginx2(lbb)192.168.142.150nginx keepalived
VIP192.168.142.20-

資源包鏈接:

https://pan.baidu.com/s/183G9ZzBNdcUUFV7Y8-K4CQ 

提取碼:6z0j 

一、部署Master2

1.遠(yuǎn)程復(fù)制master的相關(guān)目錄

  • 關(guān)閉防火墻及安全功能
systemctl stop firewalld.service
setenforce 0
  • 復(fù)制kubernetes目錄到master2
scp -r /opt/kubernetes/ root@192.168.142.120:/opt
  • 復(fù)制etcd目錄到master2(內(nèi)含證書(shū))
scp -r /opt/etcd/ root@192.168.142.120:/opt
  • 復(fù)制服務(wù)啟動(dòng)腳本到master2
scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service root@192.168.142.120:/usr/lib/systemd/system/

2.修改kube-apiserver配置文件

vim /opt/kubernetes/cfg/kube-apiserver

#將第5和7行IP地址改為master2主機(jī)的地址
--bind-address=192.168.142.120 \
--advertise-address=192.168.142.120 \

3.啟動(dòng)服務(wù)并設(shè)定開(kāi)機(jī)自啟

systemctl start kube-apiserver.service 
systemctl enable kube-apiserver.service

systemctl start kube-controller-manager.service 
systemctl enable kube-controller-manager.service

systemctl start kube-scheduler.service
systemctl enable kube-scheduler.service

4.追加環(huán)境變量并生效

vim /etc/profile
#末尾追加
export PATH=$PATH:/opt/kubernetes/bin/

source /etc/profile

5.查看node節(jié)點(diǎn)

kubectl get node
NAME              STATUS   ROLES    AGE     VERSION
192.168.142.130   Ready    <none>   10d12h   v1.12.3
192.168.142.131   Ready    <none>   10d11h   v1.12.3

二、Nginx負(fù)載均衡部署-keeplived服務(wù)

1.在lbm&lbb端的操作,安裝nginx服務(wù)

  • 把nginx.sh和keepalived.conf腳本拷貝到家目錄(后面會(huì)用到)
#nginx.sh

cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
EOF

stream {

   log_format  main  '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';
    access_log  /var/log/nginx/k8s-access.log  main;

    upstream k8s-apiserver {
        server 10.0.0.3:6443;
        server 10.0.0.8:6443;
    }
    server {
                listen 6443;
                proxy_pass k8s-apiserver;
    }
    }
#keepalived.conf
! Configuration File for keepalived 

global_defs { 
   # 接收郵件地址 
   notification_email { 
     acassen@firewall.loc 
     failover@firewall.loc 
     sysadmin@firewall.loc 
   } 
   # 郵件發(fā)送地址 
   notification_email_from Alexandre.Cassen@firewall.loc  
   smtp_server 127.0.0.1 
   smtp_connect_timeout 30 
   router_id NGINX_MASTER 
} 

vrrp_script check_nginx {
    script "/usr/local/nginx/sbin/check_nginx.sh"
}

vrrp_instance VI_1 { 
    state MASTER 
    interface eth0
    virtual_router_id 51 # VRRP 路由 ID實(shí)例,每個(gè)實(shí)例是唯一的 
    priority 100    # 優(yōu)先級(jí),備服務(wù)器設(shè)置 90 
    advert_int 1    # 指定VRRP 心跳包通告間隔時(shí)間,默認(rèn)1秒 
    authentication { 
        auth_type PASS      
        auth_pass 1111 
    }  
    virtual_ipaddress { 
        10.0.0.188/24 
    } 
    track_script {
        check_nginx
    } 
}

mkdir /usr/local/nginx/sbin/ -p
vim /usr/local/nginx/sbin/check_nginx.sh

count=$(ps -ef |grep nginx |egrep -cv "grep|$$")

if [ "$count" -eq 0 ];then
    /etc/init.d/keepalived stop
fi

chmod +x /usr/local/nginx/sbin/check_nginx.sh
  • 編輯nginx.repo文件
vim /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
  • 安裝nginx服務(wù)
yum install nginx -y
  • 添加四層轉(zhuǎn)發(fā)
vim /etc/nginx/nginx.conf
#在第12行下追加以下內(nèi)容
stream {

   log_format  main  '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';
    access_log  /var/log/nginx/k8s-access.log  main;

    upstream k8s-apiserver {
        server 192.168.142.129:6443;        #此處為master的ip地址
        server 192.168.142.120:6443;        #此處為master2的ip地址
    }
    server {
                listen 6443;
                proxy_pass k8s-apiserver;
    }
    }

2.部署keeplived服務(wù)

#安裝keepalived
yum install keepalived -y

復(fù)制前面的keepalived.conf配置文件,覆蓋安裝后原有的配置文件
cp keepalived.conf /etc/keepalived/keepalived.conf

vim /etc/keepalived/keepalived.conf

script "/etc/nginx/check_nginx.sh"      #18行,目錄改為/etc/nginx/,腳本后寫(xiě)
interface ens33     #23行,eth0改為ens33,此處的網(wǎng)卡名稱可以使用ifconfig命令查詢
virtual_router_id 51        #24行,vrrp路由ID實(shí)例,每個(gè)實(shí)例是唯一的
priority 100            #25行,優(yōu)先級(jí),備服務(wù)器設(shè)置90
virtual_ipaddress {     #31行,
192.168.142.20/24   #32行,vip地址改為之前設(shè)定好的192.168.142.20
#38行以下全部刪除

vim /etc/nginx/check_nginx.sh
#統(tǒng)計(jì)數(shù)量       
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")    #統(tǒng)計(jì)數(shù)量
#匹配為0,關(guān)閉keepalived服務(wù)
if [ "$count" -eq 0 ];then
    systemctl stop keepalived
fi

chmod +x /etc/nginx/check_nginx.sh

#啟動(dòng)服務(wù)
systemctl start keepalived
  • 查看地址信息
ip a
# lbm地址信息

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:eb:11:2a brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.140/24 brd 192.168.142.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.142.20/24 scope global secondary ens33  //漂移地址在lb01中
       valid_lft forever preferred_lft forever
    inet6 fe80::53ba:daab:3e22:e711/64 scope link 
       valid_lft forever preferred_lft forever

#lbb地址信息

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c9:9d:88 brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.150/24 brd 192.168.142.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::55c0:6788:9feb:550d/64 scope link 
       valid_lft forever preferred_lft forever
  • 驗(yàn)證地址漂移
#停止lbm端的nginx服務(wù)
pkill nginx

#查看服務(wù)狀態(tài)
systemctl status nginx
systemctl status keepalived.service

#此時(shí)判斷條件若為0,keepalived服務(wù)則是停止的
ps -ef |grep nginx |egrep -cv "grep|$$"
  • 查看地址信息
ip a
# lbm地址信息

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:eb:11:2a brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.140/24 brd 192.168.142.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::53ba:daab:3e22:e711/64 scope link 
       valid_lft forever preferred_lft forever

#lbb地址信息

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c9:9d:88 brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.150/24 brd 192.168.142.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.142.20/24 scope global secondary ens33  //漂移地址在lb01中
       valid_lft forever preferred_lft forever
    inet6 fe80::55c0:6788:9feb:550d/64 scope link 
       valid_lft forever preferred_lft forever
  • 恢復(fù)操作
#在lbm端啟動(dòng)nginx和keepalived服務(wù)
systemctl start nginx
systemctl start keepalived
  • 漂移地址回歸lbm端
ip a
# lbm地址信息

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:eb:11:2a brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.140/24 brd 192.168.142.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.142.20/24 scope global secondary ens33  //漂移地址在lb01中
       valid_lft forever preferred_lft forever
    inet6 fe80::53ba:daab:3e22:e711/64 scope link 
       valid_lft forever preferred_lft forever

三、node節(jié)點(diǎn)修改配置文件統(tǒng)一VIP(bootstrap.kubeconfig,kubelet.kubeconfig)

cd /opt/kubernetes/cfg/
#配置文件統(tǒng)一修改為VIP
vim /opt/kubernetes/cfg/bootstrap.kubeconfig

server: https://192.168.142.20:6443     
#第5行改為Vip的地址

vim /opt/kubernetes/cfg/kubelet.kubeconfig
server: https://192.168.142.20:6443 
#第5行改為Vip的地址

vim /opt/kubernetes/cfg/kube-proxy.kubeconfig
server: https://192.168.142.20:6443     
#第5行改為Vip的地址
  • 替換完成后自檢
grep 20 *
bootstrap.kubeconfig:    server: https://192.168.142.20:6443
kubelet.kubeconfig:    server: https://192.168.142.20:6443
kube-proxy.kubeconfig:    server: https://192.168.142.20:6443
  • 在lb01上查看nginx的k8s日志
tail /var/log/nginx/k8s-access.log
192.168.142.140 192.168.142.129:6443 - [08/Feb/2020:19:20:40 +0800] 200 1119
192.168.142.140 192.168.142.120:6443 - [08/Feb/2020:19:20:40 +0800] 200 1119
192.168.142.150 192.168.142.129:6443 - [08/Feb/2020:19:20:44 +0800] 200 1120
192.168.142.150 192.168.142.120:6443 - [08/Feb/2020:19:20:44 +0800] 200 1120

四、創(chuàng)建Pod

  • 測(cè)試創(chuàng)建Pod
kubectl run nginx --image=nginx
  • 查看狀態(tài)
kubectl get pods
  • 綁定群集中的匿名用戶賦予管理員權(quán)限(解決日志不可看問(wèn)題)
kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous
  • 查看Pod網(wǎng)絡(luò)
kubectl get pods -o wid

五、創(chuàng)建UI顯示界面

  • 在master1上創(chuàng)建dashborad工作目錄
mkdir /k8s/dashboard

cd /k8s/dashboard
#上傳官方的文件到該目錄中
  • 創(chuàng)建頁(yè)面,注意順序
#授權(quán)訪問(wèn)api
kubectl create -f dashboard-rbac.yaml

#進(jìn)行加密
kubectl create -f dashboard-secret.yaml

#配置應(yīng)用
kubectl create -f dashboard-configmap.yaml

#控制器
kubectl create -f dashboard-controller.yaml

#發(fā)布出去進(jìn)行訪問(wèn)
kubectl create -f dashboard-service.yaml
  • 完成后查看創(chuàng)建在指定的kube-system命名空間下
kubectl get pods -n kube-system
  • 查看如何訪問(wèn)
kubectl get pods,svc -n kube-system
  • 在瀏覽器中輸入nodeIP地址就可以訪問(wèn)(谷歌瀏覽器無(wú)法訪問(wèn)題解決方法)

1.在master端操作,編寫(xiě)進(jìn)行證書(shū)自簽

vim dashboard-cert.sh

cat > dashboard-csr.json <<EOF
{
   "CN": "Dashboard",
   "hosts": [],
   "key": {
       "algo": "rsa",
       "size": 2048
   },
   "names": [
       {
           "C": "CN",
           "L": "NanJing",
           "ST": "NanJing"
       }
   ]
}
EOF

K8S_CA=$1
cfssl gencert -ca=$K8S_CA/ca.pem -ca-key=$K8S_CA/ca-key.pem -config=$K8S_CA/ca-config.json -profile=kubernetes dashboard-csr.json | cfssljson -bare dashboard
kubectl delete secret kubernetes-dashboard-certs -n kube-system
kubectl create secret generic kubernetes-dashboard-certs --from-file=./ -n kube-system

2.重新應(yīng)用新的自簽證書(shū)

bash dashboard-cert.sh /root/k8s/apiserver/

3.修改yaml文件

vim dashboard-controller.yaml
#在47行下追加以下內(nèi)容
          - --tls-key-file=dashboard-key.pem
          - --tls-cert-file=dashboard.pem

4.重新進(jìn)行部署

kubectl apply -f dashboard-controller.yaml

5.生成登錄令牌

  • 生成令牌
kubectl create -f k8s-admin.yaml
  • 將令牌保存
kubectl get secret -n kube-system
NAME                               TYPE                                  DATA   AGE
dashboard-admin-token-drs7c        kubernetes.io/service-account-token   3      60s
default-token-mmvcg                kubernetes.io/service-account-token   3      55m
kubernetes-dashboard-certs         Opaque                                10     10m
kubernetes-dashboard-key-holder    Opaque                                2      23m
kubernetes-dashboard-token-crqvs   kubernetes.io/service-account-token   3      23m
  • 查看令牌
kubectl describe secret dashboard-admin-token-drs7c -n kube-system

6.復(fù)制粘貼令牌后,登錄到UI界面

Kubernetes多節(jié)點(diǎn)二進(jìn)制線網(wǎng)部署(實(shí)例!!!)

Kubernetes多節(jié)點(diǎn)二進(jìn)制線網(wǎng)部署(實(shí)例!!!)

謝謝閱讀!

當(dāng)前文章:Kubernetes多節(jié)點(diǎn)二進(jìn)制線網(wǎng)部署(實(shí)例!!!)-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://jinyejixie.com/article12/dchdgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站策劃全網(wǎng)營(yíng)銷推廣、App設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
洛浦县| 永和县| 德江县| 临清市| 望谟县| 嘉黎县| 万源市| 兰溪市| 穆棱市| 施秉县| 清丰县| 汽车| 安岳县| 绩溪县| 壤塘县| 偏关县| 白水县| 左云县| 忻城县| 玛沁县| 长汀县| 渑池县| 潮州市| 乃东县| 尖扎县| 和顺县| 将乐县| 富阳市| 肇源县| 和平区| 冀州市| 教育| 英吉沙县| 越西县| 五指山市| 海口市| 珠海市| 会昌县| 辛集市| 陵水| 砚山县|