角色 | IP |
---|---|
master1 | 192.168.18.10 |
master2 | 192.168.18.40 |
node1 | 192.168.18.20 |
node2 | 192.168.18.30 |
LB1 | 192.168.18.50 |
LB2 | 192.168.18.60 |
VIP | 192.168.18.70 |
Tips:其他节点已在单节点部署
scp -r /opt/kubernetes/ [email protected]:/opt/
scp -r /usr/lib/systemd/system/{kube-apiserver,kube-scheduler,kube-controller-manager}.service [email protected]:/usr/lib/systemd/system/
scp -r /opt/etcd/ [email protected]:/opt/
vim /opt/kubernetes/cfg/kube-apiserver
#只需要修改:
--bind-address=192.168.18.40 \
--advertise-address=192.168.18.40 \
systemctl start kube-apiserver
systemctl enable kube-apiserver
systemctl start kube-controller-manager
systemctl enable kube-controller-manager
systemctl start kube-scheduler
systemctl enable kube-scheduler
vim /etc/profile
#末行添加
export PATH=$PATH:/opt/kubernetes/bin
source /etc/profile
kubectl get node
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
#加载yum仓库
yum list
yum install nginx -y
vim /etc/nginx/nginx.conf
#在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.18.10:6443;
server 192.168.18.40:6443;
}
server {
listen 6443;
proxy_pass k8s-apiserver;
}
}
vim /usr/share/nginx/html/index.html
#LB1
<h1>Welcome to master nginx!</h1>
#LB2
<h1>Welcome to backup nginx!</h1>
systemctl start nginx
yum install keepalived -y
修改Keepalived配置文件
vim /etc/keepalived/keepalived.conf
#修改
vrrp_script check_nginx {
script "/etc/nginx/check_nginx.sh"
}
vrrp_instance VI_1 {
state MASTER #备服务器改为BACKUP
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.18.70/24
}
track_script {
check_nginx
}
}
vim /etc/nginx/check_nginx.sh
chmod +x /etc/nginx/check_nginx.sh
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
systemctl stop keepalived
fi
cd /opt/kubernetes/cfg
vim bootstrap.kubeconfig
server: https://192.168.18.70:6443 #修改为VIP的地址
vim kubelet.kubeconfig
server: https://192.168.18.70:6443 #修改为VIP的地址
vim kube-proxy.kubeconfig
server: https://192.168.18.70:6443 #修改为VIP的地址
systemctl restart kubelet
systemctl restart kube-proxy
tail -f /var/log/nginx/k8s-access.log
kubectl run nginx --image=nginx
vim /opt/kubernetes/cfg/kubelet.config
#末行添加
authentication:
anonymous:
enabled: true
kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous
kubectl logs nginx-dbddb74b8-nn7z2