Kubernetes: debug Running Pods
Fleeting- External reference: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
kubernetes, Debug Running Pods
kubectl debug -it ephemeral-demo –image=busybox:1.28 –target=ephemeral-demo Defaulting debug
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
The –target parameter targets the process namespace of another container. It’s necessary here because kubectl run does not enable process namespace sharing in the pod it creates
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
kubectl debug myapp -it –image=ubuntu –share-processes –copy-to=myapp-debug Defaulting
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
The –share-processes allows the containers in this Pod to see processes from the other containers in the Pod. For more information about how this works, see Share Process Namespace between Containers in a Pod.
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
simulate a crashing application,
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
can use kubectl debug to create a copy of this Pod with the command changed to an interactive
debug myapp -it –copy-to=myapp-debug –container=myapp – sh If you don’t — https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
Now you have an interactive shell that you can use to perform tasks like checking filesystem paths or running the container command manually.
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
change the command of a specific container you must specify its name using –container or kubectl debug will instead create a new container to run the command you specified.
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
may want to change a misbehaving Pod from its normal production container images to an image containing a debugging build or additional utilities.
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
kubectl debug myapp –copy-to=myapp-debug –set-image=*=ubuntu The syntax
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
. *=ubuntu means change the image of all containers to ubuntu
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
If none of these approaches work, you can find the Node on which the Pod is running and create a Pod running on the Node
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
kubectl debug node/mynode -it –image=ubuntu Creating
— https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/