https://rancher.com/ logo
Title
q

quick-midnight-5000

08/31/2022, 8:36 PM
Is there a way to map forwarded ports to a specific IP address when creating a cluster? I have a made-up domain for development (
dev.local
) and I've previously made this work by adding a HOSTS entry to map to an always-consistent IP (
192.168.64.200
) and then having MetalLB + Traefik's Ingress LB mapped to that IP specifically on port 80. In my head that means I should be able to:
k3d cluster create foo-cloud --no-lb --k3s-arg="--disable=traefik@server:0" -p "192.168.64.200:80:80"
but k3d doesn't seem to agree:
FATA[0000] failed to transform ports: No nodefilters specified
Is there a more appropriate way to accomplish this?
The
--no-lb
and disabling Traefik are to accommodate a pre-existing Traefik + MetalLB configuration, but perhaps it may be more appropriate to use Klipper at least?
I can drop the IP address to access the cluster under
localhost
no issue, mapping an
/etc/hosts
entry to
localhost
seems to fail because the port forward isn't actually listening for that host.
Ah, for future readers: this is because containers don't inherit
/etc/hosts
entries and need to be specified with
--host-alias
. And because
--host-alias
only understands IPs, it means you must have an
/etc/hosts
entry like
127.0.0.1 foobar.local
and then an additional
--host-alias 127.0.0.1 foobar.local
when running
k3d cluster create
w

wide-garage-9465

08/31/2022, 9:27 PM
The only error k3d states is that you didn't mention for which node you want to forward the ports. Since it's port 80, just go for
@loadbalancer
, appended to your -p value.
*just read it again and you disabled the lb, sorry.
Note though that --no-lb is not about Klipper but about k3d's cluster loadbalancer
q

quick-midnight-5000

08/31/2022, 9:30 PM
Ah, well I ended up dropping MetalLB and doing the above and it seems to work as expected. Perhaps MetalLB and Klipper were interfering with each other on top of the host mapping issue.
No, what I said about host aliasing isn't quite right, or at least unrelated. It's specifically just that
/etc/hosts
entries that map to
localhost
will not function whereas mapping directly to
127.0.0.1
will.
w

wide-garage-9465

09/04/2022, 2:01 PM
Ah sorry, I never got back to this. Well,
/etc/hosts
must have one IP per line, which it "resolves" the names on the same line to.