003_部署loadbalance

关于我们

https://yuemake.xyz
公众号: 悦码客
v: ymkcode
视频教程:https://www.bilibili.com/video/BV1bG411M7we?vd_source=2d319a7a197bc133da44d00cd53e970c

专注方向:
自动化流程服务
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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuemake999

请我喝茶呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值