Search code examples
powershellkubectlportforwarding

Powershell - execute multiple commands - kubectl port-forward on Windows


I'm running minikube (no tunnel) on Windows 10

Is it possible to run multiple commands that block the console until exited all at once? I am looking at kubectl port-forward here.

kubectl port-forward -n istio-system service/grafana 13000:3000;
kubectl port-forward --address 0.0.0.0 pod/web-ui-deployment-ff6ffbd44-5vxqk 8080:1337;

Only outputs:

Forwarding from 127.0.0.1:13000 -> 3000
Forwarding from [::1]:13000 -> 3000

Essentially it is blocking the next one from running. Ctrl+C just stops all from running.

This one is for mac - kubectl port-forward multiple services.

The commands can run individually in two PowerShell terminals so I don't think the issue lies with commands being hung.

NOTE: Running one command requires a Ctrl+C to exit it.


Solution

  • The first command will "block" in terms that once launched, PowerShell will wait until the process finishes (e.g. till you hit Ctrl + C to end task) before it will return and run the next command. Like the example that you linked to, the solution is to launch the process in the background, which allows the next command to run. You can do this with Start-Process

    Start-Process kubectl -ArgumentList "port-forward -n istio-system service/grafana 13000:3000"
    Start-Process kubectl -ArgumentList "port-forward --address 0.0.0.0 pod/web-ui-deployment-ff6ffbd44-5vxqk 8080:1337"