Updating Loadbalancer IP with Microk8s and Metallb
While using Metallb add-on in microk8s certainly makes life easy, what happens if you make a mistake with your original IP address configuration and you would like to physically assign an IP from a new IP range?
The answer is to use custom address pool. The details of which can be found on the microk8s add-on page.
In short you can add the following yaml to your cluster:
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: custom-addresspool
namespace: metallb-system
spec:
addresses:
- 192.168.1.1-192.168.1.100
Now that the new IP Address pool has been loaded into the kube, the final step is to point the ingress Loadbalancer to the desired address. You can edit the Loadbalancer by adding these two lines to the config:
This line under annotations
The loadBanacerIP in the spec, as seen below.
metadata:
annotations:
metallb.universe.tf/address-pool: custom-addresspool
spec:
selector:
name: nginx
type: LoadBalancer
loadBalancerIP: 192.168.1.100
In your utopia-ingress-nginx-controller it might look something like this once added:
apiVersion: v1
kind: Service
metadata:
name: utopia-ingress-nginx-controller
namespace: default
uid: 366c9141-b73b-4d38-afe9-1c0040203b94
resourceVersion: '6089'
creationTimestamp: '2024-04-01T09:31:51Z'
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: utopia
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1
helm.sh/chart: ingress-nginx-4.7.1
annotations:
meta.helm.sh/release-name: utopia
meta.helm.sh/release-namespace: default
metallb.universe.tf/address-pool: custom-addresspool
managedFields:
- manager: helm
operation: Update
apiVersion: v1
time: '2024-02-01T09:31:51Z'
subresource: status
selfLink: /api/v1/namespaces/default/services/utopia-ingress-nginx-controller
status:
loadBalancer:
ingress:
- ip: 192.168.1.100
spec:
ports:
- name: http
protocol: TCP
appProtocol: http
port: 80
targetPort: http
nodePort: 30711
- name: https
protocol: TCP
appProtocol: https
port: 443
targetPort: https
nodePort: 32668
selector:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: utopia
app.kubernetes.io/name: ingress-nginx
clusterIP: 10.152.183.223
clusterIPs:
- 10.152.183.223
type: LoadBalancer
loadBalancerIP: 192.168.1.100
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
allocateLoadBalancerNodePorts: true
internalTrafficPolicy: Cluster
This should help you assign the new IP address to your loadbalancer.
Last updated