✅ Scenario #3: Debugging a Running Container in Kubernetes



This content originally appeared on DEV Community and was authored by Latchu@DevOps

🟩 Step 1 — Create an NGINX Pod

Create a file named nginx-debug.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-debug
  labels:
    app: nginx-debug
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80

Apply it:

kubectl apply -f nginx-debug.yaml

🟩 Step 2 — Verify Pod Is Running

Check Pod status:

kubectl get pods -o wide

Expected output:

NAME          READY   STATUS    RESTARTS   AGE   IP
nginx-debug   1/1     Running   0          5s    10.x.x.x

🟩 Step 3 — Wait Until Pod Is Ready (Recommended)

This avoids connection errors:

kubectl wait --for=condition=Ready pod/nginx-debug --timeout=60s

🟩 Step 4 — Exec Into the NGINX Container

Try bash first; if not available, fall back to sh:

kubectl exec -it nginx-debug -- /bin/bash 2>/dev/null || \
kubectl exec -it nginx-debug -- /bin/sh

Now you should be inside the container:

root@nginx-debug:/#

1

🟩 Step 5 — Perform Debugging Inside the Container

Below is a list of useful real-time debugging actions.

🔎 5.1 Check running processes

ps aux

You will see nginx master + worker processes.

🔎 5.2 Check NGINX config

cat /etc/nginx/nginx.conf

Or check site configs:

ls -R /etc/nginx

🔎 5.3 Test local NGINX web server

apt update 2>/dev/null || true
apt install curl -y 2>/dev/null || true
curl http://localhost

You should see the default NGINX welcome page HTML.

🔎 5.4 Check environment variables

env

🔎 5.5 Inspect container filesystem

ls -l /
ls -l /usr/share/nginx/html

🔎 5.6 Check network connectivity from inside the container

ping -c 3 google.com

Check internet DNS from the container:

nslookup google.com

🔎 5.7 View logs (inside container)

Check access and error logs:

ls -l /var/log/nginx
cat /var/log/nginx/access.log
cat /var/log/nginx/error.log

🔎 5.8 Inspect listening ports

netstat -tulnp

You should see:

tcp 0.0.0.0:80 → nginx

🟩 Step 6 — Exit the Container

exit

🟩 Step 7 — Clean Up (Optional)

kubectl delete pod nginx-debug

🌟 Thanks for reading! If this post added value, a like ❤, follow, or share would encourage me to keep creating more content.

— Latchu | Senior DevOps & Cloud Engineer

☁ AWS | GCP | ☸ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions


This content originally appeared on DEV Community and was authored by Latchu@DevOps