Port forward service vs pod
bypassing the Service to hit a Pod directly is a common "power move."
Here is why you would do it:
1. Debugging a "Broken" Service¶
If you try to access your app through the Service and get a 503 Service Unavailable or a timeout, you need to find out where the chain is broken.
-
By port-forwarding directly to the Pod, you can verify if the Nginx container itself is actually running and serving content.
-
If the Pod works but the Service doesn't, you know the problem is in your Service Selector or the Port Mapping, not the application code.
2. Accessing a Specific Pod in a ReplicaSet¶
Imagine you have 10 Nginx Pods behind one Service. If one of those Pods is behaving strangely (maybe it has a corrupted cache or a specific log error), hitting the Service will use load balancing—meaning you only have a 1-in-10 chance of hitting the "bad" Pod.
- Port-forwarding to that specific Pod name allows you to "pin" your connection to the exact instance you want to inspect.
3. Handling "Headless" Scenarios or Database Tweaks¶
If you are running a database like MySQL or MongoDB as a StatefulSet, you might need to connect to the Primary node specifically to run a migration or a manual query.
- Instead of messing with Service routing, you just port-forward to
pod/mysql-0to get a direct line to the database engine.