17

I am using Docker for Mac but currently only using it for its Kubernetes cluster. The Kubernetes cluster's single node is named docker-for-desktop.

I'm currently going through a Kubernetes tutorial on Persistent Volumes (https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/) and as part of that, I'm setting up a hostPath persistent volume. It seems like the way this works is, you create a path on the Kubernetes Node itself and you can use that as your persistent volume for development and testing purposes.

To do that, the tutorial instructs you to SSH into your Kubernetes node itself and create a path which can then be turned into a persistent volume. The only problem is, I have no idea how to SSH directly into the Kubernetes node itself (not a container). The equivalent for minikube would just be minikube ssh. I can kubectl describe the node, but I only get an internal IP address, not an external one. So I have no idea how to address it in an ssh command.

Any ideas?

2

4 Answers 4

14

Comment in the OP should get credit for this but i'll add again so i find it easier in a few months:

docker run -it --rm --privileged --pid=host justincormack/nsenter1

From https://github.com/justincormack/nsenter1/blob/master/README.md

... this is useful when you are running a lightweight, container-optimized Linux distribution such as LinuxKit... you are demonstrating with Docker for Mac, for example, your containers are not running on your host directly, but are running instead inside of a minimal Linux OS virtual machine specially built for running containers, i.e., LinuxKit. But being a lightweight environment, LinuxKit isn't running sshd, so how do you get access to a shell so you can run nsenter to inspect the namespaces for the process running as pid 1?

3

I was looking for the same thing. I am playing around with PV/PVC and really just wanted to get "eyes on" on the thing that's being stored.

I am running Kubernetes 1.22.5 and Docker Desktop 4.5.0

To gain access to the docker-desktop node

docker run -it --rm --privileged --pid=host justincormack/nsenter1

My PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
  namespace: my-namespace
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

Finding the Directory /mnt/data

There were quite a few different locations and manually sniffing was a little overwhelming. It's search to just search for what you're looking for:

Search for "data" directory

find / -type d -name "data"

This will return a list of matches. I had quite a few results. But now you can search your terminal for "mnt/data" and there you are.

Mine was at /containers/services/docker/rootfs/mnt/data

0

I was looking for an answer when running k8s on Docker Desktop, then I tried docker ps and to my surprise, the containers of my pod was there.

So I just ssh like you would with any docker container

$ docker exec -it 0b83055dac1b /bin/bash
1
  • I think OP wants to ssh to the k8's master node which in his case is docker-desktop Commented Feb 19, 2021 at 22:10
-1

Update:

If the node were created by docker-machine using VirtualBox, would be similar to minikube, with the command:

docker-machine ssh default

If you are using the default HyperKit driver for MAC, there isn't an VM like VirtualBox, but you should be able to open the shell with following command:

screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

Original:

If you have direct access to the node and the certificate, it is as simple as a command like this:

ssh -i certificatename 10.0.0.1

or

ssh -i certificatename [email protected]

take a look into this post.

If you are running Kubernetes in a cloud provider, you should use the provider tools to do that.

An example is the Google Cloud you would use:

gcloud compute ssh <NODE_NAME> --zone <ZONE>

Azure and Aws also have similar options, you can also use their portal for it.

Other alternative, is using a bastian\helper container in the cluster to connect to the nodes without setting up network permissions, it works on cloud or on premises clusters.

Something like:

kubectl run -it --rm aks-ssh --image=debian

This will run a container with bash, then you have to install the ssh client apt-get update && apt-get install openssh-client -y copy the client certificate to the container and ssh into the node like ssh -i id_rsa [email protected].

There is a nice example in the AKS docs

2
  • 1
    Doesn't the question ask specifically about Docker for Mac? Your answer seems to address the issue for a more generic installation on Cloud
    – Pierre B.
    Commented Mar 27, 2019 at 14:09
  • Correct @PierreB., the problem is that Docker for Mac doesn't seem to expose a DNS name or anything like that. This answer doesn't address that point.
    – Stephen
    Commented Mar 27, 2019 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.