Skip to content

Execute "kubectl port-forward" for the duration of another command

License

Notifications You must be signed in to change notification settings

sapcc/with-kubectl-port-forward

Folders and files

NameName
Last commit message
Last commit date
Feb 14, 2025
Feb 28, 2025
Jan 15, 2025
Jan 16, 2024
Feb 12, 2025
Jan 16, 2025
Jan 16, 2025
Jan 17, 2024
Feb 6, 2025
Apr 4, 2024
Jan 16, 2024
Dec 6, 2024
Feb 28, 2025
Feb 28, 2025
Mar 15, 2024
Mar 22, 2024
Feb 14, 2025
Mar 22, 2024

Repository files navigation

with-kubectl-port-forward

As the name implies, this tool executes kubectl port-forward for the duration of the supplied command. For example, Keppel has a PostgreSQL database that can be reached passwordless on localhost, so the following works to log into the DB:

$ with-kubectl-port-forward service/keppel-postgresql 5432:5432 -- psql -U postgres -d keppel -h 127.0.0.1 -p 5432

This is the same as:

  1. running kubectl port-forward service/keppel-postgresql 5432:5432 in one shell
  2. running psql -U postgres -d keppel -h 127.0.0.1 -p 5432 in another shell
  3. terminating kubectl once psql is done

Installation

Clone the repo, then run make install in it.

Usage

$ with-kubectl-port-forward <port-forward-args>... -- <command>...

The exit status will be zero on success, or equivalent to the exit status of the first failing child otherwise.