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 tunneled through SSH, but here is where my problem starts. I can't find a suitable place to SSH into for making changes to the repo that Docker runs the REPL on:
Adding or removing SSH keys for all of the instances in your project
part here.I would like to edit the source files via SSH but I would need to access the docker code repo. I don't know 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?
If your endgoal is to get remote SSH access to your private Kubernetes cluster nodes or pods, then you have 2 options: Option# 1: Install and run an OpenSSH server inside your docker container pod. SSH server listens on port 22 and you need to expose that to the outside network.
In order to SSH into the Pod, the Pod should have SSH server installed. This can be provisioned by installing OpenSSH Server as part of the Docker image tied to the Pod. The following commands should be included in the Dockerfile associated with the container tied to the Pod.
How do you use SSH to enter a Docker container? The traditional approach consists of two steps: Step 1: SSH into your remote Linux server (if you are running the container in a remote system). Step 2: And then you enter the shell of your running Docker container in interactive mode like this:
Step 1: SSH into your remote Linux server (if you are running the container in a remote system). Step 2: And then you enter the shell of your running Docker container in interactive mode like this: With that, you can run Linux command or do some maintenance of the service running inside the container.
The deployment.yaml file is connected to the Docker image created earlier, therefore to deploy the application to the Kubernetes cluster, we use the Docker image. The image will automatically create containers for the application when we deploy the application.
If you need a true interactive shell in a container, you can open a remote shell with the oc rsh command as long as the container includes a shell. By default, oc rsh launches /bin/sh: If you're using Kubernetes directly, you can use the kubetcl exec command to run a Bash shell in your pod. First, confirm that your pod is running:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With