Bornak
Bornak

Reputation: 87

How to debug a kubernetes cluster?

As the question shows, I have very low knowledge about kubernetes. Following a tutorial, I made a Kubernetes cluster to run a web app on a local server using Minikube. I have applied the kubernetes components and they are running but the Web-Server does not respond to HTTP requests. My problem is that all the system that I have created is like a black box for me and I have literally no idea how to open it and see where the problem is. Can you explain how I can debug such implementaions in a wise way. Thanks.

Upvotes: 0

Views: 238

Answers (3)

Rotem jackoby
Rotem jackoby

Reputation: 22068

I think that we should split the title of the question from what you are asking eventually.

(1) In the title you're asking how to debug a K8s cluster:

You can do it with:

Debugging via a shell on the node

Debugging with an ephemeral debug containe

Or SSH-ing into a container with a command like:

kubectl exec -it -n   -- /bin/sh

(2) You're describing that the web server does not respond to HTTP requests.

In this case, I would start to debug the networking issue from "inside out", from the container to the cluster and then to the outside world.

(a) Start with port-forwarding to the web server and trying see if CURL-ing into the localhost return a response. If you don't have curl in the webserver pod, add an ephemeral container in the same pod with a CURL installed.

(b) If that works, try to launch a new pod inside the cluster with CURL and reffer to the DNS of the K8S service.

(c) If that also work, then you probably have some issue with your ingress definition. Try to recreate it, and check for logs in the ingress controller. Try also to see if you can hit the load balancer DNS/IP directly with the relevant header (probably HOST).

(d) If you reached this point, then you have probably an issue with your DNS.

(e) Try to lauch a mock web server and see if you can reach it or maybe it is blocked by VPN access or something.

Upvotes: 1

Jason Farmer
Jason Farmer

Reputation: 67

kubectl get pods

will show you all your pods and their status. A quick check to make sure that all is at least running.

If there are pods that are unhealthy, then

kubectl describe pod <pod name>

will give some more information.. eg image not found etc

kubectl log <pod name> --all

is often the next step , use -f to follow the logs as you exercise your api.

It is possible to link up images running in a pod with most ide debuggers, but instructions will differ depending on language and ide used...

Upvotes: 2

Jonathan Allen Grant
Jonathan Allen Grant

Reputation: 3648

use a tool like https://github.com/kubernetes/kubernetes-dashboard

You can install kubectl and kubernetes-dashboard in a k8s cluster (https://kubernetes.io/docs/tasks/tools/install-kubectl/), and then use the kubectl command to query information about a pod or container, or use the kubernetes-dashboard web UI to query information about the cluster. For more information, please refer to https://kubernetes.io/

Upvotes: 2

Related Questions