MoJo2600 / pihole-kubernetes

PiHole on kubernetes
498 stars 173 forks source link

error when using loadBalancerIP on dual stack setups #228

Open craigcabrey opened 2 years ago

craigcabrey commented 2 years ago

Warning from MetalLB:

Warning  AllocationFailed  111s  metallb-controller  Failed to allocate IP for "pihole/pihole-dns-tcp": requested loadBalancer IP(s) ["192.168.100.101"] does not match the ipFamily of the service

values.yaml:

dualStack:
  enabled: true

[snip]

serviceDns:
  type: LoadBalancer
  loadBalancerIP: 192.168.100.101
  loadBalancerIPv6: [snip]:f904::101
  annotations:
    metallb.universe.tf/allow-shared-ip: pihole-svc

[snip]

What the Helm chart generates for the IPv4 services:

apiVersion: v1
kind: Service
metadata:
  name: pihole-dns-tcp
  labels:
    app: pihole
    chart: pihole-2.5.8
    release: pihole
    heritage: Helm
  annotations:
    metallb.universe.tf/allow-shared-ip: pihole-svc
spec:
  type: LoadBalancer
  loadBalancerIP: 192.168.100.101
  externalTrafficPolicy: Local
  ports:
    - port: 53
      targetPort: dns
      protocol: TCP
      name: dns
  selector:
    app: pihole
    release: pihole

What it generates for the IPv6 service:

apiVersion: v1
kind: Service
metadata:
  name: pihole-dns-tcp-ipv6
  labels:
    app: pihole
    chart: pihole-2.5.8
    release: pihole
    heritage: Helm
  annotations:
    metallb.universe.tf/allow-shared-ip: pihole-svc
spec:
  type: LoadBalancer
  ipFamilies:
  - IPv6
  ipFamilyPolicy: SingleStack
  loadBalancerIP: [snip]:f904::101
  externalTrafficPolicy: Local
  ports:
    - port: 53
      targetPort: dns
      protocol: TCP
      name: dns
  selector:
    app: pihole
    release: pihole

The workaround is to save the IPv4 service to a file, edit it to include the ipFamilyPolicy and ipFamilies directives, then apply it. After that, Metallb assigns the requested IPv4 address immediately.