Kubernetes Port-Forward Go-Edition For Python
- Free software: MIT license
- Documentation: https://portforward.readthedocs.io.
Wheels are available for:
- Windows
- MacOS X
- Linux
with Python versions:
- 3.6
- 3.7
- 3.8
- 3.9
- 3.10
and architectures:
- x84_64
Requirements for installation from source
The following things are required when there is no wheel available for the target system.
- Go installed and available in the path (at least v1.16 / https://go.dev)
- Python (at least v3.6 - below was never tested but might work)
- gcc (for Windows available via MinGW)
Pip knows how to install portforward
.
pip install portforward
import requests
import portforward
def main():
namespace = "test"
pod_name = "web"
local_port = 9000 # from port
pod_port = 80 # to port
# No path to kube config provided - will use default from $HOME/.kube/config
with portforward.forward(namespace, pod_name, local_port, pod_port):
response = requests.get("http://localhost:9000")
print(f"Done: \n'{response.status_code}'\n'{response.text[:20]}...'")
if __name__ == "__main__":
main()
- Go native Kubernetes port-forwarding with the
.kube/config
from the home dir or any other path to config.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
This project is enabled by setuptools-golang.