<p>I have a web deployment and a mongoDB statefulset.  The web deployment connects to the mongodb but once in a while a error may occur in the mongodb and it reboots and starts up.  The connection from the web deployment to the mongodb never get restarted.  Is there a way in the web deployment.  If the mongodb pod restarts to restart the web pod as well?</p>

<p>Yes, you can use a <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-a-liveness-command" rel="nofollow noreferrer">liveness probe</a> on your application container that probes your Mongo Pod/StatefulSet. You can configure it in such a way that it fails if it fails to <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-a-tcp-liveness-probe" rel="nofollow noreferrer">TCP connect</a> to your Mongo Pod/StatefulSet when Mongo crashes (Maybe check every second)</p>

<p>Keep in mind that with this approach you will have to always start your Mongo Pod/StatefulSet first.</p>

<p>The sidecar function described in the other answer should work too, only it would take a bit more configuration.</p>
