I have a question regarding Kubernetes Liveness/Readiness probes configuration.
I have an application developed in netCore 3.1 that at this moment, in production env (version 1.0.0), doesn't have configured health checks. I have implemented the health 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?
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).
Here I post an example of my actual deployment yml:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: "#{tenant}#-test-app"
name: "#{tenant}#-test-app"
labels:
app: "#{tenant}#-test-app"
product: "#{tenant}#-test-app"
app.kubernetes.io/name: "#{tenant}#-test-app"
app.kubernetes.io/version: "#{server_image_version}#"
app.kubernetes.io/component: "test-app"
app.kubernetes.io/part-of: "#{tenant}#-test-app"
app.kubernetes.io/managed-by: "#{managed_by}#"
spec:
selector:
matchLabels:
app: "#{tenant}#-test-app"
template:
metadata:
labels:
app: "#{tenant}#-test-app"
spec:
containers:
- name: "#{tenant}#-test-app"
image: mycontainerregistryurl/test-app:#{server_image_version}#
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: "#{tenant}#-test-app-variables-config"
env:
- name: DD_AGENT_HOST
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: DD_SERVICE_NAME
value: "#{tenant}#-test-app"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- NET_RAW
imagePullSecrets:
- name: test-registries
server_image_version variable could be used to identify if I have to perform an health check or not.
Thanks in advance, Dave.
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 .
env:
- name: version
value: v2
livenessProbe:
exec:
command:
- /bin/bash
- -exc
- |
set +x
echo "running below scripts"
if [[ $version -eq "v1" ]]; then
echo "Running script or command for version 1 "
else
echo "Running wget to check the http healthy "
wget api/v2
fi
I hope that my idea can help you to resolve your issue .