概述

在上一篇中已经实践了 非高可用的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.安装网络策略

最新参阅https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network

[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集群实践的更多相关文章

  1. 基于saltstack自动化部署高可用kubernetes集群

    SaltStack自动化部署HA-Kubernetes 本项目在GitHub上,会不定期更新,大家也可以提交ISSUE,地址为:https://github.com/skymyyang/salt-k8 ...

  2. 基于Containerd安装部署高可用Kubernetes集群

    转载自:https://blog.weiyigeek.top/2021/7-30-623.html 简述 Kubernetes(后续简称k8s)是 Google(2014年6月) 开源的一个容器编排引 ...

  3. kubeasz 部署高可用 kubernetes 集群

    文章目录 环境准备 配置模板机 配置hosts解析 配置ssh 免密钥登陆 kubeasz 部署服务准备 配置主机清单 部署集群 环境准备 IP HOSTNAME SYSTEM 192.168.131 ...

  4. 高可用Kubernetes集群-16. ansible快速部署

    说明 本文档指导采用二进制包的方式快速部署高可用kubernetes集群. 脚本托管:k8s-ansible(持续更新) 参考:高可用kubernetes集群 组件版本 组件 版本 备注 centos ...

  5. 高可用Kubernetes集群-3. etcd高可用集群

    五.部署高可用etcd集群 etcd是key-value存储(同zookeeper),在整个kubernetes集群中处于中心数据库地位,以集群的方式部署,可有效避免单点故障. 这里采用静态配置的方式 ...

  6. 高可用Kubernetes集群原理介绍

    ■ 文/ 天云软件 云平台开发工程师 张伟 1. 背景 Kubernetes作为容器应用的管理中心,对集群内部所有容器的生命周期进行管理,结合自身的健康检查及错误恢复机制,实现了集群内部应用层的高可用 ...

  7. 搭建高可用kubernetes集群(keepalived+haproxy)

    序 由于单master节点的kubernetes集群,存在master节点异常之后无法继续使用的缺陷.本文参考网管流程搭建一套多master节点负载均衡的kubernetes集群.官网给出了两种拓扑结 ...

  8. 使用Kubeadm搭建高可用Kubernetes集群

    1.概述 Kubenetes集群的控制平面节点(即Master节点)由数据库服务(Etcd)+其他组件服务(Apiserver.Controller-manager.Scheduler...)组成. ...

  9. 高可用Kubernetes集群-11. 部署kube-dns

    参考文档: Github介绍:https://github.com/kubernetes/dns Github yaml文件:https://github.com/kubernetes/kuberne ...

随机推荐

  1. requests_html使用asyncio

    import asyncio import functools from concurrent.futures.thread import ThreadPoolExecutor from reques ...

  2. dos切换其他目录加参数/D

    D:\>cd /D c:\Windows c:\Windows> 不加参数/D 无法切换到另一个盘符

  3. 18.二叉树的镜像 Java

    题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...

  4. 【Elasticsearch】Docker 安装 Elasticsearch 2.4.4 版本(高版本方式不同)

    1. 下载  elasticsearch docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.3 2.启动 elasticsea ...

  5. IntelliJ IDEA-配置文件位置

    关于配置文件的位置 一旦开始使用IDEA之后,就需要做很多的配置相关工作,使得IDEA越来越符合你的个人习惯,让你使用起来得心应手.而这些配置信息,都保存在C盘,比如我的就会默认保存在如图所示的位置 ...

  6. python 普通继承方式和super继承方式

    Python中对象方法的定义很怪异,第一个参数一般都命名为self(相当于其它语言的this),用于传递对象本身,而在调用的时候则不必显式传递,系统会自动传递. 举一个很常见的例子: >> ...

  7. Qt VS MFC

    最近用了一段时间Qt,觉得网上这篇文章讲述Qt与MFC之间的区别很到位,分享一下. ----------------------------------原文---------------------- ...

  8. android data binding jetpack VIIII 第一坑

    <LinearLayout android:id="@+id/ll_item_home_page_pics" android:layout_width="wrap_ ...

  9. Nginx命令与配置详解

    1. 控制命令 ./sbin/nginx –t 测试配置是否正确 ./sbin/nginx –s reload 加载最新配置,进程并不重启  ./sbin/nginx –s stop  立即停止   ...

  10. SpringMVC整合SpringFox实践总结

    项目中使用的swagger框架在生成api文档时存在一些问题: 1. 控制器下方法无法点击展开 2.api内容结构混乱 基于上述原因,重新整合重构了一下api文档生成的代码.在此将重整过程记录下来,方 ...