Search code examples
kubernetescontainers

Kubernetes - waiting on Oracle DB container


Apologies for a basic question. I have a simple Kubernetes deployment where I have 3 containers (each in their own pod) deployed to a Kubernetes cluster.

The RESTapi container is dependent upon the OracleDB container starting. However, the OracleDB container takes a while to startup and by that time the RESTapi container has restarted a number of times due to not being able to connect and ends up in a Backoff state.

Is there a more elegant solution for this?

I’ve also noticed that when the RESTapi container goes into the Backoff state it stops retrying?


Solution

  • This is a community wiki answer posted for better visibility. Feel free to expand it.

    The best approach in this case is to improve your “RESTapi” application to provide a more reliable and fault-tolerant service that will allow it reconnect to the database anyway.

    From Kubernetes production best practices:

    When the app starts, it shouldn't crash because a dependency such as a database isn't ready.

    Instead, the app should keep retrying to connect to the database until it succeeds.

    Kubernetes expects that application components can be started in any order.

    In other case you can use solution with Init Containers.

    You can look at this question on stackoverflow, which is just one of many others about the practical use of Init Containers for the case described.