<p><code>kubectl</code> exposes commands that can be used to create a Service for an application and assigns an IP address to access it from internet.</p>

<p>As far as I understand, to access any application within Kubernetes cluster there should be a Service resource created and that should have an IP address which is accessible from an external network.</p>

<p>But in case of <code>port-forward</code> how does <code>kubectl</code> create a connection to the application without an IP address which is accessible externally?</p>

<p>To start, it's useful to note and remember that in Kubernetes, <em>every</em> pod gets its own ip address from 10.*, that is usable only within the cluster. Now, the <code>port-forward</code> feature of kubectl simply tunnels the traffic from a specified port at your local host machine to the specified port on the specified pod. API server then becomes, in a sense, a temporary gateway between your local port and the Kubernetes cluster.</p>
<p><code>kubectl port-forward</code> forwards connections to a local port to a port on a pod. Compared to <code>kubectl proxy</code>, <code>kubectl port-forward</code> is more generic as it can forward TCP traffic while <code>kubectl proxy</code> can only forward HTTP traffic.</p>
<p><code>kubectl port-forward</code> is useful for testing/debugging purposes so you can access your service locally without exposing it.</p>
<p>Below is the name of the <code>pod</code> and it will forward it's port <code>6379</code> to <code>localhost:6379</code>.</p>
<pre><code>kubectl port-forward redis-master-765d459796-258hz 6379:6379 
</code></pre>
<p>which is the same as</p>
<pre><code>kubectl port-forward pods/redis-master-765d459796-258hz 6379:6379
</code></pre>
<p>or</p>
<pre><code>kubectl port-forward deployment/redis-master 6379:6379 
</code></pre>
<p>or</p>
<pre><code>kubectl port-forward rs/redis-master 6379:6379 
</code></pre>
<p>or</p>
<pre><code>kubectl port-forward svc/redis-master 6379:6379
</code></pre>
