<p>I want to use ssh from localhost to Pod. Is there any way to connect using <code>ssh [Pod_IP]</code> without using <code>kubectl exec -it [Pod] /bin/bash</code>? </p>

<p>The results are as shown in <code>ERROR: ssh: connect to host [ip] port 22: Connection refused</code>.</p>

K.k
<p>I think you can achieve this goal by installing <code>openssh-server</code> on the targeted Pod</p>

<p><strong>For example:</strong></p>

<p>Establish SSH connection to the Pod:</p>

<pre><code>$ kubectl exec -it &lt;Pod_name&gt; -- /bin/bash
$ apt-get update
$ apt-get install -y openssh-server
</code></pre>

<p>Ensure that SSHD service is up and running:</p>

<pre><code>$ service ssh status
</code></pre>

<p>Start it if necessary:</p>

<pre><code>$ service ssh start
</code></pre>

<p>Edit the <code>/etc/ssh/sshd_config</code> file if you want to change some specific settings, and restart the SSH service.</p>

<p>Check the connection via SSH from your local machine using Pod IP address.</p>

<p><strong>Update:</strong></p>

<p>I use the following Pod configuration in order to establish SSH connection to the Centos 7 container:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: centos
spec:
  containers:
  - name: centos
    image: centos:latest
    command: [ "/bin/bash", "-c", "yum install openssh-server -y &amp;&amp; /usr/bin/ssh-keygen -A &amp;&amp; /usr/sbin/sshd -p 
22 -f /etc/ssh/sshd_config &amp;&amp; tail -f /dev/null" ]
    securityContext:
      privileged: true
</code></pre>
