dockergoogle-compute-enginekubernetesgoogle-cloud-platformgoogle-kubernetes-engine

How to SSH to docker container in kubernetes cluster?


I am fairly new to the Google Cloud platform and Docker and set-up a cluster of nodes, made a Dockerfile that copies a repo and runs a Clojure REPL on a public port. I can connect to it from my IDE and play around with my code, awesome!

That REPL should however probably be tunneled through SSH, but here is where my problem starts. I can't find a suitable place to SSH into making changes to the repo that Docker runs the REPL on:

I'd like to modify the source files via SSH, but I'll need to access the Docker code repository. I'm not sure how to proceed.

I understand this isn't exactly a typical way to deploy applications so I am not even sure it's possible to have multiple nodes work with a modified docker codebase (do the nodes share the JVM somehow?).

Concretely my question is how do I SSH into the docker container to access the codebase?


Solution

  • For more recent Kubernetes versions the shell command should be separated by the --:

    kubectl exec -it <POD NAME> -c <CONTAINER NAME> -- bash
    

    Please note that bash needs to be availalble for execution inside of the container. For different OS flavours you might need to use /bin/sh, /bin/bash (or others) instead.

    The command format for Kubernetes 1.5.0:

    kubectl exec -it <POD NAME> -c <CONTAINER NAME> bash