Kubernetes Port Forwarding for Dashboard Access¶
Kubernetes port forwarding is a network access method used to connect local services to resources running within a Kubernetes cluster.^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md] It is commonly employed to access web-based UIs, such as the Kubernetes Dashboard, directly from a local workstation without exposing the service externally.^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md]
Mechanism¶
The process creates a secure tunnel between a specific port on the local machine (localhost) and a port on a target Pod inside the cluster^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md]. This allows traffic sent to localhost:LOCAL_PORT to be routed to TARGET_POD:REMOTE_PORT.
Accessing the Kubernetes Dashboard¶
When using the official Helm chart, the Dashboard is typically not exposed via a public URL by default. Instead, users access it by forwarding a port to the Dashboard Pod^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md].
1. Identify the Target Pod¶
First, the name of the running Dashboard Pod must be retrieved. This can be done using kubectl get with a label selector to filter for the specific application instance^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md].
export POD_NAME=$([kubectl get pods](<./kubectl-get-pods.md>) -n default -l "app.kubernetes.io/name=kubernetes-dashboard,app.kubernetes.io/instance=kubernetes-dashboard" -o jsonpath="{.items[0].metadata.name}")
2. Establish the Tunnel¶
Once the POD_NAME is identified, the kubectl port-forward command is used to map a local port to the Pod's port^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md]. For the Kubernetes Dashboard, the default HTTPS port is 8443.
[kubectl](<./kubectl.md>) -n default port-forward $POD_NAME 8443:8443
3. Access the URL¶
With the tunnel active, the Dashboard becomes accessible at the local address specified during the forward operation^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md].
https://127.0.0.1:8443/
Sources¶
^[400-devops__06-Kubernetes__devops-helm__terraform-helm__README.md]