【业务功能118】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere-OpenELB部署及应用

2023-11-17

OpenELB部署及应用

一、OpenELB介绍

网址: openelb.io

OpenELB 是一个开源的云原生负载均衡器实现,可以在基于裸金属服务器、边缘以及虚拟化的 Kubernetes 环境中使用 LoadBalancer 类型的 Service 对外暴露服务。OpenELB 项目最初由 KubeSphere 社区发起,目前已作为 CNCF 沙箱项目加入 CNCF 基金会,由 OpenELB 开源社区维护与支持。

与 MetalLB 类似,OpenELB 也拥有两种主要工作模式:Layer2 模式和 BGP 模式。OpenELB 的 BGP 模式目前暂不支持 IPv6。
无论是 Layer2 模式还是 BGP 模式,核心思路都是通过某种方式将特定 VIP 的流量引到 k8s 集群中,然后再通过 kube-proxy 将流量转发到后面的特定服务。

1.1 Layer2 模式

Layer2 模式需要我们的 k8s 集群基础环境支持发送 anonymous ARP/NDP packets。因为 OpenELB 是针对裸金属服务器设计的,因此如果是在云环境中部署,需要注意是否满足条件。

在这里插入图片描述

  • 图中有一个类型为 LoadBalancer 的 Service,其 VIP 为 192.168.0.91(和 k8s 的节点相同网段),后端有两个 pod(分别为 pod1 和 pod2)
  • 安装在 Kubernetes 集群中的 OpenELB 随机选择一个节点(图中为 worker 1)来处理 Service 请求。当局域网中出现 arp request 数据包来查询 192.168.0.91 的 mac 地址的时候,OpenELB 会进行回应(使用 worker 1 的 MAC 地址),此时路由器(也可能是交换机)将 Service 的 VIP 192.168.0.91 和 worker 1 的 MAC 地址绑定,之后所有请求到 192.168.0.91 的数据包都会被转发到 worker1 上
  • Service 流量到达 worker 1 后, worker 1 上的 kube-proxy 将流量转发到后端的两个 pod 进行负载均衡,这些 pod 不一定在 work1 上

主要的工作流程就如同上面描述的一般,但是还有几个需要额外注意的点:

  • 如果 worker 1 出现故障,OpenELB 会重新向路由器发送 APR/NDP 数据包,将 Service IP 地址映射到 worker 2 的 MAC 地址,Service 流量切换到 worker 2
  • 主备切换过程并不是瞬间完成的,中间会产生一定时间的服务中断(具体多久官方也没说,实际上应该是却决于检测到节点宕机的时间加上重新选主的时间)
  • 如果集群中已经部署了多个 openelb-manager 副本,OpenELB 使用 Kubernetes 的领导者选举特性算法来进行选主,从而确保只有一个副本响应 ARP/NDP 请求

1.2 BGP 模式

OpenELB 的 BGP 模式使用的是gobgp实现的 BGP 协议,通过使用 BGP 协议和路由器建立 BGP 连接并实现 ECMP 负载均衡,从而实现高可用的 LoadBalancer。

在这里插入图片描述

  • 图中有一个类型为 LoadBalancer 的 Service,其 VIP 为 172.22.0.2(和 k8s 的节点不同网段),后端有两个 pod(分别为 pod1 和 pod2)
  • 安装在 Kubernetes 集群中的 OpenELB 与 BGP 路由器建立 BGP 连接,并将去往 172.22.0.2 的路由发布到 BGP 路由器,在配置得当的情况下,路由器上面的路由表可以看到 172.22.0.2 这个 VIP 的下一条有多个节点(均为 k8s 的宿主机节点)
  • 当外部客户端机器尝试访问 Service 时,BGP 路由器根据从 OpenELB 获取的路由,在 master、worker 1 和 worker 2 节点之间进行流量负载均衡。Service 流量到达一个节点后,该节点上的 kube-proxy 将流量转发到后端的两个 pod 进行负载均衡,这些 pod 不一定在该节点上

1.3 注意事项

配置 ARP 参数

部署 Layer2 模式需要把 k8s 集群中的 ipvs 配置打开strictARP,开启之后 k8s 集群中的 kube-proxy 会停止响应 kube-ipvs0 网卡之外的其他网卡的 arp 请求,而由 MetalLB 接手处理。

strict ARP 开启之后相当于把 将 arp_ignore 设置为 1 并将 arp_announce 设置为 2 启用严格的 ARP,这个原理和 LVS 中的 DR 模式对 RS 的配置一样。

二、OpenELB安装及配置

2.1 需求

  • You need to prepare a Kubernetes cluster, and ensure that the Kubernetes version is 1.15 or later. OpenELB requires CustomResourceDefinition (CRD) v1, which is only supported by Kubernetes 1.15 or later. You can use the following methods to deploy a Kubernetes cluster:

  • Use KubeKey (recommended). You can use KubeKey to deploy a Kubernetes cluster with or without KubeSphere.

  • Follow official Kubernetes guides.

OpenELB is designed to be used in bare-metal Kubernetes environments. However, you can also use a cloud-based Kubernetes cluster for learning and testing.

2.2 Install OpenELB Using kubectl

1.Log in to the Kubernetes cluster over SSH and run the following command:

# kubectl apply -f https://raw.githubusercontent.com/openelb/openelb/master/deploy/openelb.yaml

2.Run the following command to check whether the status of openelb-manager is READY: 1/1 and STATUS: Running. If yes, OpenELB has been installed successfully.

# kubectl get pods -n openelb-system

2.2 OpenELB配置

Use OpenELB in Layer 2 Mode

2.2.1 需求

  • You need to prepare a Kubernetes cluster where OpenELB has been installed. All Kubernetes cluster nodes must be on the same Layer 2 network (under the same router).
  • You need to prepare a client machine, which is used to verify whether OpenELB functions properly in Layer 2 mode. The client machine needs to be on the same network as the Kubernetes cluster nodes.
  • The Layer 2 mode requires your infrastructure environment to allow anonymous ARP/NDP packets. If OpenELB is installed in a cloud-based Kubernetes cluster for testing, you need to confirm with your cloud vendor whether anonymous ARP/NDP packets are allowed. If not, the Layer 2 mode cannot be used.

2.2.2 配置步骤

Step 1: Enable strictARP for kube-proxy

In Layer 2 mode, you need to enable strictARP for kube-proxy so that all NICs in the Kubernetes cluster stop answering ARP requests from other NICs and OpenELB handles ARP requests instead.

1.Log in to the Kubernetes cluster and run the following command to edit the kube-proxy ConfigMap:

# kubectl edit configmap kube-proxy -n kube-system

2.In the kube-proxy ConfigMap YAML configuration, set data.config.conf.ipvs.strictARP to true.

ipvs:
  strictARP: true
mode:ipvs

3.Run the following command to restart kube-proxy:

# kubectl rollout restart daemonset kube-proxy -n kube-system

Step 2: Specify the NIC Used for OpenELB

If the node where OpenELB is installed has multiple NICs, you need to specify the NIC used for OpenELB in Layer 2 mode. You can skip this step if the node has only one NIC.

In this example, the master1 node where OpenELB is installed has two NICs (eth0 192.168.0.2 and eth1 192.168.1.2), and eth0 192.168.0.2 will be used for OpenELB.

Run the following command to annotate master1 to specify the NIC:

# kubectl annotate nodes k8s-master01 layer2.openelb.kubesphere.io/v1alpha1="192.168.10.141"

Step 3: Create an Eip Object

The Eip object functions as an IP address pool for OpenELB.

1.Run the following command to create a YAML file for the Eip object:

# vim layer2-eip.yaml

2.Add the following information to the YAML file:

apiVersion: network.kubesphere.io/v1alpha2
kind: Eip
metadata:
  name: layer2-eip
spec:
  address: 192.168.10.70-192.168.10.99
  interface: ens33
  protocol: layer2
  • The IP addresses specified in spec:address must be on the same network segment as the Kubernetes cluster nodes.
  • For details about the fields in the Eip YAML configuration, see Configure IP Address Pools Using Eip.

3.Run the following command to create the Eip object:

# kubectl apply -f layer2-eip.yaml

三、OpenELB使用

3.1 在k8s命令行中使用

3.1.1 Create a Deployment

The following creates a Deployment of two Pods using the luksa/kubia image. Each Pod returns its own Pod name to external requests.

1.Run the following command to create a YAML file for the Deployment:

# vim layer2-openelb.yaml

2.Add the following information to the YAML file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: layer2-openelb
spec:
  replicas: 2
  selector:
    matchLabels:
      app: layer2-openelb
  template:
    metadata:
      labels:
        app: layer2-openelb
    spec:
      containers:
        - image: luksa/kubia
          name: kubia
          ports:
            - containerPort: 8080

3.Run the following command to create the Deployment:

# kubectl apply -f layer2-openelb.yaml

3.1.2 Create a Service

1.Run the following command to create a YAML file for the Service:

# vim layer2-svc.yaml

2.Add the following information to the YAML file:

kind: Service
apiVersion: v1
metadata:
  name: layer2-svc
  annotations:
    lb.kubesphere.io/v1alpha1: openelb
    protocol.openelb.kubesphere.io/v1alpha1: layer2
    eip.openelb.kubesphere.io/v1alpha2: layer2-eip
spec:
  selector:
    app: layer2-openelb
  type: LoadBalancer
  ports:
    - name: http
      port: 80
      targetPort: 8080
  externalTrafficPolicy: Cluster
  • You must set spec:type to LoadBalancer.
  • The lb.kubesphere.io/v1alpha1: openelb annotation specifies that the Service uses OpenELB.
  • The protocol.openelb.kubesphere.io/v1alpha1: layer2 annotation specifies that OpenELB is used in Layer 2 mode.
  • The eip.openelb.kubesphere.io/v1alpha2: layer2-eip annotation specifies the Eip object used by OpenELB. If this annotation is not configured, OpenELB automatically uses the first available Eip object that matches the protocol. You can also delete this annotation and add the spec:loadBalancerIP field (for example, spec:loadBalancerIP: 192.168.0.91) to assign a specific IP address to the Service.
  • If spec:externalTrafficPolicy is set to Cluster (default value), OpenELB randomly selects a node from all Kubernetes cluster nodes to handle Service requests. Pods on other nodes can also be reached over kube-proxy.
  • If spec:externalTrafficPolicy is set to Local, OpenELB randomly selects a node that contains a Pod in the Kubernetes cluster to handle Service requests. Only Pods on the selected node can be reached.

3.Run the following command to create the Service:

kubectl apply -f layer2-svc.yaml

3.1.3 Verify OpenELB in Layer 2 Mode

In the Kubernetes cluster, run the following command to obtain the external IP address of the Service:

# kubectl get svc

3.2 在kubesphere中使用

3.2.1创建项目

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3.2.2 创建应用

在这里插入图片描述在这里插入图片描述

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

3.2.3 创建服务

在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

lb.kubesphere.io/v1alpha1:openelb
protocol.openelb.kubesphere.io/v1alpha1:layer2
eip.openelb.kubesphere.io/v1alpha2:layer2-eip

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

3.2.4 创建应用路由

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.2.5 通过域名访问

3.2.5.1 通过 hosts文件添加域名解析

在这里插入图片描述
在这里插入图片描述

3.2.5.2 通过域名服务器实现域名解析
  • 前面我们部署公开服务DNS节点中,访问 /var/named/msb.com.zone 进行域名解析配置增加主机映射: www1 A 192.168.10.70 , 保存退出
  • systemctl restart named //重启服务
  • 这样就可以通过 www1.msb.com 进行访问了

可以进入到k8s集群master节点中 进行访问:curl http://www1.msb.com

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【业务功能118】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere-OpenELB部署及应用 的相关文章

随机推荐

  • Maven环境正常,打包后使用报 java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream 错误

    也是找的网上的解决方法 下载一个tomcat 里面包含着必要的jar包 然后把TOMCAT PATH common lib servlet api jar复制出来 放到 JDK PATH jre lib ext下面 如果不行就重启一下项目
  • 区块链都记录了哪些信息?

    区块如何连接成区块链 之前的文章里又说到区块链 想要知道区块链上的信息首先需要了解一下什么是区块链 区块链其实是一串使用密码学算法产生的区块连接而成 每一个区块上写满了交易记录 区块按顺序相连形成链状结构 就像世界上的电脑一样 电脑每一台电
  • 十四、内置模块path、邂逅Webpack和打包过程、css-loader

    一 内置模块path 1 path介绍 2 path常见的API 这里重点讲一下path resolve 看上面的例子 从右往左开始解析 所以一开始解析的就是 abc txt 这个时候就会把它当成一个绝对路径了 为什么 因为看到斜杠 默认就
  • httpclient工具类

    import java io IOException import java net URI import java util ArrayList import java util List import java util Map imp
  • Channel-wise Knowledge Distillation for Dense Prediction阅读笔记

    Channel wise KD阅读笔记 一 Title 二 Summary 三 Research Object 四 Problem Statement 五 Method 5 1 spatial distillation 5 2 Channe
  • macOS使用 之 读写NTFS格式磁盘

    因为版权问题 macOS并没有开放是支持Windows NTFS 格式硬盘的写入操作 因此对MAC用户使用移动磁盘造成了极大的困扰 下面楼主就来介绍一下mac系统中读取NTFS格式的简单办法 1 使用常见付费软件 如果你土豪级别的人物 不在
  • CHROME扩展开发之·消息传递Message(window.message)

    由于content scripts运行在Web页面的上下文中 属于Web页面的组成部分 而不是Google Chrome扩展程序 但是content scripts又往往需要与Google Chrome扩展程序的其他部分通信以共享数据 这可
  • 小红书流量逻辑、KOL模型、内容营销

    小红书平台专项课 品牌营销训练营 融合了千瓜历年研究和整理的成果 结合实际案例给到大家最全最干货的内容 本文选取了课程中的精华部分 为大家提供一份历年品牌营销投放的实操总结 助力2022年品牌营销增长 从消费者层级到消费者决策 从品牌内容营
  • 【Transformer学习笔记】VIT解析

    很久以前科学家做过一个生物实验 发现视觉神经元同样可以被训练来作听觉神经元之用 受此启发 不少计算机研究者也在寻找着机器学习领域的大一统 将CV任务和NLP任务使用相同或者类似的结构进行建模 随着transformer在nlp领域已经杀出了
  • 微信小程序使用本地图片在真机预览不显示的问题解决

    开发工具上本地图片可以显示 但是在真机上预览的时候不能显示 通常我们代码路径是代码是这样写的
  • 什么是 Python?Python 基础编程入门指南,带你从零开始深入了解

    Python是当今最流行的编程语言之一 Python以其简单的语法和多功能性而闻名 既易于学习又可用于高级应用程序 可以使用Python的领域也非常广泛 人工智能 机器学习 Web 开发 基本上绝大多数热门的域都能看到Python的身影 今
  • MODBUS CRC校验原理及C语言实现

    MODBUS通信协议的CRC校验原理多项式为8005的逆序A001 列01的CRC校验原理 1111111111111111 初始化CRC寄存机 0000000000000001 1111111111111110 异或 0111111111
  • pread介绍

    1 先来介绍pread函数 root bogon mycode cat test c include
  • QT中的事件

    目录 1 QT事件 1 1 事件介绍 1 2 事件的处理 2 键盘事件 2 1 keyPressEvent 2 1 1 判断某个键按下 2 1 2 组合键操作 3 鼠标事件 3 1 鼠标单击事件 3 2 鼠标释放事件 3 3 鼠标双击事件
  • vim 常用命令

    文本替换 s 替换 g global 全部 如果不加g则只会替换每行第一个word1 1 20s hello helloworld g 将1 20行中的 hello 替换为 helloworld 统计字符串出现次数 s pattern gn
  • innerHTML 用法

    用法 比如在中写了如下的代码 div div 现在用top innerHTML 的方法就可以向这个id的位置写入HTML代码了 例如top innerHTML
  • 啊哈c语言 潦草的初步笔记(3)

    第四章 while 当while后面 中的关系表达式为真时 即成立时才执行 种的内容 读作 mod 也称作 取模 作用是获取余数 的左右两边必须是整数 表示除号 作用是获取商 的左右两边可以是整数也可以是小数 等待 语句 Sleep 注意S
  • 20. 异常处理

    Hi 大家好 我是茶桁 在我们日常使用Python或者其他编程语言的时候 不可避免的都会出现报错和异常 那么 我们今天就来谈谈异常 什么是异常 异常异常 根据名字简单理解 那就是非正常 也就是没有达到预期目标 异常呢 其实就是一个事件 并且
  • CAP原理的证明

    CAP概述 C Consistency 一致性 A Availability 可用性 P Partition Tolerance分区容错性 CAP理论的核心是 一个分布式系统不可能同时很好的满足一致性 可用性和分区容错性这三个需求 最多只能
  • 【业务功能118】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere-OpenELB部署及应用

    OpenELB部署及应用 一 OpenELB介绍 网址 openelb io OpenELB 是一个开源的云原生负载均衡器实现 可以在基于裸金属服务器 边缘以及虚拟化的 Kubernetes 环境中使用 LoadBalancer 类型的 S