What is the equivalent for depends_on in kubernetes What is the equivalent for depends_on in kubernetes kubernetes kubernetes

What is the equivalent for depends_on in kubernetes


That's the beauty of Docker Compose and Docker Swarm... Their simplicity.

We came across this same Kubernetes shortcoming when deploying the ELK stack.We solved it by using a side-car (initContainer), which is just another container in the same pod thats run first, and when it's complete, kubernetes automatically starts the [main] container. We made it a simple shell script that is in loop until Elasticsearch is up and running, then it exits and Kibana's container starts.

Below is an example of a side-car that waits until Grafana is ready.

Add this 'initContainer' block just above your other containers in the Pod:

spec:      initContainers:      - name: wait-for-grafana        image: darthcabs/tiny-tools:1        args:        - /bin/bash        - -c        - >          set -x;          while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://grafana:3000/login)" != "200" ]]; do             echo '.'            sleep 15;          done      containers:          .          .  (your other containers)          .          .


This was purposefully left out. The reason being is that applications should be responsible for their connect/re-connect logic for connecting to service(s) such as a database. This is outside the scope of Kubernetes.


While I don't know the direct answer to your question except this link (k8s-AppController), I don't think it's wise to use same deployment for DB and app. Because you are tightly coupling your db with app and loosing awesome k8s option to scale any one of them as needed. Further more if your db pod dies you loose your data as well.

Personally what I would do is to have a separate StatefulSet with Persistent Volume for database and Deployment for app and use Service to make sure their communication.
Yes I have to run few different commands and may need at least two separate deployment files but this way I am decoupling them and can scale them as needed. And my data is being persistent as well!