skip to Main Content

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


  1. I think you’re confusing livenessProbewith readinessProbe. livenessProbe tells kubernetes to restart your pod if your command returns a non-zero exit code, this is executed after the period specified in initialDelaySeconds: 20

    Whereas readinessProbe is what decides whether a pod is in Ready state to accept traffict or not.

      readinessProbe:
        initialDelaySeconds: 20
        periodSeconds: 10
        exec:
          command:
            {{- include "liveness_probe" . | nindent 16 }}
    

    They can also be used together if you need so.

    Please check this page from kubernetes documentation where they explain livenessProbe, readinessProbe and startupProbe

    Login or Signup to reply.
  2. Try this for your liveness probe it is working fine and you can try the same in readinessProbe:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      creationTimestamp: null
      labels:
        app: redis
      name: redis
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: redis
      strategy: {}
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: redis
        spec:
          containers:
          - image: redis
            name: redis
            livenessProbe:
              exec:
                command:
                - sh
                - -c
                - |            
                    #!/usr/bin/env bash -e
                    #export REDISCLI_AUTH="$REDIS_PASSWORD"
    
                    set_response=$(
                      redis-cli set liveness_test_key "SUCCESS"
                    )
    
                    del_response=$(
                        redis-cli del liveness_test_key
                    )
    
                    response=$(
                      redis-cli get liveness_test_key
                    )
    
                    if [ "$response" != "SUCCESS" ] ; then
                      echo "Unable to get keys, something is wrong"
                      exit 1
                    fi               
    
              initialDelaySeconds: 5
              periodSeconds: 5
              
    status: {}
    
    

    You will need to edit these values in your template

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search