I can't get a shell from localhost to Pod

10/17/2018

From Pod to localhost, ssh works well. And ping also works well with each other. There is centos7 in Pod. Also, openssh-server is installed in Pod. But there is always an error.

kubectl get pods -o wide

NAME                   READY   STATUS    RESTARTS   AGE   IP             NODE      NOMINATED NODE
hadoop-master-pod      1/1     Running   0          39m   10.244.9.25    slave10   <none>
hadoop-secondary-pod   1/1     Running   0          48m   10.244.11.11   slave12   <none>

ssh 10.244.9.25

ssh: connect to host 10.244.9.25 port 22: Connection refused
-- K.k
centos
containers
docker
kubernetes
ssh

2 Answers

10/17/2018

10.244.9.25 IP is an internal IP address given to pod by Kubernetes ( you can read more about Kubernetes networking model here ) to use inside Kubernets cluster so you won't be able to SSH or even to ping to these IPs from outside the cluster. In other words the network containing 10.244.9.25 is like a private network inside the K8 cluster and your host machine (localhost) is on different network.

If you want to get into the container for example in here you can use kubectl exec -it hadoop-master-pod -- /bin/bash or /bin/sh depending on the shell installed in the container and you can do anything that you tried to do by SSH into the pod.

If you really want to SSH into the pod from localhost (outside the cluster) you can write a Kubernetes Service probably exposing over NodePort which will expose the 22 (default port of SSH) to outside via NodePort.

-- Hansika Madushan Weerasena
Source: StackOverflow

10/17/2018

You should be able to connect using kubectl exec -it hadoop-master-pod -- /bin/bash

Then You can check if your pod in listening on port 22 for 0.0.0.0

Check the iptables if there is nothing blocked.

Make sure openssh is running and on which port it's running.

-- Crou
Source: StackOverflow