<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>Your first attempt looks okay at first glance, although I don't see an <code>ExecInPod</code> method in the <code>client-go</code> package. Because you haven't provided a reproducible example I haven't tried building and running your code.</p>
<p>There's no guarantee that the <code>kill</code> command is available inside a particular container. If you update your question to include details about your deployment manifests -- so we can see what image you're using -- we can provide you with a better answer.</p>
<hr />
<p>Your second two examples are simply invalid:</p>
<h2>1</h2>
<pre><code>args = []string{&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;'kill&quot;, &quot;1'&quot;}
</code></pre>
<p>Here you're trying to run the command <code>'kill</code>, which doesn't exist. You need to pass a single string to <code>sh -c</code>, so this would need to look like:</p>
<pre><code>args = []string{&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;kill 1&quot;}
</code></pre>
<p>The argument to <code>-c</code> is the script to run; any additional parameters are provided as arguments to that script (so in this example, the shell would see <code>1'</code> in <code>$0</code>).</p>
<p>You could avoid the shell altogether and just run:</p>
<pre><code>args = []string{&quot;kill&quot;, &quot;1&quot;}
</code></pre>
<p>But again, both of these solutions require that the target container have the <code>kill</code> command available.</p>
<h2>2</h2>
<pre><code>args = []string{&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;\&quot;kill 1\&quot;&quot;}
</code></pre>
<p>Here you're trying to run the command <code>&quot;kill 1&quot;</code>, which against doesn't exist; if you were to run this from the command line you would see:</p>
<pre><code>$ &quot;kill 1&quot;
bash: kill 1: command not found...
</code></pre>
<p>The correct syntax would be as shown in the previous section.</p>
