kubernetes: ssh to a pod from another pod in same namespace

7/18/2018

I have created 4 containers within a single namespace( All have bash ). I want to ssh to container1 from container2.

I want to get some values like: the "image" used to create the container, any "Environment variables" etc.

How can I achieve it?

Thanks in advance.

Pritish

-- Pritish
containers
docker
kubernetes
kubernetes-helm

1 Answer

7/18/2018

If you really need to get necessary info to use with ssh, you could extract those info via Downward API, and make sure that your pods are ssh-enabled as well.

IMHO, the intuitive way to check for deployment status is using readiness check. In that case, you could run a bash script to check for specific environment variables, if those info is not available then those pods would be not allowed to server traffic.

For e.g:

readinessProbe:
  periodSeconds: 60
  exec:
    command:
    - "/bin/bash"
    - "-c"
    - if [ "$env" != "{{ .Values.environment }}" ]; then exit 1; fi
-- Tommy Nguyen
Source: StackOverflow