<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: satwik raj</title>
    <description>The latest articles on DEV Community by satwik raj (@s_raj07).</description>
    <link>https://dev.to/s_raj07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2172683%2F398c4362-3b18-484b-9b84-1ae253868bdb.jpg</url>
      <title>DEV Community: satwik raj</title>
      <link>https://dev.to/s_raj07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s_raj07"/>
    <language>en</language>
    <item>
      <title>Kubernetes Debug Container</title>
      <dc:creator>satwik raj</dc:creator>
      <pubDate>Wed, 24 Sep 2025 18:53:30 +0000</pubDate>
      <link>https://dev.to/s_raj07/kubernetes-debug-container-5cdg</link>
      <guid>https://dev.to/s_raj07/kubernetes-debug-container-5cdg</guid>
      <description>&lt;h3&gt;
  
  
  What is the use of the “kubectl debug” command?
&lt;/h3&gt;

&lt;h3&gt;
  
  
  What is a Debug Container?
&lt;/h3&gt;

&lt;p&gt;→ Let’s say there is a situation where a pod is running and it does not have any pre-installed tools like netstat, curl, and ping because of safety issues and to make the container lightweight. Then, in that case, we use a debug container. A debug container is a container that has debugging tools installed inside it, and it is attached to a running container to resolve issues. It is a Container, not a Pod.&lt;/p&gt;

&lt;p&gt;Example:-&lt;br&gt;
The image below shows a Pod, nginx-pod, running in the default namespace. Inside the nginx-pod, a container is running with the name nginx-container, as you can see below.&lt;/p&gt;

&lt;p&gt;Now let's assume nginx-container does not have any debug tools like ping, curl, netstat, and that container encountered some network issue, like the nginx web page is not accessible on the running port.&lt;/p&gt;

&lt;p&gt;So to solve this issue, we have 2 options: -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Either stop the running pod of nginx-pod and container nginx-container and install tools inside it, and then redeploy those pods with the container.&lt;/li&gt;
&lt;li&gt;Run a parallel container where we can test what issue is there through the CLI.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So here we are going to discuss the 2nd scenario.&lt;/p&gt;

&lt;p&gt;In this, we are creating a new container called debug-container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpckdzn0y9pkjt9w0qlga.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpckdzn0y9pkjt9w0qlga.png" alt=" " width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hyajrvsmqi6kp71qwxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hyajrvsmqi6kp71qwxl.png" alt=" " width="800" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here in the above image you can see nginx-pod and nginx-container is running.&lt;/p&gt;

&lt;p&gt;Now we are going to create a new container debug-container in the nginx-pod which will have busybox image inside it. Busybox image container will share the same network namespace with the nginx-container, so we can run any command on the busybox container will be executed as command on the nignx-container.&lt;/p&gt;

&lt;p&gt;Temporary busybox container in the same network and PID namespace as the NGINX container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqsncd2ijbck8a5w7gp9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqsncd2ijbck8a5w7gp9i.png" alt=" " width="800" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, in the below image, as you can see, I ran a command &lt;strong&gt;wget -q0- &lt;a href="http://127.0.0.1:80" rel="noopener noreferrer"&gt;http://127.0.0.1:80&lt;/a&gt;&lt;/strong&gt; → this command gave the output because the nginx and busybox containers share the same network namespace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe01tjdhvsq8akit3kcvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe01tjdhvsq8akit3kcvk.png" alt=" " width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Commands used: -
&lt;/h3&gt;

&lt;p&gt;kubectl run nginx-pod --image=nginx #(in order to name the container use manifest file)&lt;/p&gt;

&lt;p&gt;kubectl get pods # This command is use to list all the pods&lt;/p&gt;

&lt;p&gt;kubectl debug -it nginx-pod --image=busybox # This command is used to create a debug container inside the nginx-pod&lt;/p&gt;

&lt;p&gt;After running the above command a terminal will open of busybox, type the below command&lt;br&gt;
wget -qO- &lt;a href="http://127.0.0.1:80" rel="noopener noreferrer"&gt;http://127.0.0.1:80&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Network namespace (net ns)
&lt;/h3&gt;

&lt;p&gt;All containers in a pod share the same network namespace.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;p&gt;They share the same IP address.&lt;/p&gt;

&lt;p&gt;Ports exposed by one container (like NGINX:80) are accessible from other containers using localhost or pod IP.&lt;/p&gt;

&lt;p&gt;wget -qO- &lt;a href="http://127.0.0.1:80" rel="noopener noreferrer"&gt;http://127.0.0.1:80&lt;/a&gt; from the debug container works, even though NGINX is in a different container.&lt;/p&gt;

&lt;h3&gt;
  
  
  PID namespace (process ID)
&lt;/h3&gt;

&lt;p&gt;By default, each container has its own PID namespace.&lt;/p&gt;

&lt;p&gt;Processes inside NGINX container cannot see processes inside busybox container, and vice versa.&lt;/p&gt;

&lt;p&gt;You can enable shared PID namespace (shareProcessNamespace: true in pod spec) if you want containers to see each other’s processes.&lt;/p&gt;

</description>
      <category>containers</category>
      <category>devops</category>
      <category>kubernetes</category>
    </item>
  </channel>
</rss>
