003_部署loadbalance

本文涉及的产品
网络型负载均衡 NLB,每月750个小时 15LCU
传统型负载均衡 CLB,每月750个小时 15LCU
应用型负载均衡 ALB,每月750个小时 15LCU
简介: 003_部署loadbalance

专注方向:

自动化流程服务

it咨询

it在线教学


doc

https://metallb.universe.tf/apis/

介绍

k8s 默认给每个 svc 分配的 都是 集群内部 ip

也就是 部署 网络 组件时 指定的 pod net cird


但是 有些服务需要 单独 ip 使用体验更好

比如, vpn 服务, dns 服务


默认的 k8s 是不支持 loadbalance svc 的。

需要 安装 插件


loadbalance 超出了calico 的工作范围,请安装 metallb 服务


Service LoadBalancer address allocation is outside the current scope of Calico, but can be implemented with an external controller. You can build your own, or use a third-party implementation like the MetalLB project.

参考

k8s\deploy\config\metallb

doc


loadbalance 超出了calico 的工作范围,请安装 metallb 服务


Service LoadBalancer address allocation is outside the current scope of Calico, but can be implemented with an external controller. You can build your own, or use a third-party implementation like the MetalLB project.


https://metallb.universe.tf/installation/#installation-by-manifest

镜像准备

host_ip=192.168.31.21
export  http_proxy="http://${host_ip}:7890"
export  https_proxy="http://${host_ip}:7890"
export  no_proxy="localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local,my-cluster-endpoint.com"
# yeah, ctr can pull images with the env variable http_proxy, but crictl cannot~
ctr -n k8s.io images pull  quay.io/metallb/controller:v0.13.7
ctr -n k8s.io images pull   quay.io/metallb/speaker:v0.13.7

部署服务

kubectl apply -f metallb-native.yaml
kubectl get pod -n metallb-system
# NAME                          READY   STATUS    RESTARTS   AGE
# controller-84d6d4db45-vr747   1/1     Running   0          13s
# speaker-q8wkk                 1/1     Running   0          13s

定义网络池

kubectl apply -f ip_pool.yaml
# ipaddresspool.metallb.io/cheap created

测试外部ip 分配

kubectl apply -f nginx_use_special_ip.yaml
# kubectl -n nginx-lb get svc
# NAME       TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
# nginx-lb   LoadBalancer   10.110.12.11   192.168.31.225   80:32408/TCP   46s

metallb-native.yaml

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml

ip_pool.yaml

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: net-192-168
  namespace: metallb-system
spec:
  addresses:
  # 225-238 is available, Because the home switch cannot modify the IP mask
  - 192.168.31.225-192.168.31.249
  avoidBuggyIPs: true
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: cheap-l2
  namespace: metallb-system
spec:
  ipAddressPools: [net-192-168]

nginx_use_special_ip.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: nginx-lb
  labels:
    name: nginx-lb
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: nginx-lb
  name: nginx-deployment
  labels:
    app: nginx-lb
spec:
  selector:
    matchLabels:
      app: nginx-lb
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx-lb
    spec:
      containers:
      - name: nginx-lb
        image: docker.io/library/nginx:1.23.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  namespace: nginx-lb
  name: nginx-lb
  annotations:
    metallb.universe.tf/address-pool: net-192-168
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: nginx-lb
  type: LoadBalancer
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
相关文章
|
弹性计算 监控 负载均衡
|
9月前
|
负载均衡 物联网 测试技术
部署硬件负载均衡时,如何评估设备的处理能力?
部署硬件负载均衡时,如何评估设备的处理能力?
566 130
|
9月前
|
运维 负载均衡 监控
部署硬件负载均衡和软件负载均衡时,分别需要考虑哪些因素?
部署硬件负载均衡和软件负载均衡时,分别需要考虑哪些因素?
405 127
|
负载均衡 网络协议 网络安全
SLB-Backend多实例部署配置健康检查
【10月更文挑战第22天】
261 3
|
运维 负载均衡 算法
|
9月前
|
运维 负载均衡 算法
部署硬件负载均衡设备时要注意哪些问题?
部署硬件负载均衡设备时要注意哪些问题?
247 57
|
负载均衡 网络协议 算法
LVS 负载均衡部署的三种模式 与搭建dr模式具体步骤
LVS 负载均衡部署的三种模式 与搭建dr模式具体步骤
|
12月前
|
弹性计算 监控 负载均衡
slb部署使用路径规则进行更细粒度控制
slb部署使用路径规则进行更细粒度控制
147 7
|
12月前
|
域名解析 监控 负载均衡
slb部署虚拟主机(Virtual Hosts)
slb部署虚拟主机(Virtual Hosts)
355 5
|
12月前
|
负载均衡 网络协议 安全
slb多站点或多域名部署
slb多站点或多域名部署
359 4

相关实验场景

更多