By Krust··7 min read

Kubernetes Service DNS on macOS Without localhost Rewrites

How scoped cluster-local DNS and port forwarding can preserve stable service URLs on macOS without rewriting every client to localhost.

networkingport-forwarddns
Stable Kubernetes service URL workflow using scoped DNS and port forwarding in Krust

Most Kubernetes teams know this kubectl flow:

kubectl port-forward svc/api 8080:80 -n default

Then local code, Postman collections, and callback URLs get rewritten to random localhost ports.
That works, but it creates drift and breaks parity fast in multi-service workflows.

Today, Krust keeps that workflow stable with three pieces working together:

  • a port-forward engine that maintains the actual Kubernetes tunnel
  • scoped DNS in the Packet Tunnel for svc.cluster.local, cluster.local and short .svc names
  • a local DNS listener that answers only from Krust’s active mapping snapshot
  • a local networking layer that keeps service-style hostnames usable from macOS apps

The result is the same goal as before, but the implementation is different from the older manual resolver-style flow. Krust now scopes DNS through the Packet Tunnel, relays only cluster-local lookups to the local DNS listener, and keeps hostname mappings synchronized from the app.


Why Plain kubectl port-forward Becomes Fragile

Traditional Kubernetes port forwarding binds each tunnel to 127.0.0.1:<local-port>.

That causes three recurring issues:

  1. URL rewrites in local code, test scripts, and API clients
  2. Port collisions when several services use port 80 or 443
  3. Lower environment parity between local development and in-cluster behavior

Current Architecture in Krust

Krust uses three layers:

  1. Port Forward Engine
    Opens and maintains forwards for Pods, Services, and workloads.

  2. Scoped Cluster-Local DNS The Packet Tunnel takes DNS lookups under svc.cluster.local, cluster.local and short .svc names, then relays them to Krust’s local DNS listener. A short name like broker.kafka.svc is answered as broker.kafka.svc.cluster.local, the way a pod’s search list would expand it.

  3. Local Networking / Tunnel Plumbing
    Krust keeps the DNS snapshot and local routing state aligned so those service-style hostnames stay usable in browsers, API clients, and scripts.

End result: you keep stable service URLs while traffic still flows through local secure forwarding.

Stable service URLs with DNS Proxy + Port Forward in Krust Current flow: start forward -> DNS mapping -> cluster-style URL opens locally.


How the Runtime Flow Works

  1. Start a forward from Pod/Service/Deployment/StatefulSet/DaemonSet.
  2. Krust resolves target pod(s) and opens local forwarding.
  3. Krust allocates a stable local VIP and registers a DNS mapping for that service hostname.
  4. The scoped DNS path serves *.svc.cluster.local and short *.svc lookups from the current snapshot.
  5. Krust tracks mappings by hostname and service port, so hostname:80 and hostname:443 do not overwrite each other.
  6. If backend pods restart, Krust reconnects and refreshes the mapping state where possible.

For common ports like 80 and 443, Krust can use safe local fallback ports when needed.


Free vs Pro in This Workflow

Current licensing behavior:

  • Free: 1 active DNS mapping
  • Pro: multiple concurrent DNS mappings
  • Free: saved port-forward profiles with manual start
  • Pro: reopen last session’s forwards in one step

So day-to-day forwarding works on Free, while hybrid multi-service DNS-heavy setups unlock fully on Pro. See Licensing for the current Free vs Pro gates.


Why Teams Prefer This Over Manual Localhost Mapping

1. Better parity with in-cluster naming

Keep service-style hostnames in local configs and tests.

2. Less config drift

Fewer “dev-only localhost rewrites” in code and scripts.

3. Better multi-service ergonomics

Forward several internal services without juggling random port maps.

4. Faster re-entry

Saved profiles (Pro) bring recurring tunnels back in one step.

5. More resilient during restarts

Krust reconnect logic reduces manual restart cycles after pod churn.


What Changed From the Older Flow

The important architectural update is not just “VPN exists now.” It is that Krust no longer depends on an older manual resolver-install pattern to keep service DNS working.

What changed:

  • DNS is scoped through the Packet Tunnel to svc.cluster.local, cluster.local and short .svc names, with one port-53 network rule per domain
  • public DNS and non-cluster domains stay on the normal macOS resolver path and are not forwarded by Krust
  • Mapping state is pushed from the app as a live snapshot instead of relying on a separate resolver-style setup step
  • Service hostname mappings are tracked per service port, which avoids the old class of collisions where one hostname could overwrite another active mapping

For users, this means the feature behaves more like a real system capability and less like a local workaround you have to babysit.

UI Views You Should Use

The DNS Proxy settings area in Krust shows whether Local Routing is enabled, whether the Packet Tunnel DNS path is healthy, and whether the current mapping set is active.

Service port selection in Krust Choose Service port mapping directly from the context menu.

Prometheus opened via cluster-local hostname Example access via cluster-style hostname with local fallback port.

DNS proxy mappings in Krust Verify active hostname mappings, loopback targets, and resources.


Practical Example

Instead of rewriting:

  • http://payments.default.svc.cluster.local:80 -> http://localhost:8082

you keep:

  • http://payments.default.svc.cluster.local:80

and let Krust manage the underlying DNS mapping, local VIP, and forwarding state.


Updated Recommendation

If your team still rewrites service URLs to localhost manually, move to DNS-aware forwarding now:

  • use Free for single-mapping daily flows
  • use Pro when you need multiple mappings and persistent profiles

That reflects how Krust works today: scoped cluster-local DNS, port-aware mappings, and local Network Extension plumbing instead of the older resolver-based approach.

Download Krust for macOS or continue with the Port Forwarding docs.