(三)Kubernetes/K8s 高可用架构
admin
2023-02-03 01:20:04
0

(三)Kubernetes/K8s 高可用架构
高可用架构 采用多master+多lb+keepalive的方案实现(注意其中lb的ip 地址的证书)
1,多master安装
将原master 1 部署文件拷贝到新master,修改bind 地址 启动 注意 由于需要连接etcd 需要拷贝etcd 的证书

scp –r /opt/kubernetes root@192.168.0.102:/opt
scp –r /opt/etcd/ssl root@192.168.0.102:/opt/etcd
scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service root@192.168.31.64:/usr/lib/systemd/system
##修改apiserver配置文件为本地IP
vim  /opt/kubernetes/cfg/kube-apiserver.conf
--bind-address=192.168.0.102 \
--secure-port=6443 \
--advertise-address=192.168.0.102 \
#启动
for i in $(ls /opt/kubernetes/bin/);do systemctl start $i;systemctl enable $i; done

lb部署
lb--nginx-mater

#安装Nginx+Keepalived
rpm -ivh http://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.16.0-1.el7.ngx.x86_64.rpm
vim /etc/nginx/nginx.conf 
##注意添加的配置文件的位置 特别是需要inclued 插入放于events  和http 之间
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.0.101:6443;    ## 后端安装master 地址
                server 192.168.0.102:6443;
            }

    server {
       listen 6443;
       proxy_pass k8s-apiserver;
    }
}

keepalived 高可用

yum install keepalived
vi /etc/keepalived/keepalived.conf
global_defs { 
   notification_email { 
     acassen@firewall.loc 
     failover@firewall.loc 
     sysadmin@firewall.loc 
   } 
   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/keepalived/check_nginx.sh"
        }

vrrp_instance VI_1 { 
    state MASTER 
    interface ens33  ## 自己机器网卡的名称
    virtual_router_id 51 # VRRP 路由 ID实例,每个实例是唯一的 
    priority 100    # 优先级,备服务器设置 90 
    advert_int 1    # 指定VRRP 心跳包通告间隔时间,默认1秒 
    authentication { 
        auth_type PASS      
        auth_pass 1111 
    }  
    virtual_ipaddress { 
        192.168.0.105/24    ## 虚拟vip地址
    } 
    track_script {
        check_nginx
    } 
}

判断nginx 进程脚本

#!/bin/bash
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")

if [ "$count" -eq 0 ];then
    exit 1
else
    exit 0
fi
systemctl start keepalived
systemctl enable keepalived

lb-nginx-backup
nginx 安装同上

yum install keepalived
vi /etc/keepalived/keepalived.conf
global_defs { 
   notification_email { 
     acassen@firewall.loc 
     failover@firewall.loc 
     sysadmin@firewall.loc 
   } 
   notification_email_from Alexandre.Cassen@firewall.loc  
   smtp_server 127.0.0.1 
   smtp_connect_timeout 30 
   router_id NGINX_BACKUP
} 

vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx.sh"
}

vrrp_instance VI_1 { 
    state BACKUP      ##标注角色
    interface ens33    ##自己网卡的名称
    virtual_router_id 51 # VRRP 路由 ID实例,每个实例是唯一的 
    priority 90    # 优先级,备服务器设置 90 
    advert_int 1    # 指定VRRP 心跳包通告间隔时间,默认1秒 
    authentication { 
        auth_type PASS      
        auth_pass 1111 
    }  
    virtual_ipaddress { 
        192.168.0.105/24
    } 
    track_script {
        check_nginx
    } 
}

# cat /etc/keepalived/check_nginx.sh 
#!/bin/bash
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")

if [ "$count" -eq 0 ];then
    exit 1
else
    exit 0
fi

# systemctl start keepalived
# systemctl enable keepalived

测试

##在lb master节点
ip addr show  ## 查看vip 是否绑定到了网卡上面 关闭nginx 查看vip 是否能漂移到backup 上面

修改所有node apiserver地址填写为vip

cd /opt/kubernetes/cfg
grep 192 *
bootstrap.kubeconfig:    server: https://192.168.31.63:6443
kubelet.kubeconfig:    server: https://192.168.31.636443
kube-proxy.kubeconfig:    server: https://192.168.31.63:6443

#批量修改:
sed -i 's#192.168.0.63#192.168.0.105 *
 curl -k --header "Authorization: Bearer c47ffb939f5ca36231d9e3121a252940" https://192.168.31.60:6443/version
##此teken 是bootstarp 的token

相关内容

热门资讯

国际观察:中拉人工智能合作持续... 张冰倩 为进一步支持全球人工智能发展、推进全球人工智能能力建设,未来5年,中国将面向发展中国家提供5...
共商汽车产业全球合作新路径 G... 当前,汽车产业正加速向绿色化、智能化、国际化、融合化发展,汽车供应链受到大国竞争与地缘政治冲突扰动。...
内蒙古耕种收综合机械化率达91... 7月22日,记者从2026年中国农机推广田间日活动上获悉,内蒙古农作物耕种收综合机械化率达到91%,...
华为黄健:在算力、存力和运力三... 7月17日至20日,以“智能伙伴,共创未来”为主题的2026世界人工智能大会(WAIC)暨人工智能全...
苹果、谷歌都没留住月之暗面创始... 英国《金融时报》7月23日刊发评论《为什么美国正在失去中国人工智能明星?》,文章谈到,月之暗面(Mo...
陪伴大家十几年的充电宝,大概要... 要说这两年最尴尬的数码配件,托尼觉得充电宝绝对算一个。 以前它的对手还都是同行 —— 大家一起卷容量...
女子举报遭公安局一副支队长猥亵... 记者 商泽阳近日,安徽的薛女士向潮新闻记者反映,称其于2025年4月遭到时任亳州市公安局经侦支队副支...
邹市明妻子冉莹颖回应“债还完了... 2026年7月22日,综艺《姐姐当家2》播出的内容中,张泉灵就冉莹颖的婚姻状况提出犀利问题,引发关注...
美方指控中国人工智能企业抄袭,... 据凤凰卫视报道,美国白宫科技政策办公室主任克拉齐奥斯7月22日指控中国人工智能企业月之暗面在开发最新...
广西一公园大树倾倒3人身亡 近日,广西一公园大树倾倒,造成人员伤亡,引发关注。7月23日,玉林市博白县人民政府办公室工作人员对中...