上海手机网站建设哪家专业,学网站建设培训班,短视频培训机构排名,怎样建设网站论文目录
一.purelb简介
1.简介
2.purelb的layer2工作模式特点
二.layer2的配置演示
1.首先准备ipvs和arp配置环境
2.purelb部署开始
#xff08;1#xff09;下载purelb-complete.yaml文件并应用
#xff08;2#xff09;查看该有的资源是否创建完成并运行
#xff…目录
一.purelb简介
1.简介
2.purelb的layer2工作模式特点
二.layer2的配置演示
1.首先准备ipvs和arp配置环境
2.purelb部署开始
1下载purelb-complete.yaml文件并应用
2查看该有的资源是否创建完成并运行
3配置地址池
3.purelb测试
1创建deploy和service在主机进行访问测试
2浏览器测试
4.卸载purelb 一.purelb简介
1.简介
PureLB是一种负载均衡器它的工作原理主要是用于在网络中分发和管理传入的请求以便将请求有效地分配给后端服务。
2.purelb的layer2工作模式特点
purelb会在k8s集群受管节点上新建一个kube-lb0的虚拟网卡这样我们可以看到集群的loadbalancervip那么他也可以使用任意路由协议去实现ECMP允许在具有相同cost开销的多条路径之间进行负载均衡和流量分发。
同时purelb的layer2模式根据单个vip来选择节点将多个vip分散到不同节点尽量将流量均衡分开避免某些节点负载失衡发生故障。
二.layer2的配置演示
1.首先准备ipvs和arp配置环境
1开启ipvs并设置严格策略将mode改为ipvs将strictarp改为true
[rootk8s-master service]# kubectl edit configmap kube-proxy -n kube-system
configmap/kube-proxy edited 2修改完后保存并验证
[rootk8s-master service]# kubectl rollout restart ds kube-proxy -n kube-system
daemonset.apps/kube-proxy restarted
[rootk8s-master service]# kubectl get configmap -n kube-system kube-proxy -o yaml | grep strictARPstrictARP: true
[rootk8s-master service]# kubectl get configmap -n kube-system kube-proxy -o yaml | grep modemode: ipvs
3到这里我们就可以在受管节点node上看到新建了kube-lb0虚拟网卡
7: kube-lb0: BROADCAST,NOARP,UP,LOWER_UP mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000link/ether 12:00:b5:78:88:25 brd ff:ff:ff:ff:ff:ffinet6 fe80::1000:b5ff:fe78:8825/64 scope link valid_lft forever preferred_lft forever
2.purelb部署开始
1下载purelb-complete.yaml文件并应用
链接百度网盘 请输入提取码 提取码epbx
文件中crd问题导致第一次会失败应用两次后才能成功
[rootk8s-master service]# wget https://gitlab.com/api/v4/projects/purelb%2Fpurelb/packages/generic/manifest/0.0.1/purelb-complete.yaml
#内部不需要有更改
[rootk8s-master service]# kubectl apply -f purelb-complete.yaml
namespace/purelb created
customresourcedefinition.apiextensions.k8s.io/lbnodeagents.purelb.io created
customresourcedefinition.apiextensions.k8s.io/servicegroups.purelb.io created
serviceaccount/allocator created
serviceaccount/lbnodeagent created
role.rbac.authorization.k8s.io/pod-lister created
clusterrole.rbac.authorization.k8s.io/purelb:allocator created
clusterrole.rbac.authorization.k8s.io/purelb:lbnodeagent created
rolebinding.rbac.authorization.k8s.io/pod-lister created
clusterrolebinding.rbac.authorization.k8s.io/purelb:allocator created
clusterrolebinding.rbac.authorization.k8s.io/purelb:lbnodeagent created
deployment.apps/allocator created
daemonset.apps/lbnodeagent created
error: resource mapping not found for name: default namespace: purelb from purelb-complete.yaml: no matches for kind LBNodeAgent in version purelb.io/v1
ensure CRDs are installed first
[rootk8s-master service]# kubectl apply -f purelb-complete.yaml
namespace/purelb unchanged #创建了一个purelb的名称空间
customresourcedefinition.apiextensions.k8s.io/lbnodeagents.purelb.io configured
customresourcedefinition.apiextensions.k8s.io/servicegroups.purelb.io configured
serviceaccount/allocator unchanged
serviceaccount/lbnodeagent unchanged
role.rbac.authorization.k8s.io/pod-lister unchanged
clusterrole.rbac.authorization.k8s.io/purelb:allocator unchanged
clusterrole.rbac.authorization.k8s.io/purelb:lbnodeagent unchanged
rolebinding.rbac.authorization.k8s.io/pod-lister unchanged
clusterrolebinding.rbac.authorization.k8s.io/purelb:allocator unchanged
clusterrolebinding.rbac.authorization.k8s.io/purelb:lbnodeagent unchanged
deployment.apps/allocator unchanged
daemonset.apps/lbnodeagent unchanged
lbnodeagent.purelb.io/default created
2查看该有的资源是否创建完成并运行
[rootk8s-master service]# kubectl get deployments.apps,ds -n purelb
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/allocator 1/1 1 1 2m6s
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/lbnodeagent 2 2 2 2 2 kubernetes.io/oslinux 2m6s
[rootk8s-master service]# kubectl get crd | grep purelb
lbnodeagents.purelb.io 2023-12-04T08:18:07Z
servicegroups.purelb.io 2023-12-04T08:18:07Z
[rootk8s-master service]# kubectl api-resources | grep purelb.io #这要查看版本后面创建地址时要用到
lbnodeagents lbna,lbnas purelb.io/v1 true LBNodeAgent
servicegroups sg,sgs purelb.io/v1 true ServiceGroup
3配置地址池
这里我们使用192.168.2.11/24-192.168.2.19/24中间的地址
[rootk8s-master service]# cat pure-ip-pool.yaml
apiVersion: purelb.io/v1 #刚才查到的版本
kind: ServiceGroup #资源类型为ServiceGroup
metadata:name: my-purelb-ip-pool #这里指定的名称在后面我们创建service要制定这个资源名称namespace: purelb
spec:local: #本地配置v4pool: #ipv4地址池subnet: 192.168.2.0/24 #指定子网范围写和主机一个网段但没有使用的地址pool: 192.168.2.11-192.168.2.19 #指定地址范围aggregation: /32
[rootk8s-master service]# kubectl apply -f pure-ip-pool.yaml
servicegroup.purelb.io/my-purelb-ip-pool created
[rootk8s-master service]# kubectl get sg -n purelb -o wide
NAME AGE
my-purelb-ip-pool 22s
[rootk8s-master service]# kubectl describe sg my-purelb-ip-pool -n purelb
Name: my-purelb-ip-pool
Namespace: purelb
Labels: none
Annotations: none
API Version: purelb.io/v1
Kind: ServiceGroup
Metadata:Creation Timestamp: 2023-12-04T08:29:55ZGeneration: 1Resource Version: 2676UID: 6b564a29-2c6d-4a26-b5df-05aa253595f1
Spec:Local:v4pool:Aggregation: /32Pool: 192.168.2.11-192.168.2.19Subnet: 192.168.2.0/24
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Parsed 54s purelb-allocator ServiceGroup parsed successfully
3.purelb测试
1创建deploy和service在主机进行访问测试
在创建service时的注意点比较多如下
[rootk8s-master service]# vim service2.yaml
[rootk8s-master service]# cat service2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:labels:name: my-nginxname: my-nginxnamespace: myns
spec:replicas: 3selector:matchLabels:name: my-nginx-deploytemplate:metadata:labels:name: my-nginx-deployspec:containers:- name: my-nginx-podimage: nginxports:- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:name: my-nginx-servicenamespace: mynsannotations: #像openelb一样要添加注解信息指定我们创建的地址池purelb.io/service-group: my-purelb-ip-pool
spec:allocateLoadBalancerNodePorts: false #这个选项指定是否为服务分配负载均衡器的节点端口。如果设置为false则不会自动分配节点端口而是由用户手动指定。默认情况下该选项为true表示自动分配节点端口。externalTrafficPolicy: Cluster#这个选项指定了服务的外部流量策略。Cluster表示将外部流量分发到集群内的所有节点。其他可选值还有Local和Local用于指定将外部流量分发到本地节点或者使用本地节点优先。internalTrafficPolicy: Cluster#这个选项指定了服务的内部流量策略。Cluster表示将内部流量限制在集群内不会流出集群。其他可选值还有Local表示只将内部流量限制在本地节点。ports:- port: 80protocol: TCPtargetPort: 80selector:name: my-nginx-deploytype: LoadBalancer #指定type为负载均衡类型
[rootk8s-master service]# kubectl apply -f service2.yaml
deployment.apps/my-nginx unchanged
service/my-nginx-service created
[rootk8s-master service]# kubectl get service -n myns
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx-service LoadBalancer 10.105.214.92 192.168.2.11 80/TCP 12s
[rootk8s-master service]# kubectl get pods -n myns
NAME READY STATUS RESTARTS AGE
my-nginx-5d67c8f488-9lxdm 1/1 Running 0 73s
my-nginx-5d67c8f488-mxksb 1/1 Running 0 73s
my-nginx-5d67c8f488-nr6pb 1/1 Running 0 73s
[rootk8s-master service]# kubectl exec -it my-nginx-5d67c8f488-9lxdm -n myns -- /bin/sh -c echo pod1 /usr/share/nginx/html/index.html
[rootk8s-master service]# kubectl exec -it my-nginx-5d67c8f488-mxksb -n myns -- /bin/sh -c echo pod2 /usr/share/nginx/html/index.html
[rootk8s-master service]# kubectl exec -it my-nginx-5d67c8f488-nr6pb -n myns -- /bin/sh -c echo pod3 /usr/share/nginx/html/index.html
[rootk8s-master service]# curl 192.168.2.11 #负载均衡实现
pod3
[rootk8s-master service]# curl 192.168.2.11
pod2
[rootk8s-master service]# curl 192.168.2.11
pod1
[rootk8s-master service]# curl 192.168.2.11
pod3
[rootk8s-master service]# curl 192.168.2.11
pod2
[rootk8s-master service]# curl 192.168.2.11
pod1
[rootk8s-master service]# curl 192.168.2.11
pod3
[rootk8s-master service]# curl 192.168.2.11
pod2
[rootk8s-master service]# curl 192.168.2.11
pod1
2浏览器测试 4.卸载purelb
采用delete -f即可卸载
[rootk8s-master service]# kubectl delete -f service2.yaml
[rootk8s-master service]# kubectl delete -f pure-ip-pool.yaml
[rootk8s-master service]# kubectl delete -f purelb-complete.yaml