โœ… Scenario #3: Debugging a Running Container in Kubernetes

๐ŸŸฉ 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:


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » โœ… Scenario #3: Debugging a Running Container in Kubernetes." Latchu@DevOps | Sciencx - Sunday November 9, 2025, https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/
HARVARD
Latchu@DevOps | Sciencx Sunday November 9, 2025 » โœ… Scenario #3: Debugging a Running Container in Kubernetes., viewed ,<https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/>
VANCOUVER
Latchu@DevOps | Sciencx - » โœ… Scenario #3: Debugging a Running Container in Kubernetes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/
CHICAGO
" » โœ… Scenario #3: Debugging a Running Container in Kubernetes." Latchu@DevOps | Sciencx - Accessed . https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/
IEEE
" » โœ… Scenario #3: Debugging a Running Container in Kubernetes." Latchu@DevOps | Sciencx [Online]. Available: https://www.scien.cx/2025/11/09/%e2%9c%85-scenario-3-debugging-a-running-container-in-kubernetes/. [Accessed: ]
rf:citation
» โœ… Scenario #3: Debugging a Running Container in Kubernetes | Latchu@DevOps | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.