txn2 / kubefwd

Bulk port forwarding Kubernetes services for local development.
https://imti.co/kubernetes-port-forwarding/
Apache License 2.0
3.78k stars 205 forks source link

Command to forward multiple svcs in multiple namespaces #234

Closed uchiha-pain closed 2 years ago

uchiha-pain commented 2 years ago

Hi, I have a cluster, and this cluster has 2 namespaces (control-plane-1 & control-plane-2). Both control planes have Cassandra database pods and a stargate pods.

microk8s kubectl get pods -n control-plane-1
NAME                                                    READY   STATUS    RESTARTS   AGE
demo-dc1-default-sts-1                                  2/2     Running   0          17h
demo-dc1-default-sts-0                                  2/2     Running   0          17h
demo-dc1-default-sts-2                                  2/2     Running   0          17h
demo-dc1-default-stargate-deployment-6ffdf566fd-g65ws   1/1     Running   0          17h
demo-dc1-reaper-7544498c-n9b6k                          1/1     Running   0          17h

and

microk8s kubectl get pods -n control-plane-2
NAME                                                    READY   STATUS    RESTARTS   AGE
demo-dc2-default-sts-1                                  2/2     Running   0          17h
demo-dc2-default-sts-0                                  2/2     Running   0          17h
demo-dc2-default-stargate-deployment-5f96d98578-klfwl   1/1     Running   0          17h
demo-dc2-reaper-7799d84f56-zgqpt                        1/1     Running   0          17h

Now, I want to forward stargate pod/svcs in both namespaces at the same time. But with kubectl port-forwarding command I am not able to achieve this goal (or maybe I don't know how to do multiple port-forwarding at the same time).

kubefwd is a command line utility built to port forward multiple services within one or more namespaces on one or more Kubernetes clusters

The statement above took me here to kubefwd and in my opinion it is a great utility. But I think the documentation is too vague or better to say that there is no documentation at all. So far, I came across the command that allows to forward all services in a particular namespace but what would be the command if I want to forward only one specific service? And what would be the command to forward multiple services in multiple namespaces? How can I assign an ip address of my choice? Let's say I want to forward stargate in both namespaces, how can I do that?

Thanks

cjimti commented 2 years ago

A few answers:

Also, please check the help command:

$ kubefwd svc --help
INFO[15:44:32]  _          _           __             _     
INFO[15:44:32] | | ___   _| |__   ___ / _|_      ____| |    
INFO[15:44:32] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |    
INFO[15:44:32] |   <| |_| | |_) |  __/  _|\ V  V / (_| |    
INFO[15:44:32] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|    
INFO[15:44:32]                                              
INFO[15:44:32] Version 1.22.3                               
INFO[15:44:32] https://github.com/txn2/kubefwd              
INFO[15:44:32]                                              
Forward multiple Kubernetes services from one or more namespaces. Filter services with selector.

Usage:
  kubefwd services [flags]

Aliases:
  services, svcs, svc

Examples:
  kubefwd svc -n the-project
  kubefwd svc -n the-project -l app=wx,component=api
  kubefwd svc -n default -l "app in (ws, api)"
  kubefwd svc -n default -n the-project
  kubefwd svc -n default -d internal.example.com
  kubefwd svc -n the-project -x prod-cluster
  kubefwd svc -n the-project -m 80:8080 -m 443:1443
  kubefwd svc -n the-project -z path/to/conf.yml
  kubefwd svc -n the-project -r svc.ns:127.3.3.1
  kubefwd svc --all-namespaces

Flags:
  -A, --all-namespaces          Enable --all-namespaces option like kubectl.
  -x, --context strings         specify a context to override the current context
  -d, --domain string           Append a pseudo domain name to generated host names.
  -f, --field-selector string   Field selector to filter on; supports '=', '==', and '!=' (e.g. -f metadata.name=service-name).
  -z, --fwd-conf string         Define an IP reservation configuration
  -h, --help                    help for services
  -c, --kubeconfig string       absolute path to a kubectl config file
  -m, --mapping strings         Specify a port mapping. Specify multiple mapping by duplicating this argument.
  -n, --namespace strings       Specify a namespace. Specify multiple namespaces by duplicating this argument.
  -r, --reserve strings         Specify an IP reservation. Specify multiple reservations by duplicating this argument.
  -l, --selector string         Selector (label query) to filter on; supports '=', '==', and '!=' (e.g. -l key1=value1,key2=value2).
  -v, --verbose                 Verbose output.