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:/#
๐ฉ 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
Latchu@DevOps | Sciencx (2025-11-09T05:50:19+00:00) โ Scenario #3: Debugging a Running Container in Kubernetes. Retrieved from https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
