接上一篇多節(jié)點(diǎn)部署(2)部署負(fù)載均衡
負(fù)載均衡
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到東豐網(wǎng)站設(shè)計(jì)與東豐網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋東豐地區(qū)。
Nginx1:192.168.13.128/24
Nginx2:192.168.13.129/24
Master節(jié)點(diǎn)
master1:192.168.13.131/24 kube-apiserver kube-controller-manager kube-scheduler etcd
master2:192.168.13.130/24 kube-apiserver kube-controller-manager kube-scheduler etcd
Node節(jié)點(diǎn)
node1:192.168.13.132/24 kubelet kube-proxy docker flannel etcd
node2:192.168.13.133/24 kubelet kube-proxy docker flannel etcd
[root@nginx01 ~]# rz -E ##上傳nginx腳本和keepalive配置文件
[root@nginx01 ~]# ls
keepalived.conf nginx.sh
[root@nginx01 ~]# systemctl stop firewalld.service ##關(guān)閉防火墻
[root@nginx01 ~]# setenforce 0
vim nginx.sh ##nginx腳本
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;
}
}
[root@nginx01 ~]# vim /etc/yum.repos.d/nginx.repo ##配置nginx的yum源
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
[root@nginx01 ~]# yum list ##更新yum
[root@nginx01 ~]# yum install -y nginx ##下載Nginx
[root@nginx01 ~]# vim /etc/nginx/nginx.conf
events {
worker_connections 1024;
} ##在此處下面添加四層轉(zhuǎn)發(fā)配置
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.13.131:6443; ##master01地址
server 192.168.13.130:6443; ##master02地址
}
server {
listen 6443;
proxy_pass k8s-apiserver;
}
}
[root@nginx01 ~]# systemctl start nginx ##開啟nginx服務(wù)
##可以修改/usr/share/nginx/html/index.html主頁(yè)區(qū)分主master從backup
##瀏覽器查看兩個(gè)nginx網(wǎng)站
[root@nginx01 ~]# yum install -y keepalived ##安裝keepalived服務(wù)
[root@nginx01 ~]# cp keepalived.conf /etc/keepalived/keepalived.conf ##復(fù)制配置文件
[root@nginx01 ~]# vim /etc/keepalived/keepalived.conf ##主master的配置文件修改
! 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 "/etc/nginx/check_nginx.sh" ##nginx檢查腳本,需要自己去編輯的
}
vrrp_instance VI_1 {
state MASTER ##主服務(wù)
interface ens33
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 ##驗(yàn)證不需要修改,主從一致
auth_pass 1111
}
virtual_ipaddress {
192.168.13.100/24 ##虛擬ip地址
}
track_script {
check_nginx
}
}
[root@nginx02 ~]# vim /etc/keepalived/keepalived.conf ##備backup的配置文件修改
! 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 "/etc/nginx/check_nginx.sh" ##nginx檢查腳本
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51 # VRRP 路由 ID實(shí)例,每個(gè)實(shí)例是唯一的
priority 90 # 優(yōu)先級(jí),備服務(wù)器設(shè)置 90
advert_int 1 # 指定VRRP 心跳包通告間隔時(shí)間,默認(rèn)1秒
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.13.100/24
}
track_script {
check_nginx
}
}
[root@nginx01 ~]# vim /etc/nginx/check_nginx.sh ##編輯nginx檢查腳本
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
systemctl stop keepalived
fi
[root@nginx01 ~]# chmod +x /etc/nginx/check_nginx.sh ##給執(zhí)行權(quán)限
[root@nginx01 ~]# systemctl start keepalived.service ##開啟服務(wù)
[root@nginx01 ~]# ip a ##查看地址信息
inet 192.168.13.100/24 scope global secondary ens33 ##漂移地址在master上
##在nginx01中關(guān)閉nginx服務(wù),此時(shí)keepalived服務(wù)也關(guān)閉了(check_nginx.sh)
[root@nginx01 ~]# pkill nginx
##在nginx02中查看漂移地址
[root@nginx02 ~]# ip a ##此時(shí)13.100在nginx02上
##在nginx01上恢復(fù)nginx和keepalived服務(wù),查看漂移地址
[root@nginx01 ~]# systemctl start nginx
[root@nginx01 ~]# systemctl start keepalived.service
[root@nginx01 ~]# ip a ##此時(shí)漂移地址又到了nginx01上
##用瀏覽器訪問(wèn)虛擬ip
[root@node01 ~]# vim /opt/kubernetes/cfg/bootstrap.kubeconfig
server: https://192.168.13.100:6443
[root@node01 ~]# vim /opt/kubernetes/cfg/kubelet.kubeconfig
server: https://192.168.13.100:6443
[root@node01 ~]# vim /opt/kubernetes/cfg/kube-proxy.kubeconfig
server: https://192.168.13.100:6443
[root@node01 ~]# cd /opt/kubernetes/cfg/ ##切換到配置文件目錄
[root@node01 cfg]# grep 100 * ##查看修改的情況
bootstrap.kubeconfig: server: https://192.168.13.100:6443
kubelet.kubeconfig: server: https://192.168.13.100:6443
kube-proxy.kubeconfig: server: https://192.168.13.100:6443
[root@node01 cfg]# systemctl restart kubelet.service ##重啟兩個(gè)服務(wù)
[root@node01 cfg]# systemctl restart kube-proxy.service
##在nginx01上查看訪問(wèn)日志
[root@nginx01 ~]# tail /var/log/nginx/k8s-access.log
192.168.13.132 k8s-apiserver - [10/Feb/2020:13:17:11 +0800] 502 0
192.168.13.132 k8s-apiserver - [10/Feb/2020:13:17:11 +0800] 502 0
192.168.13.132 k8s-apiserver - [10/Feb/2020:13:17:11 +0800] 502 0
192.168.13.133 k8s-apiserver - [10/Feb/2020:13:17:11 +0800] 502 0
192.168.13.133 k8s-apiserver - [10/Feb/2020:13:17:11 +0800] 502 0
[root@master01 ~]# kubectl get pods ##查看pod
No resources found.
[root@master01 ~]# kubectl run nginx --image=nginx ##創(chuàng)建pod
[root@master01 ~]# kubectl get pods ##查看pod狀態(tài)是正在創(chuàng)建的狀態(tài)
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-brjlj 0/1 ContainerCreating 0 86s
[root@master01 ~]# kubectl get pods ##此時(shí)pod是已經(jīng)運(yùn)行的狀態(tài)
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-brjlj 1/1 Running 0 87s
[root@master01 ~]# kubectl logs nginx-dbddb74b8-brjlj ##此時(shí)日志文件不能查看
[root@master01 ~]# kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous
##提權(quán)后日志文件就可以查看了
[root@master01 ~]# kubectl get pods -o wide ##查看pod網(wǎng)絡(luò),此時(shí)pod容器分配到node01上
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-dbddb74b8-brjlj 1/1 Running 0 5m18s 172.17.45.2 192.168.13.132 <none>
[root@node01 cfg]# curl 172.17.45.2 ##此時(shí)就可以訪問(wèn)nginx信息
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
##用node01虛擬機(jī)的瀏覽器訪問(wèn)
[root@master01 ~]# kubectl logs nginx-dbddb74b8-brjlj
172.17.45.1 - - [10/Feb/2020:05:29:23 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
文章標(biāo)題:Kubernetes二進(jìn)制部署——負(fù)載均衡部署(3)-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://jinyejixie.com/article12/gpjgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站改版、建站公司、微信小程序、動(dòng)態(tài)網(wǎng)站、網(wǎng)站維護(hù)
聲明:本網(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)
猜你還喜歡下面的內(nèi)容