Search code examples
kuberneteskubernetes-health-check

Kubernetes: Hit readinessProbe only once


I have following setting for readiness probe:

 readinessProbe:
      httpGet:
        path: /xyzapi/health
        port: 8888
      initialDelaySeconds: 30
      periodSeconds: 30
      timeoutSeconds: 30
      successThreshold: 2
      failureThreshold: 5

I want this readiness probe to be hit only once. It should fail or pass my deployment base on one try only.

I did some googling, but not much of help. Any kube expert? please help.


Solution

  • Oswin Noetzelmann's comment is spot-on. The purpose of a readiness probe is to continually check for the state of readiness. You can probably still change it so that your readiness-check script checks once and then caches that result, but it wouldn't be idiomatic use of readiness.

    Better alternatives for a one-time check are: init-containers or just using a wrapper script which wraps the actual work of your main container and performs the check you want.

    I think it is a good use case for init-containers. From the documentation, one of the common purposes of init containers is:

    They run to completion before any app Containers start, whereas app Containers run in parallel, so Init Containers provide an easy way to block or delay the startup of app Containers until some set of preconditions are met.