How to enter docker containers deployed on Google cluster? - docker

I have deployed my application via docker on Google Kubernetes cluster. I am facing an application error due to which I want to enter inside the container and check a few things. At local, all I had to do was run sudo docker ps and then exec -it into the container.
How can I do that when containers are deployed on a Kubernetes cluster?

You need to use kubectl
kubectl get pods
kubectl exec -it pod-container-name -- /bin/bash

Related

how to check docker containers and images inside aks nodes

how to check running docker containers and images for the deployed pods inside aks nodes?
I have deployed company pods and services inside the azure aks cluster.
Need to login as a root user inside containers running inside nodes of managed aks cluster. Those containers are of rabbitmq pods deployed with bitnami helm chart.
I was able to login into worker nodes by following this link https://learn.microsoft.com/en-us/azure/aks/node-access, but couldn't find the docker package running/installed inside them.
They do have containerd://1.4.9+azure as the CONTAINER-RUNTIME.
Tried below commands of 'containerd' inside those nodes, but nothing came, empty response, no running containers or downloaded images.
ctr container ls
ctr images ls
So how to check running docker containers and images for the deployed pods inside aks nodes?
We can use the below commands to check running containers inside worker nodes of managed k8s clusters at least in the case of aks clusters.
Here's the reference link https://kubernetes.io/docs/tasks/debug-application-cluster/crictl/
use below commands
sudo crictl --help
sudo crictl ps
sudo crictl images
I use nerdctl instead. Here are the steps work for me..
Create a debug pod to access the aks node
kubectl debug node/<nodeName> -it --image=mcr.microsoft.com/dotnet/runtime-deps:6.0
You can interact with the node session by running below command:
chroot /host
Install nerdctl tool:
wget https://github.com/containerd/nerdctl/releases/download/v0.20.0/nerdctl-0.20.0-linux-amd64.tar.gz
tar zxvf nerdctl-0.20.0-linux-amd64.tar.gz -C /usr/local/bin/
alias n=nerdctl
Check the containers in the AKS node
nerdctl --namespace k8s.io ps -a
Reference:
https://kubernetes.io/docs/tasks/debug/debug-cluster/crictl/
https://learn.microsoft.com/en-us/azure/aks/node-access
https://github.com/containerd/nerdctl#whale-nerdctl-load

Can't create spanner instance emulator in minikube

On local environment, use spanner's docker emulator to create development tools.
If use minikube, run its docker in kubernetes environment, can start its container
minikube start
eval $(minikube docker-env)
docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator
But can't create an instance via gcloud command
gcloud spanner instances create test-env --config=emulator-config --description="Local dev instance" --nodes=1
It became pending.
When use an environment without minikube, I can start docker and create an instance
docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator
gcloud spanner instances create test-env --config=emulator-config --description="Local dev instance" --nodes=1
gcloud spanner instances list
It seems can't run gcloud spanner command under minikube's docker-env. Why?
Doing eval $(minikube docker-env) configures environment to use minikube’s Docker daemon (https://minikube.sigs.k8s.io/docs/commands/docker-env/).
Thus, emulator is running "inside" the docker domain that is running "inside" the minikube cluster.
You can verify the same by sshing into the minikube cluster using ssh minikube to see the list of running processes. You can then do a curl on http://localhost:9020/v1/projects/test-project/instances, which should return a result immediately.
This seems likely due to the port not being exposed.
By default, minikube only exposes ports 30000-32767. You can change that with the following:
minikube start --extra-config=apiserver.service-node-port-range=1-65535
https://minikube.sigs.k8s.io/docs/handbook/accessing/#increasing-the-nodeport-range

Accessing kafka running on the local machine from Docker Toolbox.?

I have a kafka cluster installed in my local windows machine, and I would like to access this cluster from my spring boot application deployed as a container in docker toolbox, here is my application.properties file.
kafka.bootstrapAddress = 127.0.0.1:9092
And when I launch the container I use the host network but it doesn't work.
docker run spring-app:latest --network host
So how can i access this cluster. ?
Thank you in advance.
From the docker run reference, the docker run command usage is like this:
$ docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
You are not providing the --network option correctly. The option must come before the image name and whatever comes after the image name will be passed to the created container as the command and arguments.
Here is how you should invoke the command to correct your issue:
$ docker run --network host spring-app:latest

Cannot access docker hub after eval of minikube docker env?

I am really confused, I had being learning kubernetes with minikube creating services and other things.
The problem comes in the following shape:
I run the following commands after a fresh install of minikube:
eval $(minikube docker-env)
The reason is because I want to get an image from my computer to be used with minikube. My understanding is that with this command I am in the same context for minikube and docker, so I can access my local images. "Please correct me if I am wrong here".
minikube start
So I get up and running the cluster, and ready to start creating things.
I want to pull the following container:
docker pull nginx/nginx-ingress
Because I want to try an ingress controller to work with my services.
But then I get this weird message:
Using default tag: latest
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at tcp://192.168.99.101:2376. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at tcp://192.168.99.101:2376. Is the docker daemon running?
I run:
docker ps
And no results with a hang out.
I go to another terminal, I run the docker ps and it works like a charm.
Please if someone can bring some light to me of the impact of the command:
eval $(minikube docker-env)
And if you know why in my current Term with minikube running cannot access to my docker machine would help a lot.
minikube starts a dedicated virtual machine as a single-node Kubernetes cluster. If you have other Docker environments (a separate Docker Machine VM, the Docker Toolbox VM, the Docker for Mac or Docker for Windows environments, or a Linux-native Docker) these are separate from the Docker in the VM. You can't share images or containers between these environments.
If you have private images that aren't published to a registry, you'll have to re-docker build them when you switch to the Minikube environment. You otherwise don't specifically have to docker pull things that you're using, when you reference them in a Kubernetes pod spec Kubernetes will pull them for you.

Where does Kubernetes log the output of "docker run"?

I am debugging a Kubernetes cluster which deploys Docker containers.
How can I see the results and exit code of docker run executed by Kubernetes?
Kubernetes does not execute docker run command, it works with an API, usualy via default docker endpoint unix:///var/run/docker.sock

Resources