<p>We have defined K8s liveness and readiness probes in our <strong>deployment</strong> resource (we have defied there liveness...), we need with <code>client-go</code> lib to access this liveness probe, how can we do that?</p>
<p>I've tried it with the <code>client-go</code> lib</p>
<p><a href="https://github.com/kubernetes/client-go" rel="nofollow noreferrer">https://github.com/kubernetes/client-go</a></p>
<p>as follows:</p>
<pre><code>client.Discovery().RESTClient().Get()
</code></pre>
<p>I've also tried to play around with the go library but did not find any <strong>deployment</strong> property on <code>client.CoreV1()</code>. However I do find <code>service</code> <code>pod</code> etc. What am I missing here?</p>
<p><code>PodList, err := client.CoreV1().Pods(&quot;mynamespace&quot;).List(metav1.ListOptions{LabelSelector: &quot;run=liveness-app&quot;})</code></p>
<p>At the end I need to get the pod liveness status according to the liveness probe which is defined in the deployment. I mean <strong>live or dead</strong></p>

PJEM
<p>How to do this depends on what you want to do.</p>
<h2>Deployment</h2>
<p>The <code>Deployment</code> contains a PodTemplate, that is used for creating each replica.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myapp
  name: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: myimage
        name: myapp
        livenessProbe:
          # your desired liveness check
</code></pre>
<p>You can get the desired PodTemplate from deployments using client-go</p>
<p>For example:</p>
<pre class="lang-golang prettyprint-override"><code>clientset := kubernetes.NewForConfigOrDie(config)
deploymentClient := clientset.AppsV1().Deployments(&quot;mynamespace&quot;)
deployment, err := deploymentClient.Get(&quot;myapp&quot;, metav1.GetOptions{})

for _, container := range deployment.Spec.Template.Spec.Containers {
    container.LivenessProbe // add your logic
}
</code></pre>
<p><strong>Note:</strong> The <code>Deployment</code> only contains the desired PodTemplate, so to look at any status, you have to look at the created Pods.</p>
<h2>Pods</h2>
<p>You can list the Pods created from the deployment by using the same labels as in the <em>selector</em> of the <code>Deployment</code>.</p>
<p>Example list of Pods:</p>
<pre class="lang-golang prettyprint-override"><code>pods, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{
    LabelSelector: &quot;app=myapp&quot;,
})

// check the status for the pods - to see Probe status
for _, pod := range pods.Items {
    pod.Status.Conditions // use your custom logic here

    for _, container := range pod.Status.ContainerStatuses {
        container.RestartCount // use this number in your logic
    }
}
</code></pre>
<p>The <code>Status</code> part of a <code>Pod</code> contain <code>conditions:</code> with some <code>Probe</code>-information and <code>containerStatuses:</code> with <code>restartCount:</code>, also illustrated in the Go example above. Use your custom logic to use this information.</p>
<p>A Pod is restarted whenever the <em>livenessProbe</em> fails.</p>
<p>Example of a <code>Pod Status</code></p>
<pre class="lang-yaml prettyprint-override"><code>status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: &quot;2020-09-15T07:17:25Z&quot;
    status: &quot;True&quot;
    type: Initialized
  containerStatuses:
  - containerID: docker://25b28170c8cec18ca3af0e9c792620a3edaf36aed02849d08c56b78610dec31b
    image: myimage
    imageID: docker-pullable://myimage@sha256:a432251b2674d24858f72b1392033e0d7a79786425555714d8e9a656505fa08c
    name: myapp
    restartCount: 0
</code></pre>
