0

For some troubleshooting, I want to connect to my coredns pod. Is this possible?

$ microk8s kubectl get pod --namespace kube-system
NAME                                      READY   STATUS    RESTARTS   AGE
hostpath-provisioner-5c65fbdb4f-w6fmn     1/1     Running   1          7d22h
coredns-7f9c69c78c-mcdl5                  1/1     Running   1          7d23h
calico-kube-controllers-f7868dd95-hbmjt   1/1     Running   1          7d23h
calico-node-rtprh                         1/1     Running   1          7d23h

When I try, I get the following error msg:

$ microk8s kubectl --namespace kube-system  exec --stdin --tty coredns-7f9c69c78c-mcdl5 -- /bin/bash
error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "f1d08ed8494894d1281cd5c43dee36119225ab1ba414def333659538e5edc561": OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Thagor
  • 820
  • 2
  • 10
  • 33
  • Coredns Pod have no shell, I think. Check this to kind-of exec with a sidecar: https://stackoverflow.com/questions/60666170/how-to-get-into-coredns-pod-kuberrnetes – AndD Sep 30 '21 at 06:29

1 Answers1

0

User AndD has good mentioned in the comment:

Coredns Pod have no shell, I think. Check this to kind-of exec with a sidecar: How to get into CoreDNS pod kuberrnetes?

Yes. This image has no shell. You can read more about this situation in this thread:

The image does not contain a shell. Logs can be viewed with kubectl.

You have asked:

I want to connect to my coredns pod, is this possible?

Theoretically yes, but you need to make a workaroud with docker. It is described in this answer: In short, do this to find a node where a coredns pod is running:

kubectl -n kube-system get po -o wide | grep coredns

ssh to one of those nodes, then:

docker ps -a | grep coredns

Copy the Container ID to clipboard and run:

ID=<paste ID here>
docker run -it --net=container:$ID --pid=container:$ID --volumes-from=$ID alpine sh

You will now be inside the "sidecar" container and can poke around. I.e.

cat /etc/coredns/Corefile

Additionally, you can check the logs, with kubectl. See also official documentation about DNS debugging.

Mikołaj Głodziak
  • 4,775
  • 7
  • 28
  • I will only have time on Monday to try it out. But will I be able to do something like `ping` as if it comes from the `coredns pod`? – Thagor Oct 01 '21 at 10:50
  • You have to do exactly as I described in the answer, or check the logs. – Mikołaj Głodziak Oct 04 '21 at 07:11
  • Okay I tried the way described there, but I can't ssh into one of the nodes because in microk8s everything runs on the main host. So jumped straight to step number 3 but here docker throws an error: `docker: Error response from daemon: No such container: coredns-7f9c69c78c-mcdl5.` – Thagor Oct 05 '21 at 09:05
  • The answer is correct because to find the container you need to login to node, not host. – Mikołaj Głodziak Oct 06 '21 at 07:12
  • I kind of solved the issues that I tried to solve, so this is no longer necessary to do for me. – Thagor Oct 12 '21 at 11:25