Lessandro

A website containing something I’ve been working on

19 Oct 2021

Debugging Kubernetes cluster pt.1

I’m pretty sure you’ve debugged a lot of systems, and Kubernetes isn’t different. In this post, I’ll show some commands you can run to help you with this debugging.

This troubleshooting will focus on cluster operations. This will help you understand a cluster and make sure the core functionality, running pods, is available.

Debugging Kubernetes cluster — part2

Commands

a. kubectl version

This command will show us the current version running. It will help us when searching for errors and reading changelogs.

Image alt

This command will show us the current version running. It will help us when searching for errors and reading changelogs.

b. kubectl cluster-info

Image alt

This command will show where the cluster is running and if the CoreDNS is running.

As we can see from the command output, we’re running Kubernetes on a local (VirtualBox) machine and not on the cloud.

c. kubectl get componentstatus

Image alt

This command will show if your scheduler, controller-manager and etcd are healthy.

As you can see the componentstatus command is deprecated in the CLI, but not yet removed.

Also, you can use the below command.

kubectl get --raw '/healthz?verbose'

Image alt

This command won’t show scheduler or controller-manager output, but it shows a lot of additional information.

d. kubectl api-resources -o wide -sort-by name

Image alt

This command will show what verbs are available, and it’ll help narrow down where you should look for errors. Maybe your workloads might be using an old alpha or beta API version, but the cluster may only use v1 or apps/v1.

e. kubectl get events -A

Image alt

This command will show what was happening before and after things broke. With this output, you should focus on the type of output, reason and object.

f. kubectl get nodes -o wide

Image alt

This command can bring a lot of information about the node(s) and master(s), such as INTERNAL-IP, Operation System version, Age and Container-Runtime version

This information will help in a potential problem and know where to look deeper at logs.

g. kubectl get pods -A -o wide

Image alt

This command will show all pods running in all namespaces(-A parameter). Using the output, you can verify any error/failure.

h. kubectl run pod-test --image=alpine -command -/bin/sleep 1d

This command will create a pod named pod-test. This can show you if the pod’s creation is working as expected. Also, you can use the command kubectl describe po pod-test to look at the events of this pod.

Image alt

kubectl describe po pod-test

Image alt

Hopefully, these commands can help you during the Kubernetes troubleshooting process.