avahi-controller

by mm503

Helm chartv1.0.6App 1.0.6MITVerified publisher

Publishes Kubernetes LoadBalancer Service IPs as .local names over mDNS through the node's avahi-daemon

About this chart

avahi-controller

A Kubernetes controller that publishes LoadBalancer Service IPs to mDNS by managing a block in /etc/avahi/hosts on a designated node.

How it works

The controller runs as a single pod pinned to one node where avahi-daemon is installed. It watches Services cluster-wide and updates a managed block in the node's hosts file whenever the desired state changes. avahi-daemon picks up the change by itself: it watches /etc/avahi with inotify and re-reads the hosts file whenever a file there is written, so the chart needs no D-Bus or systemd access. The pod mounts only /etc/avahi/hosts and rewrites it in place; if the file is replaced on the host (for example by an editor that saves via rename), restart the pod so it binds to the new file.

avahi-daemon on the node answers the mDNS queries, not the controller, so names keep resolving while the pod restarts. Clients on the same network segment resolve the names with the mDNS support they already have; no router or DNS server configuration is needed.

Note: This is not a production tool. mDNS is not a production-level solution. This is intended for home labs and simple Kubernetes clusters.

Prerequisites

  • avahi-daemon installed and running on the designated node
  • A load balancer that assigns dedicated LAN addresses, such as MetalLB, kube-vip or Cilium LB-IPAM
  • Every static line in /etc/avahi/hosts must be one IP address and one hostname; avahi stops reading the file at the first invalid line
  • The node must be labeled with avahi-controller: "true" — the pod will remain Pending without this label
  • RBAC: list/watch on Services (cluster-wide), create/patch on Events

Limitations

  • One node. Only the designated node answers. If it or its avahi-daemon is down, the names stop resolving as client caches expire (120-second TTL), even when the load balancer has moved the IP to another node. replicaCount above 1 is not supported.
  • One hostname per IP address. avahi publishes only one name for each address in its hosts file. When Services with different hostnames share an IP (MetalLB allow-shared-ip), the one with the lowest namespace/name is published and the others get a SharedIPConflict Event.
  • Not a node's own address. A LoadBalancer IP that belongs to a node, which is what k3s ServiceLB (klipper-lb) assigns, is rejected by avahi and never published. The controller raises a NodeAddress Event when it is the designated node's address.
  • One address per Service. The first IP in status.loadBalancer.ingress is used.
  • One network segment. mDNS does not cross VLANs or subnets without a reflector.
  • Names. Use a single label followed by .local, such as myapp.local.

The project README explains each of these and lists alternatives.

Node labeling (required)

The controller writes the hosts file of the node it runs on, so it is pinned to the node where avahi-daemon runs. This is required even on a single-node cluster (k3s, etc.).

Label the node before installing:

kubectl label node <node-name> avahi-controller=true

Without this label, the pod's nodeSelector will not match any node and the pod will stay in Pending indefinitely.

Installation

helm repo add avahi-controller https://mm503.github.io/avahi-controller
helm repo update avahi-controller
helm install avahi-controller avahi-controller/avahi-controller \
  --namespace kube-system

Annotation

Add to any type: LoadBalancer Service:

annotations:
  avahi.homelab/hostname: "myapp.local"

The controller ignores Services without this annotation, and requeues with backoff if a LoadBalancer IP hasn't been assigned yet.

Hosts file block

The controller owns only a marked block and never touches the rest of the file:

# your static entries above are untouched

### BEGIN k8s-avahi-controller ###
# Managed by avahi-controller. Do not edit between these markers.
192.168.1.100 myapp.local
192.168.1.101 otherapp.local
### END k8s-avahi-controller ###

Values

KeyDefaultDescription
image.repositoryghcr.io/mm503/avahi-controllerContainer image repository
image.tag(chart appVersion)Image tag override
image.pullPolicyIfNotPresentImage pull policy
args[--cleanup-on-exit=false]Controller flags passed to the binary
nodeSelector{avahi-controller: "true"}Node selector — must match a labeled node
tolerations[{operator: Exists}]Tolerates any taint on the designated node
resources.requestscpu: 10m, memory: 32MiResource requests
resources.limitscpu: 50m, memory: 64MiResource limits
serviceAccount.createtrueCreate a ServiceAccount
rbac.createtrueCreate ClusterRole and ClusterRoleBinding
envNODE_NAME, HOST_IPEnvironment variables from the downward API. HOST_IP enables the NodeAddress warning. Helm replaces this list, so keep both when you override it
terminationGracePeriodSeconds30Grace period for pod shutdown

Release images are published to both ghcr.io/mm503/avahi-controller and docker.io/mm404/avahi-controller. The chart defaults to GHCR; set --set image.repository=mm404/avahi-controller to pull from Docker Hub.

Controller flags

FlagDefaultDescription
--hosts-file/etc/avahi/hostsPath to the avahi hosts file
--kubeconfig(in-cluster)Path to kubeconfig; empty uses in-cluster config
--cleanup-on-exitfalseRemove managed block from Avahi hosts on controller shutdown
--resync-period10mInformer resync interval
--verbosefalseVerbose logging
--debugfalseDebug logging (very noisy)

Example — enable verbose logging and remove the managed block on shutdown:

helm install avahi-controller avahi-controller/avahi-controller \
  --namespace kube-system \
  --set args="{--cleanup-on-exit=true,--verbose}"

Upgrade

helm repo update avahi-controller
helm upgrade avahi-controller avahi-controller/avahi-controller \
  --namespace kube-system

The chart is released together with the controller and has the same version number. A breaking change in either bumps the major version.

Upgrading from 0.6.x (chart 0.1.x)

The --reload and --avahi-service flags were removed, along with the host D-Bus socket mount; avahi-daemon reloads the hosts file on its own. Before upgrading:

  • Remove --reload and --avahi-service from args. The controller now exits at startup if either is passed.
  • If you set your own volumes, volumeMounts or env, delete the /run/dbus/system_bus_socket volume and mount and the DBUS_SYSTEM_BUS_ADDRESS variable. Helm replaces these lists instead of merging them, so a custom copy keeps mounting the host D-Bus socket, which gives the root container control of systemd on the node.

License

MIT — see LICENSE.

Deploy avahi-controller with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has avahi-controller on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartavahi-controller is pinned at v1.0.6 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply