### Install portforward via pip Source: https://portforward.readthedocs.io Use pip to install the portforward library. ```bash pip install portforward ``` -------------------------------- ### Forward a Kubernetes port using portforward Source: https://portforward.readthedocs.io Establishes a port-forwarding connection to a pod or service using a context manager. Requires a valid kubeconfig file, defaulting to $HOME/.kube/config. ```python import requests import portforward def main(): namespace = "test" pod_name = "web" # You can also use a service name instead 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() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.