Shawn Varughese
Shawn Varughese

Reputation: 500

How to make deployment restart if another pod restarts

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?

Upvotes: 5

Views: 3445

Answers (3)

ravi.zombie
ravi.zombie

Reputation: 1570

Several different way of triggering a reload

  1. The Reloader Controller can be used and configured accordingly if they both use same configmaps/secrets. Or it can also be configured to reload even without using the secrets but the deployment spec is annotated with the right ConfigMap or Secrets name.

    kind: Deployment metadata: annotations: configmap.reloader.stakater.com/reload: "foo-configmap,bar-configmap,baz-configmap" spec: template: metadata:

  2. Use Liveness probe to probe the other deployment/service endpoint and reload as mentioned above.

Upvotes: 0

Rico
Rico

Reputation: 61669

Yes, you can use a liveness probe 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 TCP connect to your Mongo Pod/StatefulSet when Mongo crashes (Maybe check every second)

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

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

Upvotes: 2

Swiss
Swiss

Reputation: 5819

Unfortunately, there's no easy way to do this within Kubernetes directly, as Kubernetes has no concept of dependencies between resources.

The best place to handle this is within the web server pod itself.

The ideal solution is to update the application to retry the connection on a failure.

A less ideal solution would be to have a side-car container that just polls the database and causes a failure if the database goes down, which should cause Kubernetes to restart the pod.

Upvotes: 0

Related Questions