You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you specify the name and port number of the pod on which the server is running, port forwarding will be performed using a free port in your local system.
Motivation
When developing tools and tests, we may want to make a request from local to a server running on our kubernetes cluster. Normally, we would use kubectl port-foward <pod name> <local port>:<remote port> to bind a remote port to a local port and send a request to that port, but we may want to automate this set of tasks. Therefore, we made a library so that this work can be done in the Go lauguage.
Install
go get github.com/goccy/kpoward
Synopsis
Create a Kpoward instance with rest.Config and the name and port number of the pod. If necessary, use the Setter method to change a value such as Namespace and then call Run will call back the local bound free port. You can send any request to this port in the callback. Upon exiting the callback, port forwarding will automatically end and the port will be released.