Configuring port forwarding
Within a Kubernetes cluster, you can access an application by its internal IP address. But, if you want to access the application from your local machine, use the port forwarding feature. Using UI, you can forward a local port to a port on the pod that runs your application. This way you can interact with the application running in a Kubernetes cluster from your local machine for debugging and testing purposes.
You can use the port forwarding feature for the pods and services running on a Kubernetes cluster. Also, you can perform port forwarding for any exposed ports.
Prerequisites
Make sure you have:
- A running Podman machine.
- A running Kubernetes cluster, such as Kind or Minikube.
- Created a YAML configuration file with an exposed port:
apiVersion: v1
kind: Pod
metadata:
name: static-web
spec:
containers:
- image: nginx
name: web
ports:
- containerPort: 80
name: web
protocol: TCP
Procedure: Start port forwarding
-
Create a Kubernetes pod:
- Go to the Pods component page.
- Click Play Kubernetes YAML.
- Select a Kubernetes YAML file, such as
pod.yaml
from your local machine. - Set the Runtime field to
Kubernetes cluster
. - Click Play and then Done.
- View the newly created pod that runs on a Kubernetes cluster on the same page.
- Click the name of the pod and select the Summary tab.
-
Click the Forward... button corresponding to the port you want to use for port forwarding.
-
Click the Open button to view the running application in a web browser.
noteYou can also start port forwarding from the Kubernetes > Services component page. After creating a service, click the name of the service and configure port forwarding in the Summary tab.
Procedure: Stop port forwarding
You can stop port forwarding by using one of the following ways:
Use the component page
- Go to the Pods or Kubernetes > Services page.
- Click the name of the Kubernetes pod or service for which you want to stop port fowarding.
- Click Remove in the Summary tab. The entry is removed from the Kubernetes > Port Forwarding page.
Use the Port Forwarding page
- Go to the Kubernetes > Port Forwarding page.
- Click the Delete icon corresponding to the pod or servivce for which you want to stop port forwarding. The entry is removed from the page.
Verification
- Go to the Kubernetes > Port Forwarding page.
- View the port forwarding details for Kubernetes pods and services.