I have configured a liveness probe for my Redis instances that makes sure that the Redis is able to retrieve keys for it to be able to be called ‘alive’.
livenessProbe:
initialDelaySeconds: 20
periodSeconds: 10
exec:
command:
{{- include "liveness_probe" . | nindent 16 }}
_liveness.tpl
{{/* Liveness probe script. */}}
{{- define "liveness_probe" -}}
- "redis-cli"
- "set"
- "liveness_test_key"
- ""SUCCESS""
- "&&"
- "redis-cli"
- "get"
- "liveness_test_key"
- "|"
- "awk"
- "'$1 != "SUCCESS" {exit 1}'"
{{- end }}
The pod is able to start after doing the change. However, I would like to make sure that the probe is working as expected. For that I just added a delete command before the get command.
{{/* Liveness probe script. */}}
{{- define "liveness_probe" -}}
- "redis-cli"
- "set"
- "liveness_test_key"
- ""SUCCESS""
- "&&"
- "redis-cli"
- "del"
- "liveness_test_key"
- "&&"
- "redis-cli"
- "get"
- "liveness_test_key"
- "|"
- "awk"
- "'$1 != "SUCCESS" {exit 1}'"
{{- end }}
I get the expected exit codes when I execute this command directly in my command prompt.
But the thing is that my pod is still able to start.
Is the liveness probe command I am using okay? If so, how do I verify this?
2
Answers
I think you’re confusing
livenessProbe
withreadinessProbe
. livenessProbe tells kubernetes to restart your pod if your command returns a non-zero exit code, this is executed after the period specified ininitialDelaySeconds: 20
Whereas
readinessProbe
is what decides whether a pod is inReady
state to accept traffict or not.They can also be used together if you need so.
Please check this page from kubernetes documentation where they explain
livenessProbe
,readinessProbe
andstartupProbe
Try this for your liveness probe it is working fine and you can try the same in readinessProbe:
You will need to edit these values in your template