hype-v上centos7部署高可用kubernetes集群实践
概述
在上一篇中已经实践了 非高可用的bubernetes集群的实践
普通的k8s集群当work node 故障时是高可用的,但是master node故障时将会发生灾难,因为k8s api server不可用
会导致整个集群群龙无首
所以本篇将在上篇的基础上扩展高可用的k8s 集群
其原理是将所有node对master的api请求通过负载均衡(haproxy)指向虚拟ip(keepalived)
而此虚拟ip由所有master节点通过优先级选举
在上篇中我已经做好了k8s环境的基础虚拟机镜像文件,所以我这篇将从恢复虚拟机镜像文件为起点
虚拟ip 192.168.1.200
m1 192.168.1.201
m2 192.168.1.202
w1 192.168.1.211
m1是matser node 1
w1是work node 1
命名自己按喜欢的来即可
在所有master节点上我需要做
1.修改host文件 加入hostname域名解析
[root@m1 ~]# [root@m1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.200 VIP
192.168.1.201 m1
192.168.1.202 m2
192.168.1.211 w1
2.修改hostname
[root@m1 ~]# hostnamectl set-hostname m1
需要登出后再登进才可以生效
3.修改静态ip
[root@m1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=ea0a7d62-0d12-4fd6-897d-d7a87e031d6f
DEVICE=eth0
ONBOOT=yes GATEWAY=192.168.1.1
IPADDR=192.168.1.201
NETMASK=255.255.255.0
DNS1=192.168.1.1
DNS2=8.8.8.8
4.安装配置keepalvied
yum install keepalived
[root@m1 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
kok.bing@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout
router_id LVS_1
} vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id
advert_int
priority
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.1.200
}
}
优先级其他的matster节点逐渐下降 90 80 70 ...
192.168.1.200是上面规划好的虚拟ip
[root@m1 ~]# systemctl restart keepalived
[root@m1 ~]# systemctl enable keepalived
重启服务,开机自诩
5.安装配置haproxy
[root@m1 ~]# cat /etc/haproxy/haproxy.cfgfg
global
chroot /var/lib/haproxy
daemon
group haproxy
user haproxy
log 127.0.0.1: local0 warning
pidfile /var/lib/haproxy.pid
maxconn
spread-checks
nbproc defaults
log global
mode tcp
retries
option redispatch listen https-apiserver
bind *:
mode tcp
balance roundrobin
timeout server 900s
timeout connect 15s server m1 192.168.1.201:6443 check port inter fall
server m2 192.168.1.202:6443 check port inter fall
所有master节点上配置一致的
[root@m1 ~]# systemctl start haproxy
[root@m1 ~]# systemctl enable haproxy
启动服务,开启自启
在第一个master节点上我需要做
1.配置kubeadm 初始化配置文件
kubeadm-init.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.16.2
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
controlPlaneEndpoint: "192.168.1.200:8443"
networking:
serviceSubnet: "10.96.0.0/16"
podSubnet: "192.168.0.0/16"
dnsDomain: "cluster.local"
192.168.1.200:8443是我们的虚拟ip ,master转发这个端口数据到负载均衡上再到某一个master的6443端口上
1.16.2是我现在在使用的kube三件的版本
192.168.0.0是我规划的pod子网段
2.初始化
kubeadm init --config=kubeadm-init.yaml --upload-certs
成功后会生成两个join的指令, 第一个是master节点用的加入 第二个是工作节点上的加入
Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of the control-plane node running the following command on each as root: kubeadm join 192.168.1.200:6443 --token 15wggu.lostbmuhkconfve8 \
--discovery-token-ca-cert-hash sha256:60bad8d33b8bea0ce9820746453e5ff28f8faa522f97e1018f56824ed29cab89 \
--control-plane --certificate-key 48b866c774671ede8d42b2188717d8e33e026d4fa7c1e9220a93e38a9bede443 Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward. Then you can join any number of worker nodes by running the following on each as root: kubeadm join 192.168.1.200:6443 --token 15wggu.lostbmuhkconfve8 \
--discovery-token-ca-cert-hash sha256:60bad8d33b8bea0ce9820746453e5ff28f8faa522f97e1018f56824ed29cab89
密钥如果过期重新上传
sudo kubeadm init phase upload-certs --upload-certs
3.安装网络策略
[root@m1 ~]# wget https://kuboard.cn/install-script/calico/calico-3.9.2.yaml
#默认是192.168.0. ,pod子网不一样的要手动修改
[root@m1 ~]# kubectl apply -f calico-3.9..yaml
4.去污点
查看污点
[root@m1 ~]# kubectl describe node m1|grep -i taints
Taints: node-role.kubernetes.io/master:NoSchedule
删除默认的污点
[root@m1 ~]# kubectl taint nodes m1 node-role.kubernetes.io/master-
node/m1 untainted
所有master都加入集群后,删除所有master的污点
kubectl taint nodes --all node-role.kubernetes.io/master-
在其他master 节点上我需要做
执行
kubeadm join 192.168.1.200: --token 15wggu.lostbmuhkconfve8 \
--discovery-token-ca-cert-hash sha256:60bad8d33b8bea0ce9820746453e5ff28f8faa522f97e1018f56824ed29cab89 \
--control-plane --certificate-key 48b866c774671ede8d42b2188717d8e33e026d4fa7c1e9220a93e38a9bede443
去污点同上
在其他work 节点上我需要做
kubeadm join 192.168.1.200: --token 15wggu.lostbmuhkconfve8 \
--discovery-token-ca-cert-hash sha256:60bad8d33b8bea0ce9820746453e5ff28f8faa522f97e1018f56824ed29cab89
在各个master节点上都可以执行 kubectl get node 等 master的指令了
最后
由于本人使用笔记本(低压)上的虚拟机实践,所以只部署了2个master node,
建议最少三个master节点,并且主机点上不应该去污点
hype-v上centos7部署高可用kubernetes集群实践的更多相关文章
- 基于saltstack自动化部署高可用kubernetes集群
SaltStack自动化部署HA-Kubernetes 本项目在GitHub上,会不定期更新,大家也可以提交ISSUE,地址为:https://github.com/skymyyang/salt-k8 ...
- 基于Containerd安装部署高可用Kubernetes集群
转载自:https://blog.weiyigeek.top/2021/7-30-623.html 简述 Kubernetes(后续简称k8s)是 Google(2014年6月) 开源的一个容器编排引 ...
- kubeasz 部署高可用 kubernetes 集群
文章目录 环境准备 配置模板机 配置hosts解析 配置ssh 免密钥登陆 kubeasz 部署服务准备 配置主机清单 部署集群 环境准备 IP HOSTNAME SYSTEM 192.168.131 ...
- 高可用Kubernetes集群-16. ansible快速部署
说明 本文档指导采用二进制包的方式快速部署高可用kubernetes集群. 脚本托管:k8s-ansible(持续更新) 参考:高可用kubernetes集群 组件版本 组件 版本 备注 centos ...
- 高可用Kubernetes集群-3. etcd高可用集群
五.部署高可用etcd集群 etcd是key-value存储(同zookeeper),在整个kubernetes集群中处于中心数据库地位,以集群的方式部署,可有效避免单点故障. 这里采用静态配置的方式 ...
- 高可用Kubernetes集群原理介绍
■ 文/ 天云软件 云平台开发工程师 张伟 1. 背景 Kubernetes作为容器应用的管理中心,对集群内部所有容器的生命周期进行管理,结合自身的健康检查及错误恢复机制,实现了集群内部应用层的高可用 ...
- 搭建高可用kubernetes集群(keepalived+haproxy)
序 由于单master节点的kubernetes集群,存在master节点异常之后无法继续使用的缺陷.本文参考网管流程搭建一套多master节点负载均衡的kubernetes集群.官网给出了两种拓扑结 ...
- 使用Kubeadm搭建高可用Kubernetes集群
1.概述 Kubenetes集群的控制平面节点(即Master节点)由数据库服务(Etcd)+其他组件服务(Apiserver.Controller-manager.Scheduler...)组成. ...
- 高可用Kubernetes集群-11. 部署kube-dns
参考文档: Github介绍:https://github.com/kubernetes/dns Github yaml文件:https://github.com/kubernetes/kuberne ...
随机推荐
- Dubbo API 笔记——配置参考
版权声明:欢迎转载,请注明出处,谢谢! https://blog.csdn.net/benhuo931115/article/details/78457391 schema 配置参考 所有配置项分为三 ...
- C/C++程序基础-C++与C有什么不同
1:C和C++的联系和区别? 答:C是一个结构化语言,它的重点在于算法和数据结构.对于语言本身而言,C是C++的子集.C程序的设计首先要考虑的是如何通过一个过程,对输入进行运算处理,得到输出.对于C+ ...
- 轻松搭建ES6开发环境
首先,你要自行查阅什么是ES6和ES5.javascript有什么关系,为什么要编译ES6.废话不多说,just go! 第一步:创建项目并让它成为npm可以管理的仓库. 新建一个项目,名字假设为te ...
- mac 安装laravel
安装laravel之前先安装composer 使用 curl 指令下载: curl -sS https://getcomposer.org/installer | php 或是沒有安裝 curl ,也 ...
- 如何用MATLAB GUI创建图形用户界面
MATLAB是众多理工科学生及工程师经常使用的一款数学软件,除了可以实现数据处理,矩阵运算.函数绘制等功能外,MATLAB还可以实现图形用户界面的设计. 下面介绍如何让小白也能用GUI创建最基本的用户 ...
- 2.jdk1.8+springboot中http1.1之tcp连接复用实现
接上篇:https://www.cnblogs.com/Hleaves/p/11284316.html 环境:jdk1.8 + springboot 2.1.1.RELEASE + feign-hys ...
- python之scrapy爬取数据保存到mysql数据库
1.创建工程 scrapy startproject tencent 2.创建项目 scrapy genspider mahuateng 3.既然保存到数据库,自然要安装pymsql pip inst ...
- jquery简单入门1
前端 html:展示 form: 属性: action和method 子标签: input(10种) text password radio checkbox file submit button r ...
- Linux学习—rpm包管理
前言 在linux上,一个软件通常由二进制程序,库文件,配置文件和帮助文件组成.其中: 二进制程序一般都放在/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin和/ ...
- centos7 忘记mysql root登录密码
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和 ...