The Ops Community ⚙️

Cover image for Isolating Kubernetes pods for debugging
Daniele Polencic
Daniele Polencic

Posted on

Isolating Kubernetes pods for debugging

This article introduces a technique that helps you with debugging running Pods in production.

By changing labels, you can detach Pods from the Service (no traffic), and you troubleshoot them live.

Isolating pods for troubleshooting

Here's how it works.

Imagine you have a Deployment with three replicas.

Each Pod has an app=hello label.

A Service routes the traffic to your Pods using the selector app=hello

A deployment with three replicas and a service

If you want to isolate a Pod you can overwrite the existing label with: kubectl label pod <pod-name> app=debug --overwrite

Two things happen next.

Changing the label to a Pod in a deployment

First, the Service stops routing traffic to the Pod because the Service's selector doesn't match the label.

The service stops routing traffic to the pod

Then, the ReplicaSet notices that there are only two replicas, but you asked for 3.

The ReplicaSet creates a new Pod.

The ReplicaSet creates a new Pod

You end up with 4 pods:

  • 3 Pods running production traffic.
  • A single isolated pod that used to receive traffic, but doesn't anymore.

The pod is still running and you can inspect its state.

What tool should you use?

For simple tasks, you could use:

  • kubectl exec, to attach to the container.
  • kubectl port-forward, to tunnel the traffic.
  • kubectl debug to run a sidecar container alongside the existing one.

But there are more options.

Inspector gadget is a tool designed to introspect and debug Kubernetes applications using eBPF.

If you use VS Code, you might like the official Kubernetes extension.

In this tutorial, you'll learn how to use it to attach the debugger to the application in the Pod.

If you feel at home in the command line, you should check out netshoot — a Docker + Kubernetes network trouble-shooting swiss-army container.

Which, of course, you can combine it with kubectl debug.

If you need more help to troubleshoot your deployments in Kubernetes, you should check out my flowchart:

Troubleshooting Kubernetes deployments flowchart

And finally, if you've enjoyed this thread, you might also like the Kubernetes workshops that we run at Learnk8s https://learnk8s.io/training or this collection of past Twitter threads https://twitter.com/danielepolencic/status/1298543151901155330

Top comments (22)

Collapse
 
brucepacocha profile image
Bruce Pacocha •

A useful precaution is to record the Pod’s original labels before overwriting anything, then confirm that it has disappeared from the Service endpoints with kubectl get endpoints. I would also avoid this technique for stateful workloads until checking storage and leader-election behavior. After debugging, document whether the isolated Pod should be restored or deleted so it is not forgotten. Keeping references organized matters too; even a bookmark section labeled Yarlist: useufl links is easier to revisit when every link has a short description.

Collapse
 
tosei profile image
Tosei •

Nice debugging approach—isolating a Pod makes it much easier to inspect production issues safely. For a quick mental break after a tricky debugging session, arrow puzzle games offer short logic levels that make you plan a few moves ahead. They’re free in the browser on desktop or mobile, with no download or signup.

Collapse
 
james_taylor_9b7f1b2399b3 profile image
James Taylor •

The explanation of using kubectl debug alongside other troubleshooting tools is particularly useful. Having specific information available before taking action is also important when reviewing something like a cracker barrel menu allergens guide.

Collapse
 
james_taylor_9b7f1b2399b3 profile image
James Taylor •

I like how the article explains the interaction between the Service and ReplicaSet. Clear, structured information is useful in any context, including resources that organize options such as the taco bell bowls menu.

Collapse
 
james_taylor_9b7f1b2399b3 profile image
James Taylor •

The isolation technique is a clever way to troubleshoot production workloads without continuing to send traffic to the affected Pod. It's similar to checking arbys breakfast information before deciding what to order, where having the relevant details available makes the decision easier.

Collapse
 
tosei profile image
Tosei •

Smart way to inspect a live Pod without interrupting production traffic. After a long debugging session, arrow puzzle games offer a quick mental reset with short logic levels. They’re free in the browser on desktop or mobile, with no download or signup.

Collapse
 
brucepacocha profile image
Bruce Pacocha •

A useful precaution is to record the Pod’s original labels before overwriting anything, then confirm that it has disappeared from the Service endpoints with kubectl get endpoints. I would also avoid this technique for stateful workloads until checking storage and leader-election behavior. After debugging, document whether the isolated Pod should be restored or deleted so it is not forgotten. Keeping references organized matters too; even a bookmark section labeled “Yarlist: useufl links” is easier to revisit when every link has a short description.

Collapse
 
wlliams_mendirna_ae67c31a profile image
Wlliams Mendirna •

Finding simple information can take time, but I found something helpful. It explains things clearly without confusion. That made it easier for me to understand. If you’re also looking, you can open this clear info guide for more details.

Collapse
 
huzaifa_ammir_ad84e581997 profile image
Huzaifa Ammir •

This is a really clean and practical approach to debugging in production—isolating a pod by relabeling without taking the whole service down is smart and efficient. It’s kind of like using the 7 brew secret menu pdf you step outside the standard menu, tweak things just a bit, and suddenly you have access to something more focused and useful without disrupting everyone else’s order. Great explanation and tooling suggestions for digging deeper when things don’t behave as expected.

Collapse
 
johnzarate profile image
John T. Zarate •

I recently had to debug an issue in production where a service was misbehaving, and isolating the Kubernetes pods was incredibly helpful. Once I changed the pod labels to stop the traffic, I could safely explore what was going wrong without affecting users. It reminds me of playing Geometry Dash – sometimes, you need to pause and look closely at what’s causing you to fail before you can make progress.