目录
安装kube-vip
kubectl apply -f https://kube-vip.io/manifests/rbac.yaml
使用daemonset部署kube-vip
export VIP=192.168.215.200 # vip地址 export INTERFACE=ens33 apt install jq KVVERSION=$(curl -sL https://api.github.com/repos/kube-vip/kube-vip/releases | jq -r ".[0].name") #或者 export KVVERSION=v0.8.0 然后配置 kubevip 方案,针对 k8e containerd 创建 kubevip 命令: alias kube-vip="ctr image pull ghcr.io/kube-vip/kube-vip:$KVVERSION; ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:$KVVERSION vip /kube-vip" #生成 Yaml 文件kubevip-ds.yaml: kube-vip manifest daemonset \ --interface $INTERFACE \ --address $VIP \ --inCluster \ --taint \ --controlplane \ --services \ --arp \ --leaderElection > kubevip-ds.yaml kubectl apply -f kubevip-ds.yaml #创建 kubevip 服务
配置服务实现负载均衡
#nginx-service.yml apiVersion: v1 kind: Service metadata: name: nginx-service namespace: default annotations: external-dns.alpha.kubernetes.io/hostname: mydomain.example.com #配置域名访问 spec: selector: app: nginx loadBalancerIP: 192.168.215.200 ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer #NodePort LoadBalancer ############################################################ kubectl apply -f nginx-service.yml
通过192.168.215.200vip地址就能访问nginx服务