I cannot run port-forward
in my k8s environment (based on k3s) and it shows failed to execute portforward in network namespace "...": failed to dial 8080: dial tcp4: lookup localhost: no such host error message when send the request to localhost:8080 (8080 is the exposed port of the k8s.gcr.io/echoserver:1.4
) .
The environment is:
Based in this environment I got the error message when I enable the wireguard in k3s host server + run port-forward command. But it success when disable the wireguard client. How can I solve this issue?
PS. kubectl proxy
works smoothly.
More detail about my environment 1. Server A in internet with WireGuard server (10.0.0.0/16) 2. My Laptop with WireGuard (10.0.1.1/32) 3. Server B behind NAT and Connect to WireGuard (10.0.1.2/32)
The Server B also install the k3s by default setting and deploy POD (k8s.gcr.io/echoserver:1.4) as the demo pod. The IP is 10.42.0.9 get by command kubectl describe pod
When I run kubectl port-forward PODNAME 8080:8080 -v=4
in my laptop and run sudo k3s kubectl port-forward PODNAME 8080:8080
in Server B, I get the same error message
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080
E0927 23:17:59.251557 140082 portforward.go:400] an error occurred forwarding 8080 -> 8080: error forwarding port 8080 to pod cbb517f914c88a3e063eb5982c182bc51fdc52a3d80acaf2c93876b0edba8d77, uid : failed to execute portforward in network namespace "/var/run/netns/cni-719289c5-7d83-02a9-3679-638ba1cc50bb": failed to dial 8080: dial tcp4: lookup localhost: no such host
And as I mentioned before, when I disconnect WireGuard in Server B everything goes smoothly and without any proble.
PS. I setup the kubernates environment via just run curl -sfL https://get.k3s.io | sh -
and the host server is ArchLinux.