Specify scheduling order of a Kubernetes DaemonSet

5/20/2018

I have Consul running in my cluster and each node runs a consul-agent as a DaemonSet. I also have other DaemonSets that interact with Consul and therefore require a consul-agent to be running in order to communicate with the Consul servers.

My problem is, if my DaemonSet is started before the consul-agent, the application will error as it cannot connect to Consul and subsequently get restarted.

I also notice the same problem with other DaemonSets, e.g Weave, as it requires kube-proxy and kube-dns. If Weave is started first, it will constantly restart until the kube services are ready.

I know I could add retry logic to my application, but I was wondering if it was possible to specify the order in which DaemonSets are scheduled?

-- syscll
daemonset
kubernetes
scheduler

2 Answers

5/20/2018

Kubernetes itself does not provide a way to specific dependencies between pods / deployments / services (e.g. "start pod A only if service B is available" or "start pod A after pod B").

The currect approach (based on what I found while researching this) seems to be retry logic or an init container. To quote the docs:

They run to completion before any app Containers start, whereas app Containers run in parallel, so Init Containers provide an easy way to block or delay the startup of app Containers until some set of preconditions are met.

This means you can either add retry logic to your application (which I would recommend as it might help you in different situations such as a short service outage) our you can use an init container that polls a health endpoint via the Kubernetes service name until it gets a satisfying response.

-- embik
Source: StackOverflow

5/20/2018

retry logic is preferred over startup dependency ordering, since it handles both the initial bringup case and recovery from post-start outages

-- Jordan Liggitt
Source: StackOverflow