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

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.99interface: ens33protocol: 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: 2selector:matchLabels:app: layer2-openelbtemplate:metadata:labels:app: layer2-openelbspec:containers:- image: luksa/kubianame: kubiaports:- 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-svcannotations:lb.kubesphere.io/v1alpha1: openelbprotocol.openelb.kubesphere.io/v1alpha1: layer2eip.openelb.kubesphere.io/v1alpha2: layer2-eip
spec:selector:app: layer2-openelbtype: LoadBalancerports:- name: httpport: 80targetPort: 8080externalTrafficPolicy: 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/81941.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用Python把csv文件批量修改编码为UTF-8格式并转为Excel格式

有时候用excel打开一个csv文件,中文全部显示乱码。然后手动用notepad打开,修改编码为utf-8并保存后,再用excel打开显示正常。 使用Python通过很少代码就能将上面过程自动化。 导入3个模块 import pandas as pd import os import chardetc…

Python 3 – 文件 readline() 方法

Python 3 – 文件 readline() 方法|极客笔记 # 打开文件 file open("example.txt", "r")# 读取文件中的一行数据 line file.readline() while line:# 移除行尾的换行符print(line.strip())# 读取文件中的下一行数据line file.readline()# 关闭文件 file…

【Seata】05 - Seata Saga 模式简单整理、Docker 部署 Nacos 单机(基于 Jpom)相关配置

文章目录 前言参考目录Saga 模式知识点简单整理1、适用场景、优缺点2、Saga 模式的使用3、可能出现的问题以及解决方法 Docker 部署 Nacos 单机(基于 Jpom)步骤 1:拉取镜像步骤 2:构建容器步骤 3:Nacos 设置 Seata 配置…

自动化测试工具slelnium的初体验

1.slelnium介绍 1.1 一个Web的自动化测试工具,最初是为网站自动化测试而开发的。 1.2 可以直接运行在浏览器上,它支持所有主流的浏览器(包括PhantomJS这些无界面的浏览器),可以接收指令,让浏览器自动加载页…

代码随想录Day41| 343. 整数拆分 |

343. 整数拆分 class Solution { public:int integerBreak(int n) {vector<int> f(n1,0);f[2]1;for(int i3;i<n;i){for(int j1;j<i-1;j){f[i]max(f[i],max(f[i-j]*j,(i-j)*j));}}return f[n];} }; 96. 不同的二叉搜索树 class Solution { public:int numTrees(int…

Flask 使用 JWT(二)

在 Python 使用 JWT 主要的方案是 PyJWT 工具。 安装与基本使用 可以使用 pip 安装 PyJWT: $ pip install pyjwt编码与解码 编码函数 def encode( self, payload: Dict[str, Any], # payload 参数 key: str, …

SkyWalking快速上手(六)——告警

文章目录 前言一、什么是SkyWalking的告警功能二、为什么要使用SkyWalking的告警功能1. 及时发现异常情况2. 提高故障处理效率3. 避免数据丢失和损坏4. 提升系统性能和稳定性 三、如何使用SkyWalking的告警功能1. 告警规则2. 告警通知3. 告警持续时间 四、注意事项1、合理设置告…

23062QTday2

完善登录框 点击登录按钮后&#xff0c;判断账号&#xff08;admin&#xff09;和密码&#xff08;123456&#xff09;是否一致&#xff0c;如果匹配失败&#xff0c;则弹出错误对话框&#xff0c;文本内容“账号密码不匹配&#xff0c;是否重新登录”&#xff0c;给定两个按钮…

vim使用

一、vim配置文件 "查看自己的vimrc所在的目录 "在命令模式下 :echo $MYVIMRC"打开自己的vimrc文件 "在命令模式下 :e $MYVIMRC 二、字体 "查看自己当前的字体及大小 "在命令模式下 :set guifont?"设置默认的字体为仿宋_GB2312&#xff…

ROS 入门

目录 简介 ROS诞生背景 ROS的设计目标 ROS与ROS2 安装ROS 1.配置ubuntu的软件和更新 2.设置安装源 3.设置key 4.安装 5.配置环境变量 安装可能出现的问题 安装构建依赖 卸载 ROS架构 1.设计者 2.维护者 3. 立足系统架构: ROS 可以划分为三层 ROS通信机制 话…

react d3使用循环显示多个地图

首先需要写一个组件&#xff1a; import React, { useState, useEffect, useRef } from react; import ChinaMap from moment; import * as d3 from d3; import chinaGeoJson from china-geojson/src/geojson/china.json;const MyMapToShowResult ({ realData }) > {const…

笔记 | 十六进制不进位加法

这里写自定义目录标题 题目极笨代码错误原因正确代码 题目 Time Limit: 1000 ms Memory Limit: 256 mb 16进制不进位的加法&#xff0c;即和正常加法类似&#xff0c;只是不用去计算进位的数&#xff0c;比正常的加法更简单。 如A 6 0&#xff08;正常加法是10&#xff0c;…

使用JAXB将xml转成Java对象

文章目录 使用JAXB将xml转成Java对象1. xml内容2. Java对象类3. 封装的工具类4. 测试 使用JAXB将xml转成Java对象 工作中遇到个问题&#xff0c;需要将xml转对象&#xff0c;之前复杂的xml都是自己用dom4j来解析组装成Java对象&#xff0c;但是对于简单的&#xff0c;看到了JAX…

SQL中的PowerDesigner逐步深入提问,你能掌握多少?

你提到了有PowerDesigner操作经验&#xff0c;请解释一下PowerDesigner是什么&#xff0c;以及它在数据库设计和开发中的作用是什么&#xff1f; 标准回答&#xff1a; PowerDesigner是一种数据库建模和设计工具&#xff0c;它用于创建数据库模型、设计表结构、定义关系和生成…

android.support.multidex.MultiDexApplication:DexPathList

修改项目的build.gradle文件&#xff0c;使用multidex并添加multidex库作为依赖&#xff0c;如下所示&#xff1a; android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 28 multiDexEnabled true } ... } dependencies { compile com.android.support:multidex…

【漏洞复现】Smanga未授权远程代码执行漏洞(CVE-2023-36076) 附加SQL注入+任意文件读取

文章目录 前言声明一、产品简介一、漏洞描述二、漏洞等级三、影响范围四、漏洞复现五、修复建议六、附加漏洞漏洞一、SQL注入漏洞二、任意文件读取 前言 Smanga存在未授权远程代码执行漏洞,攻击者可在目标主机执行任意命令,获取服务器权限。 声明 请勿利用文章内的相关技术从…

windows彻底卸载unity

1.控制面板卸载 双击打开桌面的控制面板&#xff0c;选择卸载程序&#xff0c;选中Unity和UnityHub右击卸载。 2.清除unity的注册表 在运行中输入“regedit”双击打开注册表界面 删除 HKEY_CURRENT_USER\Software\Unity 下所有项 删除 HKEY_CURRENT_USER\Software\Unity Tec…

电脑怎么取消磁盘分区?

有时候&#xff0c;我们的电脑会出现一个磁盘爆满&#xff0c;但另一个却空着&#xff0c;这时我们可以通过取消磁盘分区来进行调整&#xff0c;那么&#xff0c;这该怎么操作呢&#xff1f;下面我们就来了解一下。 磁盘管理取消磁盘分区 磁盘管理是Windows自带的磁盘管理工具…

BMS电池管理系统的蓝牙芯片 国产高性能 低功耗蓝牙Soc芯片PHY6222

电池管理系统是对电池进行监控与控制的系统&#xff0c;将采集的电池信息实时反馈给用户&#xff0c;同时根据采集的信息调节参数&#xff0c;充分发挥电池的性能。但是&#xff0c;前技术中&#xff0c;在管理多个电池时&#xff0c;需要人员现场调试与设置&#xff0c;导致其…

leetcode Top100 (5) 盛最多水的容器

/*** 给定一个长度为 n 的整数数组 height 。有 n 条垂线&#xff0c;第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。* <p>* 找出其中的两条线&#xff0c;使得它们与 x 轴共同构成的容器可以容纳最多的水。* <p>* 返回容器可以储存的最大水量。* <p>* …