<p>I have a Kubernetes cluster which doesn't need to expose ports to the public. I am installing monitoring and logging (Prometheus &amp; Loki or Elastic) for in house use and would like to use their GUI. I could provision https ingress and limit IP access but port forwarding seems to work.</p>
<ol>
<li>How Does port forwarding work, under the hood?</li>
<li>Is port forwarding as secure as my kubectl connection?</li>
<li>Is the connection as fast as an ingress load balancer based HTTPs connection?</li>
</ol>

Rubber Duck
<p>In <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward" rel="nofollow noreferrer">Kubernetes documentation</a> you can find information that <code>port-forward</code> command allows you to access and interact with internal Kubernetes cluster processes from your localhost. Also it's one of the best tools to debugging.</p>
<blockquote>
<p>Forward one or more local ports to a pod. This command requires the node to have 'socat' installed.
Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted.
If there are multiple pods matching the criteria, a pod will be selected automatically. The forwarding session ends when the selected pod terminates, and rerun of the command is needed to resume forwarding.</p>
</blockquote>
<p><strong>1. How Does port forwarding work, under the hood?</strong></p>
<p>This information can be found in <a href="https://phoenixnap.com/kb/kubectl-port-forward" rel="nofollow noreferrer">How Does Kubernetes Port Forwarding Work?</a> article.</p>
<blockquote>
<p>The whole process is simplified by the fact that kubectl already has a built-in port forwarding functionality.</p>
</blockquote>
<blockquote>
<ol>
<li>A user interacts with Kubernetes using the kubectl command-line on their local machine.</li>
<li>The port-forward command specifies the cluster resource name and defines the port number to port-forward to.</li>
<li>As a result, the Kubernetes API server establishes a single HTTP connection between your localhost and the resource running on your cluster.</li>
<li>The user is now able to engage that specific pod directly, either to diagnose an issue or debug if necessary.</li>
</ol>
</blockquote>
<blockquote>
<p>Port forwarding is a work-intensive method. However, in some cases, it is the only way to access internal cluster resources.</p>
</blockquote>
<p><strong>2. Is port forwarding as secure as my kubectl connection?</strong></p>
<p>For this question, you can find answer in <a href="https://stackoverflow.com/q/50645059/11148139">Is kubectl port-forward encrypted?</a>. As pointed by @iomv</p>
<blockquote>
<p>As far as I know when you port-forward the port of choice to your machine kubectl connects to one of the masters of your cluster so yes, normally communication is encrypted. How your master communicate to the pod though is dependent on how you set up internal comms.</p>
</blockquote>
<p>or @neokyle</p>
<blockquote>
<p>kubectl port-forward uses socat to make an encrypted TLS tunnel with port forwarding capabilities. The tunnel goes from you to the kube api-server to the pod so it may actually be 2 tunnels with the kube api-server acting as a pseudo router.</p>
</blockquote>
<p>Kubecelt port-forward is encrypted.</p>
<p><strong>3. Is the connection as fast as an ingress load balancer based HTTPs connection</strong></p>
<p>As connection is inside the cluster, it should be faster than connection from outside the cluster to the cluster.</p>
<p>In addition, there was similar <a href="https://stackoverflow.com/questions/51468491/how-kubectl-port-forward-works/51476393">Stackoverflow thread</a> about <code>kubectl port-forward</code>.</p>
