k8s node 宕机
1.查看当前的项目运行
无论是web访问还是看log日志 都能请求到我的这个项目 接下来演示下宿主机挂掉的流程
2.前提准备
首先设置副本至少2个
[root@hdss7-21 ~]# kubectl delete node hdss7-22.host.com
这里要删除挂掉的node 如果不删除k8s会认为短暂的不可达 但用户访问可能会出现网络不可达。这块的话可以写脚本进行监控宿主机。
删除之后k8s 自己会触发自愈机制,然后dashboard 会从21上启动,会将pod 调度到node21上
然后将前端nignx负载注释掉
[root@hdss7-11 ~]# vim /etc/nginx/nginx.conf
stream {
upstream kube-apiserver {
server 192.168.40.21:6443 max_fails=3 fail_timeout=30s;
# server 192.168.40.22:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
include proxy_params;
}
}
[root@hdss7-11 ~]# cat /etc/nginx/conf.d/od.com.conf
upstream default_backend_traefik {
server 192.168.40.21:81 max_fails=3 fail_timeout=10s;
#server 192.168.40.22:81 max_fails=3 fail_timeout=10s;
}
server {
server_name *.od.com;
location / {
proxy_pass http://default_backend_traefik;
proxy_set_header Host $http_host;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
}
[root@hdss7-11 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@hdss7-11 ~]# nginx -s reload
再次访问dubbo项目已经正常了
3.节点恢复
22节点恢复 他会自动启动自身的服务加入到集群内部
[root@hdss7-22 ~]# supervisorctl status
etcd-server-7-22 STARTING
flanneld-7-22 STARTING
kube-apiserver-7-22 STARTING
kube-controller-manager-7-22 STARTING
kube-kubelet-7-22 STARTING
kube-proxy-7-22 STARTING
kube-scheduler-7-22 STARTING
[root@hdss7-22 ~]# kubectl label node hdss7-22.host.com node-role.kubernetes.io/master=
[root@hdss7-22 ~]# kubectl label node hdss7-22.host.com node-role.kubernetes.io/node=
去掉前端nginx注释即可