<p>I have a question regarding Kubernetes Liveness/Readiness probes configuration.</p>
<p>I have an application developed in <strong>netCore</strong> 3.1 that at this moment, in production env (version 1.0.0), doesn't have configured health checks.
I have implemented the <strong>health</strong> endpoints in the second release (version 2.0.0) but how can I manage the Kubernetes deployment template file in order to be compliant with version v1 that does not have an endpoint?</p>
<p>If I will deploy my template with probes configured, all container that runs on v1 will fail cause no endpoint are reachable.
I would like to understand if I can maintain one deployment yml file that will be compatible with v1 (without health) and v2 (with health).</p>
<p>Here I post an example of my actual deployment yml:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: &quot;#{tenant}#-test-app&quot;
  name: &quot;#{tenant}#-test-app&quot;
  labels:
    app: &quot;#{tenant}#-test-app&quot;
    product: &quot;#{tenant}#-test-app&quot;
    app.kubernetes.io/name: &quot;#{tenant}#-test-app&quot;
    app.kubernetes.io/version: &quot;#{server_image_version}#&quot;
    app.kubernetes.io/component: &quot;test-app&quot;
    app.kubernetes.io/part-of: &quot;#{tenant}#-test-app&quot;
    app.kubernetes.io/managed-by: &quot;#{managed_by}#&quot;
spec:
  selector:
    matchLabels:
      app: &quot;#{tenant}#-test-app&quot;
  template:
    metadata:
      labels:
        app: &quot;#{tenant}#-test-app&quot;
    spec:
      containers:
        - name: &quot;#{tenant}#-test-app&quot;
          image: mycontainerregistryurl/test-app:#{server_image_version}#
          ports:
            - containerPort: 80
          envFrom:
            - configMapRef:
                name: &quot;#{tenant}#-test-app-variables-config&quot;
          env:
            - name: DD_AGENT_HOST
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: DD_SERVICE_NAME
              value: &quot;#{tenant}#-test-app&quot;
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - NET_RAW
      imagePullSecrets:
        - name: test-registries

</code></pre>
<p>server_image_version variable could be used to identify if I have to perform an health check or not.</p>
<p>Thanks in advance, Dave.</p>

DavideP
<p>To check the liveness for k8s  you can use the command like that, we can define an environement variable and after that on the liveness section we can use the cammand to make an if-else to check the current version and specify what we need to execute on each section .</p>
<pre class="lang-yaml prettyprint-override"><code>env:
- name: version
  value: v2
livenessProbe:
  exec:
    command:
    - /bin/bash
    - -exc
    - |
          set +x
          echo &quot;running below scripts&quot;
          if [[ $version -eq &quot;v1&quot; ]]; then
            echo &quot;Running script or command for version 1 &quot;
          else
            echo &quot;Running wget to check the http healthy &quot;
              wget api/v2
          fi
</code></pre>
<p>I hope that my idea can help you to resolve your issue .</p>
