1

I am running into a situation where, initcontainer execution to completion has to be time bounded. Can someone tell or recommend a strategy to achieve the same? What I have tried till now:

  1. activeDeadlineSeconds - This attribute is supported on Pod but not on ReplicaSet. So, cannot use inside deployment object.

  2. killing initcontainer from inside, when timer expires. This is not working as expected, please refer to link.

  3. progressDeadlineSeconds - This doesnt take into account initcontainers.

Prateek Jain
  • 2,738
  • 4
  • 28
  • 42
  • what is the scenario? May it is possible to avoid the `initContainer` usage? – Nick May 11 '20 at 15:30
  • @Nick we are migrating an old product to k8s. Not all things are k8s compliant so, not possible to avoid init container. issue is due to some random issue in cluster, some times init container goes in hung state and deloyment gets stuck because there is no way to check if init container has stuck indefinitely. We can find other ways to achieve the same but that will make our solution uglier. For now, I have modified entrypoint script to fix this issue. – Prateek Jain May 11 '20 at 15:57

1 Answers1

0

One of the solutions could be by Adding lifecycle hooks

Pods also allow you to define two lifecycle hooks:

1: Post-start hooks: K8 docs

Remember: Until the hook completes, the container will stay in the Waiting state with the reason ContainerCreating. Because of this, the pod’s status will be Pending instead of Running. If the hook fails to run or returns a non-zero exit code, the main container will be killed.

2: Pre-stop hooks: K8 docs and pre-stop hook is executed immediately before a container is terminated.

Note:

1: These lifecycle hooks are specified per container, unlike init containers, which apply to the whole pod.

2: As their names suggest, they’re executed when the container starts and before it stops.

I hope this helps you to land you to a new approach!

Gupta
  • 8,882
  • 4
  • 49
  • 59
  • I would most probably write a ticket on github and see if they can introduce this as a feature. This particular approach doesn't help me in current scenario. I want to control initContainer itself. – Prateek Jain May 07 '20 at 15:53