kubefwd icon indicating copy to clipboard operation
kubefwd copied to clipboard

app in() not work when using multiple different namespace

Open khumam opened this issue 2 years ago • 1 comments

Hi great work, I love it! First, I'm using kubefwd for port forwading on my staging with 'default' as namespace name. But now, I have several namespace, let say namespace-1, namespace-2, and default. Example

namespace service name
default s-cart
default s-order
namespace-1 cart
namespace-1 order
namespace-2 cart
namespace-2 order

When I used this command, it's work

sudo -E kubefwd svc -l "app in (s-cart,s-order)" 

its returned

INFO[14:43:59]  _          _           __             _
INFO[14:43:59] | | ___   _| |__   ___ / _|_      ____| |
INFO[14:43:59] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |
INFO[14:43:59] |   <| |_| | |_) |  __/  _|\ V  V / (_| |
INFO[14:43:59] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|
INFO[14:43:59]
INFO[14:43:59] Version 1.22.4
INFO[14:43:59] https://github.com/txn2/kubefwd
INFO[14:43:59]
INFO[14:43:59] Press [Ctrl-C] to stop forwarding.
INFO[14:43:59] 'cat /etc/hosts' to see all host entries.
INFO[14:43:59] Loaded hosts file /etc/hosts
INFO[14:43:59] HostFile management: Original hosts backup already exists at /Users/myname/hosts.original
INFO[14:44:00] Successfully connected context: context-name
INFO[14:44:00] Port-Forward:       127.1.27.1 s-cart:port to pod pod-cart-name:port
INFO[14:44:00] Port-Forward:       127.1.27.2 s-order:port to pod pod-order-name:port

But, when I used this command

sudo -E kubefwd svc -l "app in (cart,order)" 

the port forward can't connect to any pod, and it's freeze

INFO[14:43:59]  _          _           __             _
INFO[14:43:59] | | ___   _| |__   ___ / _|_      ____| |
INFO[14:43:59] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |
INFO[14:43:59] |   <| |_| | |_) |  __/  _|\ V  V / (_| |
INFO[14:43:59] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|
INFO[14:43:59]
INFO[14:43:59] Version 1.22.4
INFO[14:43:59] https://github.com/txn2/kubefwd
INFO[14:43:59]
INFO[14:43:59] Press [Ctrl-C] to stop forwarding.
INFO[14:43:59] 'cat /etc/hosts' to see all host entries.
INFO[14:43:59] Loaded hosts file /etc/hosts
INFO[14:43:59] HostFile management: Original hosts backup already exists at /Users/myname/hosts.original
INFO[14:44:00] Successfully connected context: context-name

Okay, so maybe I need to add namespace detail like this

sudo -E kubefwd svc -l "app in (cart,order)" -n namespace-1

and that's give me the same result, can't connect to any services or pods.

And I also set the config yaml then loaded to the command. The service.yaml

baseUnreservedIP: 127.1.27.1
serviceConfigurations:
- ip: 127.1.27.1
  name: cart.namespace-1.svc.cluster.local
- ip: 127.1.27.2
  name: order.namespace-2.svc.cluster.local

the command

sudo -E kubefwd svc -l "app in (cart,order)" -n namespace-1 -z service.yaml

# and also tried this command
sudo -E kubefwd svc -l "app in (cart,order)" -z service.yaml

The both of commands doesn't work, and not connected to any services or pods

There are any suggestion?

khumam avatar Sep 30 '22 07:09 khumam

And also I need to connect into different namespaces, lets say I want to connect into 'user' too from namespace-3

namespace service name
default s-cart
default s-order
namespace-1 cart
namespace-1 order
namespace-2 cart
namespace-2 order
namespace-3 user

And I don't know how to realize the command using app in method just for specific service name.

I know that we can use

sudo -E kubefwd svc -n namespace-1 -n namespace-3

But in my project, there are so many service name, and I won't to port forwarding all of the services

khumam avatar Sep 30 '22 07:09 khumam

To clarify: this issue is when there are identically-named services within multiple namespaces and those namespaces are listed in the kubefwd command, i.e. so the issue is disambiguating which service to connect to in multiple namespaces?

Woodz avatar Apr 16 '24 06:04 Woodz

@Woodz kubefwd uses the same field selector logic as kubectl, see https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/ and https://github.com/txn2/kubefwd/issues/215

As for service names, kubefwd only uses the "naked" service name for the first namespace it encounters (as if you were a service in that namespace). Check /etc/hosts, and you will see it also added standard Kubernetes DNS entries: example.namespace-a, example.namespace-a.svc, example.namespace-b, example.namespace-b.svc, etc...

cjimti avatar Apr 22 '24 00:04 cjimti