<p>I am trying to open the terminal inside the container and execute the command.</p>
<p>When I use this: kubectl exec -it POD_NAME, I cannot connect, I see connection timeout.</p>
<p>Do you know other methods instead of kubectl exec to open a terminal inside the container?</p>

user3740179
<p>Yes!</p>
<p>ssh into the Kubernetes node/machine where your container is running and run:</p>
<pre class="lang-sh prettyprint-override"><code>$ docker exec -it &lt;container-name&gt; sh
</code></pre>
<p>or if you have bash in the container</p>
<pre class="lang-sh prettyprint-override"><code>$ docker exec -it &lt;container-name&gt; bash
</code></pre>
<p>The fact that it's timing out means that you may have some other networking issues in your cluster like a firewall preventing access, your kube-apiserver not being accessible, or your network overlay not configured the way it's supposed to.</p>
<p><a href="https://erkanerol.github.io/post/how-kubectl-exec-works/" rel="nofollow noreferrer">This is the best guide I know</a> to understand how <code>kubectl exec ...</code> works under the hood, if you'd like to understand where things might be wrong.</p>
