Skip to content
subuilds.dev

← logbuild #26 passed0ed38ec

Debugging Kubernetes by Symptom: The Kubectl Commands I Reach For

A kubectl reference sorted by symptom, from real homelab debugging. It covers pods with the wrong CPU architecture, app 500s with healthy pods, ingress 404s, cert-manager challenges, and log patterns that show the cause.

· 14 min read

When something breaks in a Kubernetes cluster, you can fix it in 5 minutes or in 5 hours. The difference is knowing which command to run first. Hundreds of commands exist. You need the one that fits the symptom you see.

This is the cheat sheet I built in one afternoon of debugging GitLab on K3s on ARM64. It is sorted by symptom. I used every command and log signature here to find a real bug. A log signature is a pattern in the output that points to one cause. Learn the patterns, not the flags.

In Simple Words#

The problem
Something in your Kubernetes cluster is broken. kubectl has hundreds of commands. You do not know which one to run first.
The root cause
Each symptom has a different cause, and the clue is in a different place. Sometimes Kubernetes shows it. Sometimes only the app’s own log shows it.
The solution
Always start with get, then describe, then logs --previous. Then go to the section that matches what you see: a pod that won’t start, a 500 error, a 404, a missing certificate, or a broken tunnel.
Think of it like this
A doctor does not run every test on every patient. The doctor first asks where it hurts, and then picks the right test. This post tells you which test fits which pain.

What You’ll Cover#

  1. The default workflow: get → describe → logs
  2. When a pod won’t start (and the empty-log architecture trap)
  3. When pods look healthy but the app returns 500
  4. When the ingress returns 404 for your hostname
  5. When cert-manager won’t issue a certificate
  6. When external access (load balancer or tunnel) is broken
  7. Operational commands: scale, restart, replay
  8. Log signatures and what they really mean

The Default Workflow: get → describe → logs#

Almost every Kubernetes debugging session starts with the same three commands, in this order. If you skip one, you lose time.

bash
# 1. What's broken?
kubectl get pods -n gitlab

# 2. Why is it broken? (events, image, conditions, mounts)
kubectl describe pod <pod-name> -n gitlab

# 3. What did it say before it died?
kubectl logs <pod-name> -n gitlab --previous

get shows the status. describe shows the why. The Events at the bottom of its output tell you about image pulls, scheduling failures, OOM (out of memory) kills, probe failures and volume mounts. logs --previous is very important for crash loops. The current container has not run yet. The failure is in the previous one.

Here are the three commands on a real bug from this post, a Job that could not start:

  1. A Job pod keeps crashing. Run three commands, always in this order.
  2. kubectl get pods shows the status: CrashLoopBackOff.
  3. kubectl describe pod shows why: Exit Code 255, and the container started and finished in the same second.
  4. kubectl logs --previous shows nothing. The process never wrote a log line.
  5. The three clues together mean an architecture mismatch: an amd64-only image on an ARM64 node.
  6. Change the image to a multi-arch tag and run the Job again. The pod ends as Completed.
6 / 6

When a Pod Won’t Start#

kubectl get pods shows you a status. Each status points to a different kind of problem.

Status First command to run Likely cause
Pending kubectl describe pod (look at Events) No node fits: resources, taints, PVC not bound
ImagePullBackOff / ErrImagePull kubectl describe pod (look at Image:) Wrong image name/tag, registry auth missing, network
CrashLoopBackOff (with logs) kubectl logs --previous App startup error. Read the log
CrashLoopBackOff (empty logs) kubectl describe pod (look at Exit Code + Started/Finished) Architecture mismatch, missing binary, exec failure
0/2 Running kubectl describe pod (look at Containers + Conditions) One container in the pod is not Ready: probe failing, init still running

The hardest one to find is the CrashLoopBackOff with empty logs. The normal next step (logs) gives you nothing. The clue is in describe.

The Empty-Log Arch Trap#

Here is the real output from a real bug. A bucket-create Job was stuck in a loop:

text
Containers:
  minio-mc:
    Image:         registry.gitlab.com/.../minio/mc:RELEASE.2018-07-13T00-53-22Z
    State:         Terminated
      Reason:      Error
      Exit Code:   255
      Started:     Wed, 20 May 2026 12:34:50 +0700
      Finished:    Wed, 20 May 2026 12:34:50 +0700
    Last State:    Terminated
      Reason:      Error
      Exit Code:   255
    Restart Count: 3

Three signs together tell you what happened:

  • Exit Code 255: a general error code, often used for “exec failed at the kernel level”
  • Started and Finished in the same second: the binary had no time to do anything
  • kubectl logs --previous returns unable to retrieve container logs: there are no logs, because the process never wrote anything to stdout

This is the classic signature of an architecture mismatch. Usually it is an amd64-only image that runs on an ARM64 node. The image is built for one CPU type, and the node has another. The kernel rejects the ELF binary (the program file) before any code runs. The image tag from 2018 is a second strong clue. That is older than the time when multi-arch manifests became common.

The fix is to change the image to a multi-arch tag and make the Job run again:

bash
# After patching the chart values:
kubectl -n gitlab delete job -l component=create-buckets
kubectl -n gitlab get pods -l component=create-buckets -w
# expect: Completed (not CrashLoopBackOff)

When Pods Look Healthy But the App Returns 500#

This is the hardest kind of problem, because Kubernetes itself reports nothing wrong. Pods are 2/2 Running. Probes are green. The Service routes traffic. But the user sees a 500 page.

Kubernetes can’t help here. The failure is inside the application. You need to read the application logs. Often you also need to run code inside the app.

Step 1: Filter the logs for errors#

bash
# Tail the container's stdout/stderr stream (works for any pod)
kubectl logs deploy/gitlab-webservice-default -c webservice -n gitlab \
  --tail=500 | grep -iE "error|exception|fatal|500" | tail -40

The -c webservice flag selects one container in a pod that has several. Without it, kubectl picks the first container. That may not be the one with the error.

Step 2: Read the app’s own log files#

Many real apps write to log files inside the container, not to stdout. Examples are GitLab, Rails apps in general, and any app with structured logging to a file. To read these files, you must run a command inside the container:

bash
# Read the actual Rails production.log inside the running container
kubectl exec deploy/gitlab-webservice-default -c webservice -n gitlab -- \
  tail -n 200 /var/log/gitlab/production.log

You get a real backtrace that points at the broken line in the app. This tells you more than the access log. The access log shows that a request returned 500. The production.log shows why.

Step 3: Reproduce in a console inside the cluster#

For Rails apps, the cleanest way is to run the failing code directly:

bash
kubectl exec -it deploy/gitlab-toolbox -n gitlab -- gitlab-rails runner '
  begin
    u = Users::Internal.duo_code_review_bot
    puts "OK: #{u.inspect}"
  rescue => e
    puts "FAILED: #{e.class}: #{e.message}"
    puts e.record.errors.full_messages if e.respond_to?(:record)
  end
'

This skips the web layer fully. If the call fails in the console too, the bug is in the app code or the database. If it works in the console but not over HTTP, the bug is in middleware, authentication, or session state.

When the Ingress Returns 404 for Your Hostname#

You configured a tunnel or load balancer. The certificate is valid and the pods are healthy. But the URL returns 404 from the cluster’s ingress controller. The ingress controller is the part that sends each incoming request to the right service. The cause is almost always a Host header that does not match.

bash
# What hostnames does the ingress controller actually know about?
kubectl get ingress -n gitlab
text
NAME              CLASS     HOSTS                  ADDRESS  PORTS  AGE
gitlab-webservice traefik   gitlab.example.com     ...      80,443 5h

The HOSTS column shows what the ingress controller really knows. Say the tunnel or LB sends Host: gitlabee.example.com, but the Ingress is configured for gitlab.example.com. Then you get a 404, because the ingress controller has no rule that matches.

Test it from the node, bypassing DNS and TLS#

The surest test is a curl straight to the ingress controller, where you set the Host header by hand:

bash
# This 404s when the Ingress doesn't know the hostname
curl -ksI -H "Host: gitlabee.example.com" https://127.0.0.1

# This succeeds when you use the correct hostname
curl -ksI -H "Host: gitlab.example.com"   https://127.0.0.1

If the second one returns 200/302 and the first one returns 404, the network is fine. The upstream (tunnel, load balancer, external DNS) sends a hostname that the ingress controller doesn’t know. Fix the chart values or the Ingress, not the network.

When cert-manager Won’t Issue a Certificate#

bash
# Top-level status
kubectl get certificate -n gitlab
# NAME         READY   SECRET       AGE
# gitlab-tls   False   gitlab-tls   3m

# The full chain — Certificate → CertificateRequest → Order → Challenge
kubectl describe certificate gitlab-tls -n gitlab
kubectl describe certificaterequest -n gitlab
kubectl describe challenge -A

If READY=False stays for more than a few minutes, something is wrong in the chain. The chain goes Certificate → CertificateRequest → Order → Challenge. The failure shows up at the lowest level, usually the Challenge:

text
Status:
  Reason:  Waiting for DNS-01 challenge propagation: NS ns1.example.com returned
           REFUSED for _acme-challenge.gitlab.example.com.

That error text tells you exactly what is wrong. In this case the DNS-01 solver can’t write the TXT record. The API token’s zone scope doesn’t include the target domain.

When External Access Is Broken (Tunnel or LB)#

If you use Cloudflare Tunnel (or another connector that links the cluster to the outside), the check on the pod side is simple:

bash
# Tail the cloudflared logs
kubectl -n gitlab logs deploy/cloudflared --tail=50
# expect: "Registered tunnel connection" lines, no repeating errors

If the tunnel pod is in CrashLoopBackOff, the usual causes are:

  • A wrong tunnel UUID in the ConfigMap
  • The name or key of the credentials secret does not match
  • The tunnel was deleted in the upstream dashboard, but the credentials are still there

The logs tell you which one.

Sometimes only the external URL fails. Then find out which part is broken: the tunnel or the cluster. Scale the tunnel to zero and see if the LAN path still works:

bash
# Drain the tunnel
kubectl -n gitlab scale deploy/cloudflared --replicas=0

# Test direct ingress from the LAN (DNS pointed at the node IP)
curl -kI https://gitlab.example.com

# Bring it back
kubectl -n gitlab scale deploy/cloudflared --replicas=1

If the LAN path works with cloudflared at zero replicas, the cluster is fine. Only the tunnel is broken. Look there.

Operational Commands: Scale, Restart, Replay#

You will type these 100 times. It is worth it to remember them.

bash
# Restart all pods in a Deployment, picking up new ConfigMap / Secret values
kubectl -n gitlab rollout restart deploy/gitlab-webservice-default

# Drain a Deployment for testing (and bring it back)
kubectl -n gitlab scale deploy/cloudflared --replicas=0
kubectl -n gitlab scale deploy/cloudflared --replicas=1

# Re-run a Job that succeeded once (delete the Job; the chart's hook will recreate it)
kubectl -n gitlab delete job <job-name>

# Watch status changes live
kubectl -n gitlab get pods -w

# Show resource usage (requires metrics-server)
kubectl top pods -n gitlab
kubectl top nodes

Reading Secrets Inline#

You will do this all the time when you set up a chart for the first time:

bash
# Decode a Secret into something readable
kubectl -n gitlab get secret gitlab-gitlab-initial-root-password \
  -o jsonpath='{.data.password}' | base64 -d ; echo

# Create one from a literal (e.g. for an Initial root password)
kubectl create secret generic gitlab-initial-root-password \
  --namespace gitlab \
  --from-literal=password='ChangeMe-Strong-Password!'

# Create one from a file (e.g. cloudflared tunnel credentials)
kubectl -n gitlab create secret generic cloudflared-credentials \
  --from-file=credentials.json=$HOME/.cloudflared/<tunnel-uuid>.json

Why the ; echo at the end of the decode? The base64-decoded output has no newline at the end. Without ; echo, the next shell prompt can hide the last line of the secret.

Read a ConfigMap to See What the Chart Built#

Sometimes a Helm chart produces something you didn’t expect: a wrong hostname, a missing flag, a strange env var. Then read the final ConfigMap directly:

bash
kubectl -n gitlab get cm gitlab-webservice -o yaml
kubectl -n gitlab get cm cloudflared-config -o yaml

The ConfigMap is what the container really reads at startup. If the chart values look correct but the behavior is wrong, the ConfigMap shows which side has the bug.

Log Signatures and What They Actually Mean#

These patterns appear again and again in homelab K8s debugging:

Signature Likely cause
Exit 255 + Started == Finished + empty logs Architecture mismatch (amd64 image on ARM64, or the other way around)
exec format error in pod events Same as above, but here the kernel says it clearly
OOMKilled in kubectl describe pod Container used more than its memory limit (raise the limit or fix the leak)
Liveness probe failed repeatedly App slow to start; raise initialDelaySeconds or fix the probe path
BackOff pulling image Image name typo, missing imagePullSecret, or registry not reachable
MountVolume.SetUp failed PVC not bound, or a Secret/ConfigMap reference doesn’t exist
FailedScheduling: insufficient memory Node doesn’t have room for the requested resources
403 SignatureDoesNotMatch (in S3-style API logs) Two users of the same store have different credentials
App returns 500 but kubectl get pods shows 2/2 Running Not a Kubernetes problem. Read the app log inside the container

Quick Reference#

bash
# Discovery
kubectl get pods -n NS
kubectl get pods -n NS -w
kubectl get pods -n NS -l app=foo

# Diagnosis
kubectl describe pod POD -n NS
kubectl logs POD -n NS --previous
kubectl logs deploy/DEPLOY -c CONTAINER -n NS --tail=200

# Exec / introspection
kubectl exec -it POD -n NS -- bash
kubectl exec DEPLOY -n NS -- tail -n 200 /var/log/app/prod.log

# Operations
kubectl rollout restart deploy/DEPLOY -n NS
kubectl scale deploy/DEPLOY -n NS --replicas=N
kubectl delete job JOB -n NS

# Networking
kubectl get ingress -n NS

If you remember only one thing, remember the first three: get then describe then logs --previous. Almost every debugging session in this post started there.

Next Steps#