Why SSH is not working in kubernetes pods/container?

12/20/2019

We have an application which uses SSH to copy artifact from one node to other. While creating the Docker image (Linux Centos 8 based), I have installed the Openssh server and client, when I run the image from Docker command and exec into it, I am successfully able to run the SSH command and I also see the port 22 enabled and listening ( $ lsof -i -P -n | grep LISTEN).

But if I start a POD/Container using the same image in the Kubernetes cluster, I do not see port 22 enabled and listening inside the container. Even if I try to start the sshd from inside the k8s container then it gives me below error:

Redirecting to /bin/systemctl start sshd.service Failed to get D-Bus connection: Operation not permitted.

Is there any way to start the K8s container with SSH enabled?

-- Abhishek Jain
kubernetes
ssh

1 Answer

12/23/2019

There are three things to consider:

  1. Like David said in his comment:

I'd redesign your system to use a communication system that's easier to set up, like with HTTP calls between pods.

  1. If you put a service in front of your deployment, it is not going to relay any SSH connections. So you have to point to the pods directly, which might be pretty inconvenient.

  2. In case you have missed that: you need to declare port 22 in your deployment template.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow