Sometimes we may need to connect to an existing Kubernetes pod to perform simple tasks like executing simple commands,
checking
connectivity from pod to other networks; for such activities the below command really helps Developers
# Authenticate and switch to the targeted Kubernetes contextdexctl--user<username>
kubectlconfiguse-context<targetedcontext>
# List all namespaces in the current contextkubectlgetnamespaces
# List all pods in a specific namespacekubectlgetpods--namespace<namespace>
# Connect to a pod and open an interactive bash terminal for debuggingkubectlexec--stdin--tty--namespace<namespace><pod-name>--/bin/bash
# Execute a single command (e.g., check the current date) inside a podkubectlexec-it--namespace<namespace><pod-name>--date
Debugging Pod
Sometimes we may need to connect to a Kubernetes pod and perform simple tasks without modifying its existing
container like executing simple commands, checking connectivity from pod to other networks; for such activities, the
below debug command really helps Developers
Sometimes we might save file in Kubernetes secrets e.g. client certificate, ssh keys, any encrypted files
We might sometimes need such files on our local machine for debugging or local development
These files might not be copied directly or downloadable directly from the Kubernetes UI.
In this case, the below command really helps to download as it is.
kubectl--cluster=<clustername>-n<namespace>getsecrets"<name of the entry>"-ojson|jq-r'.data."<key>"'|base64-d><desiredtargetfilenamee.g.localhost.p12>
Port Forwarding
Sometimes we might need to debug a pod on Kubernetes, for example, testing configurations.
Sometimes our local application might want to connect to a particular Kubernetes pod, in these
cases Port Forwarding really helpful.