<p>I am trying to kill a container using client-go and <a href="https://github.com/kubernetes-sigs/e2e-framework/blob/1af0fd64ebd2474f40cbb1a29c8997ed56aba89d/klient/k8s/resources/resources.go#L293" rel="nofollow noreferrer">e2e</a> framework in Golang but not able to do it successfully.
Example of the full implementation can be accessed <a href="https://github.com/kubernetes-sigs/e2e-framework/tree/1af0fd64ebd2474f40cbb1a29c8997ed56aba89d/examples/pod_exec" rel="nofollow noreferrer">e2e</a> apart from this I am using kind image as &quot;kindest/node:v1.26.6&quot;</p>
<p>I have tried the following commands but none using the following pieces of code.</p>
<pre><code>args := []string{&quot;kill&quot;, &quot;1&quot;}
var stdout, stderr bytes.Buffer
err := cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &amp;stdout, &amp;stderr)
</code></pre>
<pre><code>args = []string{&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;'kill&quot;, &quot;1'&quot;}
err = cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &amp;stdout, &amp;stderr)
</code></pre>
<pre><code>args = []string{&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;\&quot;kill 1\&quot;&quot;}
err = cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &amp;stdout, &amp;stderr)
</code></pre>
<p>But all of them are giving error. Some are giving</p>
<p>exec failed: unable to start container process: exec: &quot;kill&quot;: executable file not found in $PATH: unknown&quot;</p>
<p>while some are giving</p>
<p>&quot;command terminated with exit code 127&quot; or
&quot;command terminated with exit code 2&quot;</p>
<p>I have also tried the following and it is working but in this case I have a dependency on kubectl which I want to avoid.</p>
<pre><code>cmdString := fmt.Sprintf(&quot;/c kubectl exec -it %s -n %s -c %s -- bash -c 'kill 1'&quot;, podName, namespace, containerName)
    args := strings.Split(cmdString, &quot; &quot;)
    cmd := exec.Command(&quot;powershell&quot;, args...)
    err := cmd.Run()
</code></pre>

Aryaman
<p>AFAIK it's generally not possible to kill a container from within a container. That's because PID 1 inside container ignores any signal.</p>
<p>From <a href="https://docs.docker.com/engine/reference/run/#foreground" rel="nofollow noreferrer">Docker documentation</a>:</p>
<blockquote>
<p>A process running as PID 1 inside a container is treated specially by
Linux: it ignores any signal with the default action. As a result, the
process will not terminate on SIGINT or SIGTERM unless it is coded to
do so.</p>
</blockquote>
<p>Instead you should rely on <code>kubectl delete pod</code> functionality.</p>
