Pages

Sunday, January 9, 2022

Kubernetes - Ephemeral Container : Copy Of Pod

Sometimes pod configurations do not allow connection for troubleshooting in certain cases. For instance, we can't run the “kubectl exec” command to connect to a container to troubleshoot. For instance, if your container image does not include a shell or if your application crashes on startup. In these situations we can use “kubectl debug” to create a copy of the pod with tools that aid in debugging.

Run the command to create a application container as below,
[root@ec2-3-138-100-101 ~]# kubectl run myapp --image=busybox --restart=Never -- sleep 1d
pod/myapp created

Once the pod is created, create the debug pod and attach to the myapp pod above. In this case we are running this command to create a copy of myapp named myapp-debug that adds a new Ubuntu container for debugging:

[root@ec2-3-138-100-101 ~]# kubectl debug myapp -it --image=ubuntu --share-processes --copy-to=myapp-debug 
Defaulting debug container name to debugger-m897h. If you don't see a command prompt, try pressing enter. 
root@myapp-debug:/#

After a few seconds, the debug pod gets connected to the original myapp pod and we can start the troubleshooting.Process namespace sharing can not be applied to an existing pod, so a copy of the target pod must be created. --share-processes flag enables process namespace sharing when used with --copy-to. These flags copy the existing pod spec definition into a new one with process namespace sharing enabled in the spec.

No comments :

Post a Comment