How to ssh mini-kube or docker-desktop? - docker

I want to ssh minikube/docker-desktop, but I cant. How can i do that?
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane,master 4m47s v1.20.2 192.168.49.2 <none> Ubuntu 20.04.2 LTS 4.19.121-linuxkit docker://20.10.6
ssh minikube
ssh: Could not resolve hostname minikube: nodename nor servname provided, or not known
I am learning K8s and able to ssh while working on K8s hands-on labs available online. I'd like t test some stuff on my local environment.

minikube is the node name within the Kubernetes API, not a hostname in this case. Minikube offers a wrapper minikube ssh command to automate pulling the IP and whatnot. Docker Desktop does not offer an official way to get a shell in the VM as it's a single-purpose appliance and they want it in a known state, but you can fake it by running a super-superuser container like docker run -it --rm --privileged --pid=host justincormack/nsenter1 to break out into the host namespaces.

Related

How to share Minikube instance on both Docker for Windows and WSL2?

How to share a Minikube instance amongst Windows/Windows WSL?
In Windows WSL minikube start fails:
😄 minikube v1.22.0 on Ubuntu 20.04
✨ Using the docker driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
🏃 Updating the running docker "minikube" container ...
🤦 StartHost failed, but will try again: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
🏃 Updating the running docker "minikube" container ...
😿 Failed to start docker container. Running "minikube delete" may fix it: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
❌ Exiting due to IF_SSH_AUTH: Failed to start host: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
💡 Suggestion: Your host is failing to route packets to the minikube VM. If you have VPN software, try turning it off or configuring it so that it does not re-route traffic to the VM IP. If not, check your VM environment routing options.
📘 Documentation: https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/
🍿 Related issue: https://github.com/kubernetes/minikube/issues/3930
The above works in Windows:
😄 minikube v1.17.1 on Microsoft Windows 10 Pro 10.0.19042 Build 19042
🎉 minikube 1.22.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.22.0
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
✨ Using the docker driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🏃 Updating the running docker "minikube" container ...
🐳 Preparing Kubernetes v1.20.2 on Docker 20.10.2 ...
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, dashboard, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
Questions:
Why would it fail on Linux? Note: I originally installed Minikube on Windows.
Is there a way to share the Minikube environment?
Second I want to share one Docker context. docker context ls:
Windows:
Returns:
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * moby Current DOCKER_HOST based configuration npipe:////./pipe/docker_engine https://127.0.0.1:53873 (default) swarm
desktop-linux moby npipe:////./pipe/dockerDesktopLinuxEngine
Windows WSL (Ubuntu):
docker context ls
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://127.0.0.1:51967 (default) swarm
desktop-linux moby
Questions:
What is default?
What is desktop-linux?
Which one is recommended to fully utilize the performance boost of WSL?
Third I want to share one Kubernetes context. kubectl config get-contexts:
Windows:
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
docker-desktop docker-desktop docker-desktop
kubernetes/REDACTED kubernetes REDACTED
* minikube minikube minikube default
Windows WSL (Ubuntu):
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
docker-desktop docker-desktop docker-desktop
* minikube minikube minikube
Questions:
What is docker-desktop?
Can I safely delete docker-desktop?
I was able to synchronize both Windows/WSL by copying the configuration files:
mkdir ~/.kube \ && cp /mnt/c/Users/[USERNAME]/.kube/config ~/.kube
kubectl config use-context docker-for-desktop # Select the Windows context
kubectl cluster-info # Check if it works## Heading ##
Ref: https://devkimchi.com/2018/06/05/running-kubernetes-on-wsl/

Exiting due to GUEST_MOUNT_CONFLICT : While starting minikube

I am trying to use kubernetes for local deployment using minikube, I want to mount a share a directory between host machine and pods. For this, I am trying to mount directory to minikube. But I already had minikube running on which few deployments were running. I deleted them. But every time I restart minikube with mount I get following error
$ minikube start --mount-string="/var/log:/log" --mount
* minikube v1.14.2 on Ubuntu 18.04
* Using the docker driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Restarting existing docker container for "minikube" ...
X Exiting due to GUEST_MOUNT_CONFLICT: Sorry, docker does not allow mounts to be changed after container creation (previous mount: '', new mount: '/var/log:/log)'
Output for kubectl get all is
kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2s
What am I doing wrong here. I need to mount /var/log:/log in my pods just like docker
You will have to delete the minikube container first using minikube delete , after that recreate the container with the new mount path minikube start --mount-string="/var/log:/log" --mount
Check this Github Issue for more details
You can try
$ minikube mount /Users/user/dir:/opt/dir
$ minikube ssh
$ ls /opt/dir # this should be mounted within minikube VM
and start minikube initially without any flags
$ minikube start
The error you see happens when you try to change the mount configuration on an existing cluster when using Docker. Docker doesn't allow changing of volumes after the container has been created and thus you cannot change the mount-string on minikube start after the cluster has already been created. More info and source for this behavior can be found here and here.

How to access NodePort in Minikube with docker driver?

I launched minikube with the docker driver on a remote machine and I have used a nodePort service for a particular pod. I believe nodePort exposes the port on the minikube docker container. On doing minikube IP it gave me the IP of the docker container in which minikube runs. How can I port map the port from the minnikube container to the host port so that I can access it remotely. A different approach would other than using driver=none or restarting minikube is appreciated as I do not want to restart my spinnaker cluster.
There is a minikube service <SERVICE_NAME> --url command which will give you a url where you can access the service. In order to open the exposed service, the minikube service <SERVICE_NAME> command can be used:
$ minikube service example-minikube
Opening kubernetes service default/hello-minikube in default browser...
This command will open the specified service in your default browser.
There is also a --url option for printing the url of the service which is what gets opened in the browser:
$ minikube service example-minikube --url
http://192.168.99.100:31167
You can run minikube service list to get list of all available services with their corresponding URL's. Also make sure the service points to correct pod by using correct selector.
Try also to execute command:
ssh -i ssh -i ~/.minikube/machines/minikube/id_rsa docker#$(minikube ip) -L *:30000:0.0.0.0:30000
Take a look: minikube-service-port-forward, expose-port-minikube, minikube-service-documentation.

Getting ErrImagePull when trying to use Local Docker Registry with Kubernetes

First I create a local Docker registry...
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Then I push
docker push localhost:5000/jrg/hello-k8s
I confirm it is there by
$ docker pull localhost:5000/jrg/hello-k8s
Using default tag: latest
latest: Pulling from jrg/hello-k8s
Digest: sha256:c475cb7167208e8f018e54ad81d4b7bbbb9c14875bc1624bcce730edf9afede0
Status: Image is up to date for localhost:5000/jrg/hello-k8s:latest
Then I start Minikube
minikube start --insecure-registry=localhost:5000
But when I run
kubectl create deployment hello-k8s --image=localhost:5000/jrg/hello-k8s
I get
NAME READY STATUS RESTARTS AGE
hello-k8s-75846c4bfc-b7zp7 0/1 ErrImagePull 0 4s
What am I missing?
Update
I also tried (assuming 5.5.5.5 is the IP address for my wireless adapter (confirmed by accessing in the browser).
Then I start Minikube
minikube start --insecure-registry=5.5.5.5:5000
But when I run
kubectl create deployment hello-k8s --image=5.5.5.5:5000/jrg/hello-k8s
But I still get the same issue, also after a while it appears to become ImagePullBackOff
FYI Project (https://github.com/jrgleason/hello-kubernetes/tree/ADD_CASSANDRA)
I think the issue is localhost will reference the kubernetes host itself, and not your registry.
You need to make it so that the registry is accessible from inside minikube. Try using the ip address of your computer instead of localhost.
There is a proxy addon for minikube that will allow you to access localhost from within minikube. I would suggest setting this up as the simplest solution https://github.com/Faithlife/minikube-registry-proxy
If this doesn't work there is a guide here to setup minikube with a local registry https://blog.hasura.io/sharing-a-local-registry-for-minikube-37c7240d0615/
If you are using minikube you must start the docker registry on the minikube machine.
You can either use the minikube registry addon, or use docker yourself. Make sure to use the docker daemon from the minikube host:
eval $(minikube docker-env)
You must push the image to the right registry then, f.e. by using the remote docker daemon for building and pushing to 'localhost' (which is the minikube VM in that case)

Unable to start container using kubectl

I am learning kubernetes and using minikube to create single node cluster in my ubuntu machine. In my ubuntu machine Oracle Virtualbox is also installed. As I run
$ minikube start
Starting local Kubernetes v1.6.4 cluster...
...
$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority: /root/.minikube/ca.crt
server: https://192.168.99.100:8443
name: minikube
...
$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8000
error: failed to discover supported resources: Get https://192.168.99.100:8443/api: Service Unavailable
I am not getting that what is causing this error. Is there some place we can check for logs. I cannot use kubectl logs as it requires container to mention which is not creating at all. Please provide any possible solution to problem.
You can debug using these steps:
kubectl talks to kube-apiserver at port 8443 to do its thing. Try curl -k https://192.168.99.100:8443 and see if there's a positive response. If this fails, it means kube-apiserver isn't running at all. You can try restarting the VM or rebuilding minikube to see if it comes up properly the 2nd time round.
You can also debug the VM directly if you feel brave. In this case, get a shell on the VM spun up by minikube. Run docker ps | grep apiserver to check if the kube-apiserver pod is running. Also try ps aux | grep apiserver to check if it's run natively. If both don't turn up results, check the logs using journalctl -xef.

Resources