Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to SSH to docker container in kubernetes cluster? [closed]

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:

  • The exposed IP just exposes the REPL service (correct kubernetes term?) and does not allow me to SSH in.
  • Neither does the cluster master endpoint, it gives me a public key error even though I've followed the 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?

like image 780
bbs Avatar asked Jul 20 '16 16:07

bbs


People also ask

How do I ssh into containers in Kubernetes?

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.

How do you ssh into a Kubernetes pod from outside the cluster?

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 I SSH into a docker container?

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:

How to run a docker container on Linux?

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.

How do I deploy an application to Kubernetes using Docker?

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.

How do I open a shell in a Kubernetes container?

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:


1 Answers

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 
like image 161
Sergey Shcherbakov Avatar answered Sep 20 '22 01:09

Sergey Shcherbakov