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