how to take a problematic pod offline to troubleshoot

2/14/2020

HI I know there's a way i can pull out a problematic node out of loadbalancer to troubleshoot. But how can i pull a pod out of service to troubleshoot. What tools or command can do it ?

-- Gabriel Wu
kubectl
kubernetes

2 Answers

2/14/2020

Change its labels so they no longer matches the selector: in the Service; we used to do that all the time. You can even put it back into rotation if you want to test a hypothesis. I don't recall exactly how quickly it takes effect, but I would guess "real quick" is a good approximation. :-)

## for example:
$ kubectl label pod $the_pod -app.kubernetes.io/name
## or, change it to non-matching
$ kubectl label pod $the_pod app.kubernetes.io/name=i-am-debugging-this-pod
-- mdaniel
Source: StackOverflow

2/14/2020

As mentioned in Oreilly's "Kubernetes recipes: Maintenance and troubleshooting" page here

Removing a Pod from a Service

Problem

You have a well-defined service (see not available) backed by several pods. But one of the pods is misbehaving, and you would like to take it out of the list of endpoints to examine it at a later time.

Solution

Relabel the pod using the --overwrite option—this will allow you to change the value of the run label on the pod. By overwriting this label, you can ensure that it will not be selected by the service selector (not available) and will be removed from the list of endpoints. At the same time, the replica set watching over your pods will see that a pod has disappeared and will start a new replica.

To see this in action, start with a straightforward deployment generated with kubectl run (see not available):

For commands, check the recipes page mentioned above. There is also a section talking about "Debugging Pods" which will be helpful

-- Vidyasagar Machupalli
Source: StackOverflow