k8s多节点

地址规划
master1:192.168.175.90
master2:192.168.175.93

node节点
node1:192.168.175.91
node2:192.168.175.92

负载均衡
nginx1:192.168.175.94
nginx2:192.168.175.95

加入master节点
在master1节点操作

///复制/kubernetes/目录到master02节点上
[root@localhost kubeconfig]# scp -r /opt/kubernetes/ root@192.168.175.93:/opt
//复制master1中三个组件的启动脚本:kube-apiserver.service、kube-controller-manager.service、kube-scheduler.service
[root@localhost kubeconfig]# scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service root@192.168.175.93:/usr/lib/systemd/system/

``


master2操作

```bash
//修改kube-apiserver文件
cd /opt/kubernetes/cfg/
 vi kube-apiserver
--bind-address=192.168.175.93    ///修改本机地址
--advertise-address=192.168.175.93    ///修改本机地址
制作master2 的ETCD证书
scp -r /opt/etcd/ root@192.168.175.93:/opt/
启动 master2 的三个组件
//开启 apiserver 组件
systemctl start kube-apiserver.service 
systemctl enable kube-apiserver.service
开启 controller-manager 组件
systemctl start kube-controller-manager.service
systemctl enable kube-controller-manager.service
//开启 scheduler 组件
systemctl start kube-scheduler.service
systemctl enable kube-scheduler.service 
//增加环境变量,优化kubectl命令
vi /etc/profile
在末尾添加:
export PATH=$PATH:/opt/kubernetes/bin
source /etc/profile

在master2 上查看node节点情况

kubectl get node

部署负载均衡

//挂载配置文件keepalived.conf 
vim keepalived.conf 
! Configuration File for keepalived 
 
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 "/usr/local/nginx/sbin/check_nginx.sh"
}
vrrp_instance VI_1 { 
    state MASTER 
    interface eth0
    virtual_router_id 51 # VRRP 路由 ID实例,每个实例是唯一的 
    priority 100    # 优先级,备服务器设置 90 
    advert_int 1    # 指定VRRP 心跳包通告间隔时间,默认1秒 
    authentication { 
        auth_type PASS      
        auth_pass 1111 
    }  
    virtual_ipaddress { 
        10.0.0.188/24 
    } 
    track_script {
        check_nginx
    } 
}

systemctl stop firewalld.service
  setenforce 0
 //编辑nginx的源,并且安装nginx
 [root@nginx_lbm ~]# cat /etc/yum.repos.d/nginx.repo
 [nginx]
 name=nginx repo
 baseurl=http://nginx.org/packages/centos/7/$basearch/
 gpgcheck=0
 //重新加载yum 仓库
 [root@nginx_lbm ~]# yum list
 //安装
 nginx[root@nginx_lbm ~]# yum install nginx -y
  //在nginx配置文件中添加负载均衡
 [root@nginx_lbm ~]# vi /etc/nginx/nginx.conf 
 
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.175.94:6443;
		server 192.168.175.95:6443;
	}
		server {
			listen 6443;
			proxy_pass k8s-apiserver;
	}
	}
	//检查配置文件是否正确
	[root@nginx_lbm ~]# nginx -t
	nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
	nginx: configuration file /etc/nginx/nginx.conf test is successful
	//编辑页面区分master和backup
	cd /usr/share/nginx/html/
	vi index.html
	
	<h1>www.backup.com</h1>
	//开启nginx服务
	systemctl start nginx


安装keepalived服务
yum install keeepalived -y
///覆盖keepalived的配置文件
cp keepalived.conf /etc/keepalived/keepalived.conf
///配置文件
vim /etc/keepalived/keepalived.conf
	
! Configuration File for keepalived
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/nginx/check_nginx.sh"
}
	vrrp_instance VI_1 {
	state MASTER         ##在nginx1,设置为master
	interface ens33        ##指定网卡名
	virtual_router_id 51     ##24行,vrrp路由ID实例,每个实例是唯一的
	priority 100        ##在master中优先级为100,backup优先级为90
	advert_int 1
	authentication { 
		auth_type PASS 
		auth_pass 1111 
	}
	virtual_ipaddress { 
		192.165.175.100      ///指定vip
	}

##指定执行上述的脚本
	track_script {
		check_nginx
	}
	}
//创建脚本
vi /etc/nginx/check_nginx.sh
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
	systemctl stop keepalived
fi
//添加权限
chmod +x /etc/nginx/check_nginx.sh

//启动服务
systemctl start keepalived.service

//查看vip
ip addr


nginx 2(backup)
//创建
keepalived的配置文件
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
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/nginx/check_nginx.sh"
	}
	
vrrp_instance VI_1 {
	state BACKUP    //此处的state为BACKUP
	interface ens33
	virtual_router_id 51
	priority 90         ##优先级为90
	 advert_int 1 
	 authentication {
	 auth_type PASS 
	 auth_pass 1111
	}
	virtual_ipaddress {
		192.168.175.100/24
	}
	track_script {
		check_nginx
	}
}	 	



vi /etc/nginx/check_nginx.sh

count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
	systemctl stop keepalived
fi


chmod +x /etc/nginx/check_nginx.sh 
systemctl start keepalived.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值