<p>You need to provide commands in list. Something like below:</p>
<pre><code>V1ExecAction execommand = new V1ExecAction(&quot;curl&quot;, &quot;http://localhost:5001/checkhealth/&quot;);
</code></pre>
<p>Since you already an endpoint for healthcheck, you should use <code>V1HTTPGetAction</code> instead of <code>V1ExecAction</code>. In your case, <code>V1ExecAction</code> will always give exit status as <code>0</code> and thus liveliness check won't be correct if your app throws any errors or down.</p>

CC BY-SA 4.0
2021-06-07T15:01:21.553Z
the same thing if I have to do using V1HTTPGetAction, then bellow is sufficient ? :
```V1HTTPGetAction execommand = new V1HTTPGetAction("http://localhost:5001/checkhealth/");
livnessconfig = new V1Probe { HttpGet= execommand, InitialDelaySeconds = 10, PeriodSeconds = 10, TimeoutSeconds = 5, FailureThreshold = 3 };
```
solveit
CC BY-SA 4.0
2021-06-03T18:39:33.447Z
2021-06-03T18:39:33.447Z
Samit
<p>I am trying to implement liveness probe through C# code (.Net core framework). I simply want to run a curl command inside container <a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/probe/exec-liveness.yaml" rel="nofollow noreferrer">like this</a> .  Below is the code snippet using <a href="https://github.com/kubernetes-client/csharp/blob/225bb1f59b650e6849858f52608ef917b2484ddb/src/KubernetesClient/generated/Models/V1Probe.cs#L66" rel="nofollow noreferrer">kubernetesClient</a>:</p>
<pre><code>IList&lt;string&gt; command = new List&lt;string&gt;();
V1Probe livnessconfig = null;
command.Add(&quot;curl http://localhost:5001/checkhealth/&quot;);
V1ExecAction execommand = new V1ExecAction(command);
livnessconfig = new V1Probe { Exec = execommand, InitialDelaySeconds = 10, PeriodSeconds = 10, TimeoutSeconds = 5, FailureThreshold = 3 };
</code></pre>
<p><strong>But getting this error in pod description:</strong></p>
<blockquote>
<p>Liveness probe errored: rpc error: code = Unknown desc = failed to
exec in container: failed to start exec
&quot;a80d33b5b2046b8e606ed622da7085013a725&quot;: OCI runtime exec failed: exec
failed: container_linux.go:380: starting container process caused:
exec: &quot;curl http://localhost:5001/checkhealth/&quot;: stat curl
http://localhost:5001/checkhealth/</p>
</blockquote>
<p>Can someone let me know whether this is correct way to provide command to V1ExecAction. Its metadata implementation in K8s.Models showing that V1ExecAction take command in List:</p>
<pre><code>    #region Assembly KubernetesClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a0f90e8c9af122d

using Newtonsoft.Json;
using System.Collections.Generic;

namespace k8s.Models
{
    //
    // Summary:
    //     ExecAction describes a &quot;run in container&quot; action.
    public class V1ExecAction
    {
        //
        // Summary:
        //     Initializes a new instance of the V1ExecAction class.
        public V1ExecAction();
        //
        // Summary:
        //     Initializes a new instance of the V1ExecAction class.
        //
        // Parameters:
        //   command:
        //     Command is the command line to execute inside the container, the working directory
        //     for the command is root ('/') in the container's filesystem. The command is simply
        //     exec'd, it is not run inside a shell, so traditional shell instructions ('|',
        //     etc) won't work. To use a shell, you need to explicitly call out to that shell.
        //     Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
        public V1ExecAction(IList&lt;string&gt; command = null);

        //
        // Summary:
        //     Gets or sets command is the command line to execute inside the container, the
        //     working directory for the command is root ('/') in the container's filesystem.
        //     The command is simply exec'd, it is not run inside a shell, so traditional shell
        //     instructions ('|', etc) won't work. To use a shell, you need to explicitly call
 

       //out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
         [JsonProperty(PropertyName = &quot;command&quot;)]
      public IList&lt;string&gt; Command { get; set; }
  } }
</code></pre>

<kubernetes><dotnet>
Liveness Probe through C# code giving error
solveit
# Liveness Probe through C# code giving error

(Asked by: username_0 on 2021-06-02)

I am trying to implement liveness probe through C# code (.Net core framework). I simply want to run a curl command inside container like this .  Below is the code snippet using kubernetesClient:
IList command = new List();
V1Probe livnessconfig = null;
command.Add("curl http://localhost:5001/checkhealth/");
V1ExecAction execommand = new V1ExecAction(command);
livnessconfig = new V1Probe { Exec = execommand, InitialDelaySeconds = 10, PeriodSeconds = 10, TimeoutSeconds = 5, FailureThreshold = 3 };

But getting this error in pod description:

Liveness probe errored: rpc error: code = Unknown desc = failed to
exec in container: failed to start exec
"a80d33b5b2046b8e606ed622da7085013a725": OCI runtime exec failed: exec
failed: container_linux.go:380: starting container process caused:
exec: "curl http://localhost:5001/checkhealth/": stat curl
http://localhost:5001/checkhealth/

Can someone let me know whether this is correct way to provide command to V1ExecAction. Its metadata implementation in K8s.Models showing that V1ExecAction take command in List:
    #region Assembly KubernetesClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a0f90e8c9af122d

using Newtonsoft.Json;
using System.Collections.Generic;

namespace k8s.Models
{
    //
    // Summary:
    //     ExecAction describes a "run in container" action.
    public class V1ExecAction
    {
        //
        // Summary:
        //     Initializes a new instance of the V1ExecAction class.
        public V1ExecAction();
        //
        // Summary:
        //     Initializes a new instance of the V1ExecAction class.
        //
        // Parameters:
        //   command:
        //     Command is the command line to execute inside the container, the working directory
        //     for the command is root ('/') in the container's filesystem. The command is simply
        //     exec'd, it is not run inside a shell, so traditional shell instructions ('|',
        //     etc) won't work. To use a shell, you need to explicitly call out to that shell.
        //     Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
        public V1ExecAction(IList command = null);

        //
        // Summary:
        //     Gets or sets command is the command line to execute inside the container, the
        //     working directory for the command is root ('/') in the container's filesystem.
        //     The command is simply exec'd, it is not run inside a shell, so traditional shell
        //     instructions ('|', etc) won't work. To use a shell, you need to explicitly call
 

       //out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
         [JsonProperty(PropertyName = "command")]
      public IList Command { get; set; }
  } }

**Tags:** kubernetes, dotnet


---

## 1 answers

### Answer by username_1 on 2021-06-03. Score: 1 | Accepted answer

You need to provide commands in list. Something like below:
V1ExecAction execommand = new V1ExecAction("curl", "http://localhost:5001/checkhealth/");

Since you already an endpoint for healthcheck, you should use V1HTTPGetAction instead of V1ExecAction. In your case, V1ExecAction will always give exit status as 0 and thus liveliness check won't be correct if your app throws any errors or down.

> **Comments:**
> **username_0**: the same thing if I have to do using V1HTTPGetAction, then bellow is sufficient ? : ```V1HTTPGetAction execommand = new V1HTTPGetAction("http://localhost:5001/checkhealth/"); livnessconfig = new V1Probe { HttpGet= execommand, InitialDelaySeconds = 10, PeriodSeconds = 10, TimeoutSeconds = 5, FailureThreshold = 3 }; ```  

---

