003_部署loadbalance

简介: 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
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
goproxy部署
docker-compose部署
292 0
|
关系型数据库 MySQL Java
Sakai-21部署
记录了两种部署方式: ① 二进制部署 ② 源文件部署
Sakai-21部署
|
2月前
|
存储 Kubernetes 物联网
K3S完美部署
K3S完美部署
65 3
|
5月前
|
Kubernetes Cloud Native Docker
在 K8S 中部署一个应用 下
在 K8S 中部署一个应用 下
|
5月前
|
Kubernetes 调度 Docker
在 K8S 中部署一个应用 上
在 K8S 中部署一个应用 上
|
监控 NoSQL 测试技术
readis部署
redis部署
|
Python Perl
K3s部署
使用k3s部署python flask项目
K3s部署
|
NoSQL 网络协议 Oracle
umpServer部署及应用
umpServer部署及应用
285 0
VuePressBlog部署
VuePressBlog部署
374 0
VuePressBlog部署
|
Java
部署服务总结
关于常用应用的操作和部署过程中遇到的错误以及处理。
385 0