SSH connection between two Pod in kubernetes

3/20/2018

I want to do ssh between two pods in kubernetes.

Can anyone tell me how to do that?

-- user2223296
kubernetes

2 Answers

3/20/2018

Instead of SSH (which is not recommended for a docker container, even in a Kubernetes environment), try kubernetes exec :

kubectl exec -it  <container/pod> bash

This is for a direct access: see "Get a Shell to a Running Container".

Note: kubectl cp can help copying from/to containers. (Although there is a bug which might be fixed only in K8S 1.10)

-- VonC
Source: StackOverflow

3/20/2018

Oversimplifying the answer, you can not.

That is, under "normal" circumstances... Your containers in pod launch single process, that is your application, be it nodejs, php, java or whatever, so they do not have a running SSH server inside their namespaces. Unless you explicitly run it by ie. running a "fat" container that launches a supervisor process (like ie. by using something like phusion/baseimage container) which by most in container world is considered an anti-pattern, or by running ssh in sidecar container, which will allow you to access that ssh server (but it will have it's own FS and potentially process tree, unless shared PID namespace is used).

As suggested in another answer, you could use serviceaccounts to grant your software rights to call kubernetes API and hence use things like ie. kubectl exec. Is it the right call for you... that depends on what you really want to achieve in the end.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow