K8s - How trigger refresh of LoadBalancer svc IP?
I'm using metallb to assign IPs to LoadBalancers in a home lab k8s cluster. I've had to shrink the IP pool though as I need to use some of them in another test cluster.
I've done this but the IPs of the existing LB svcs have remained the same afterwards -- I need to give the LB svcs a kick somehow to get them to request new IPs. How can I do this?
Solution 1:
It looks like the answer to your question is contained in this github thread.
Everything should come down to recreate your service with the appropriate configmap. Look at this answer:
Before change
[root@m-k8s ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cfgmap-svc LoadBalancer 10.100.199.95 192.168.1.11 80:31463/TCP 2m5s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h13m
Change IP address
[root@m-k8s ~]# cat metallb-l2.yaml | grep 192.168
- 192.168.1.11-192.168.1.13
[root@m-k8s ~]# sed -i 's/11/101/;s/13/103/' metallb-l2.yaml
[root@m-k8s ~]# cat metallb-l2.yaml | grep 192.168
- 192.168.1.101-192.168.1.103
Just applykubectl apply -f metallb-l2.yaml
Delete and revise by kubelet
[root@m-k8s ~]# kubectl delete pods --all -n metallb-system
pod "controller-65895b47d4-l5xnn" deleted
pod "speaker-bk8gr" deleted
pod "speaker-bksns" deleted
pod "speaker-c2z6z" deleted
pod " speaker-chlt5" deleted
pod "speaker-scx6x" deleted
Recreate svc
[root@m-k8s ~]# kubectl delete service cfgmap-svc
service "cfgmap-svc" deleted
[root@m-k8s ~]# kubectl expose deployment cfgmap --type=LoadBalancer --name=cfgmap-svc --port=80
service/cfgmap-svc exposed
Check svc
[root@m-k8s ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cfgmap-svc3 LoadBalancer 10.104.192.184 192.168.1.101 80:31440/TCP 8s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h34m
You can also look at this github issue. Note, it is old thread.