<p>I want to forward the ports</p>
<pre><code>kubectl port-forward ...
</code></pre>
<p>But for this I need to find out the name of pods, I run the command</p>
<pre><code>kubectl -n main_sp get pods
</code></pre>
<p>Getting a list:</p>
<pre><code>NAME                              READY   STATUS    RESTARTS   AGE
main-ms-hc-78469b74c-7lfdh         1/1     Running   0          13h
</code></pre>
<p>I'm trying</p>
<pre><code>kubectl port-forward main-ms-hc-78469b74c-7lfdh 8080:80
</code></pre>
<p>and I get</p>
<pre><code>Error from server (NotFound): pods &quot;main-ms-hc-78469b74c-7lfdh&quot; not found
</code></pre>
<p>What am I doing wrong?</p>

<p>You need to mention the namespace too while using port-forward:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl port-forward -n main_sp main-ms-hc-78469b74c-7lfdh 8080:80
</code></pre>
<p>To port-forward a pod:</p>
<pre><code>$ kubectl port-forward -n &lt;namespace&gt; &lt;pod-name&gt; &lt;local-port&gt;:&lt;target-port&gt;
</code></pre>
<p>To port-forward a pod via service name:</p>
<pre><code>$ kubectl port-forward -n &lt;namespace&gt; svc/&lt;servic-name&gt; &lt;local-port&gt;:&lt;target-port&gt;
</code></pre>
