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

这篇具有很好参考价值的文章主要介绍了【业务功能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 是针对裸金属服务器设计的,因此如果是在云环境中部署,需要注意是否满足条件。

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

  • 图中有一个类型为 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。

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

  • 图中有一个类型为 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创建项目

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

3.2.2 创建应用

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

3.2.3 创建服务

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

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

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

3.2.4 创建应用路由

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8sopenelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

3.2.5 通过域名访问

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

openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s
openelb,Spring cloud,分布式,Spring boot,spring cloud,spring boot,微服务,kubesphere,kubernetes,OpenELB,k8s

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文章来源地址https://www.toymoban.com/news/detail-774388.html

到了这里,关于【业务功能118】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere-OpenELB部署及应用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【业务功能100】补充代码【业务功能88】微服务-springcloud-分布式锁-redis-redisson-springcache

    采用redisson做分布式锁,完成数据的查询接口功能getCatelog2JSONRedis 原先从mysql数据库查询的效率较低,现在将部分固定数据展示比如页面的树形栏目信息等,存储到 redis缓存 ,然后基于分布式集群,需要结合本地锁(synchronized )与分布式锁(redissonClient.getLock(“catelog2JSON-lock”

    2024年02月09日
    浏览(32)
  • 【业务功能篇91】微服务-springcloud-多线程-线程池执行顺序

    1.1 继承Thread 1.2 实现Runnable接口 1.3 Callable接口   上面的三种获取线程的方法是直接获取,没有对线程做相关的管理,这时可以通过线程池来更加高效的管理线程对象。 然后我们就可以通过这个线程池对象来获取对应的线程   通过上面的介绍我们发现获取线程的方式 继承

    2024年02月10日
    浏览(42)
  • 【业务功能篇85】微服务-springcloud-Nginx-反向代理-网关

    Nginx域名 在c:/window/system32/drivers/etc/hosts文件,我们在这个文件中添加 注意如果是没有操作权限,那么点击该文件右击属性,去掉只读属性即可 通过这个域名访问到Nginx服务 nginx.cof是全局配置文件 /mydata/nginx/conf/nginx.cof 文件中最后配置了一个信息 include /etc/nginx/conf.d/*.conf 表示

    2024年02月10日
    浏览(49)
  • 【业务功能篇90】微服务-springcloud-检索服务-ElasticSearch实战运用-DSL语句

      商品检索页面我们放在search服务中处理,首页我们需要在mall-search服务中支持Thymeleaf。添加对应的依赖 然后我们拷贝模板文件到template目录下,然后不要忘记添加Thymeleaf的名称空间 需要把相关的静态资源文件拷贝到Nginx服务中。目录结构是:/mydata/nginx/html/static/search/ 我们

    2024年02月10日
    浏览(42)
  • 【业务功能109】微服务-springcloud-springboot-Skywalking-链路追踪-监控

    skywalking 是一个apm系统,包含监控,追踪,并拥有故障诊断能力的 分布式 系统   Skywalking是由国内开源爱好者吴晟开源并提交到Apache孵化器的产品,它同时吸收了Zipkin /Pinpoint /CAT 的设计思路。特点是:支持多种插件,UI功能较强,支持非侵入式埋点。目前使用厂商最多,版

    2024年02月08日
    浏览(44)
  • 【业务功能篇92】微服务-springcloud-多线程-异步处理-异步编排-CompletableFutrue

    一个商品详情页 展示SKU的基本信息 0.5s 展示SKU的图片信息 0.6s 展示SKU的销售信息 1s spu的销售属性 1s 展示规格参数 1.5s spu详情信息 1s   Future是Java 5添加的类,用来描述一个异步计算的结果。你可以使用 isDone 方法检查计算是否完成,或者使用 get 阻塞住调用线程,直到计算

    2024年02月10日
    浏览(43)
  • 【业务功能篇94】微服务-springcloud-springboot-认证服务-注册功能-第三方短信验证API

      结合我们前面介绍的商城的架构我们需要单独的搭建一个认证服务。   首先创建一个SpringBoot项目,然后添加对应的依赖   我们需要把认证服务注册到Nacos中,添加对应的依赖,然后完成对应的配置 放开Nacos注册中心 然后启动测试   然后我们整理登录和注册的相关

    2024年02月09日
    浏览(38)
  • 【业务功能篇99】微服务-springcloud-springboot-电商订单模块-生成订单服务-锁定库存

    一个是需要生成订单信息一个是需要生成订单项信息。具体的核心代码为 锁定库存的操作,需要操作ware仓储服务。 没有库存或者锁定库存失败我们通过自定义的异常抛出 如果下订单操作成功(订单数据和订单项数据)我们就会操作锁库存的行为 锁定库存失败通过抛异常来

    2024年02月09日
    浏览(34)
  • 【业务功能篇84】微服务SpringCloud-ElasticSearch-Kibanan-电商实例应用

    ElasticSearch实现商城系统中全文检索的流程。 商品的映射关系 如上的例子,netsted类型,避免了我们properties属性里的三个字段值同类型,他们的内容不会错乱匹配 参考官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.4/nested.html 3.1 创建ESModel 点击上架功能传递spuId到后台

    2024年02月10日
    浏览(44)
  • 【业务功能篇93】微服务-springcloud-多线程-异步处理-异步编排-CompletableFutrue-实战运用

      我们可以在商品详细信息查询的位置实现CompletableFuture的异步编排处理。 根据业务分析:3.4.5数据接口的入参信息需要来源于1数据接口的返回信息,也就是skuid 所以可以设计 1 3 4 5 串行线程 ,而 3 4 5依赖1 ,需要等1 执行完成 2接口数据没有关系,所以就与上面的线程是并

    2024年02月10日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包