Conditional init container

Cluster information:

Kubernetes version: minikube 1.20
Cloud being used: baremetal
Installation method:n/a
Host OS: unix
CNI and version: ?
CRI and version: ?

Hi all, I have a basic understanding of k8s. I am tasked with something that goes a bit beyond my scope of understanding.

What I know: we can have multiple init containers. Those init containers run sequentially. Init containers run to completion.

What I would like to know: is it possible to have 2 init containers, one which does a conditional check. Lets say checks if a service or website is available. If it is available then proceed to running the second init container. If the condition is met with website or service being unavailable then the second init container is skipped, and the main app container starts.

Thank you,

There is no way to express that.

Thank you, @thockin.

You could have a semaphore the two init pods share, i.e. via a pvc? i.e. declare a persistant volumeclaim, and mount it to both pods at /var/pvc/ and then:

  - name: checksite
    command: "sh", "curl","http://whatever:80",">","/var/pvc/up"
  - name: checksite2
    command: "sh","if cat /var/pvc/up | grep -q hello ; then ; else return 0", 


  1. First have 1st pod check the site, and write output to a file if the site is up .
  2. wrap the invocation command of the second init pod in a snippet that checked wether the 1st one worked.

thanks all. We got it squared away doing the a shell script in the init container. based on the out come of that script the next step is decided.