0

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<string> command = new List<string>();
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<string> 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<string> Command { get; set; }
  } }
1

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.

1
  • 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 Jun 7 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.