<p>we are facing issue while trying to set up <code>activeDeadlineSeconds</code> on Deployment. While we see at kubectl explain, according to that; it is a valid parameter on deployment. Please refer to this image:</p>

<p><a href="https://i.stack.imgur.com/0rY3r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0rY3r.png" alt="enter image description here"></a></p>

<p>Now, when we try to set same parameter to deployment; it say's this is invalid. Please refer to image below:</p>

<p><a href="https://i.stack.imgur.com/lgBGE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lgBGE.png" alt="enter image description here"></a></p>

<p>Please let us know, if we are doing something wrong here. You can use following yaml to do quick experiments:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: test
  name: test
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
</code></pre>

<p>we are trying this because in our case there is an init-container which sometimes hangs, because <code>activeDeadlineSeconds</code> includes init containers too; <code>progressdeadlineseconds</code> doesn't include init containers</p>

<p>Is there an alternative to this?</p>

Prateek Jain
<blockquote>
  <p>Is there an alternative to this?</p>
</blockquote>

<p>It's a pretty simple linux task that could be solved using <a href="http://man7.org/linux/man-pages/man1/timeout.1.html" rel="nofollow noreferrer"><code>timeout</code></a> or <a href="https://devel.ringlet.net/sysutils/timelimit/" rel="nofollow noreferrer"><code>timelimit</code></a> binary.</p>

<pre><code>$ timeout -k 1 5 bash -c "while true ; do sleep 1 &amp;&amp; echo 1 ; done" || echo
# the above task will be terminated in 5 secs or killed in 6 secs.

# timeout [OPTION] DURATION COMMAND [ARG]...
# -k, --kill-after=DURATION also send a KILL signal if COMMAND is still running
    this long after the initial signal was sent (not available on some containers)
# DURATION is a floating point number with an optional suffix: 's' for
#   seconds (the default), 'm' for minutes, 'h' for hours or 'd' for
#   days.  A duration of 0 disables the associated timeout.
# the above task will be terminated in 5 secs or killed in 6 secs.


$ timelimit -t 5 -T 1 bash -c "while true ; do sleep 1 &amp;&amp; echo 1 ; done" || exit 0
# the above task will be terminated in 5 secs or killed in 6 secs.

# -t 5 - five seconds before sending SIGTERM to the process  
# -T 1 - one second after SIGTERM was sent and before sending SIGKILL
</code></pre>

<p>Just specify it in the <code>InitContainer</code> command to stop the task after some reasonable time.  </p>

<p>To make the <code>InitContainer</code> think that the command is completed successfully even if it was terminated, add <code>|| echo</code> or <code>|| exit 0</code> to the end of the command as it shown in the example above. </p>

<p><code>timeout</code> is present in the system by default (checked on busybox, ubuntu, centos, alpine), but <code>timelimit</code> isn't and could be installed by appropriate packet manager. For ex.:</p>

<pre><code>$ apt-cache search timelimit
timelimit  - simple utility to limit a process's absolute execution time

$ apt-get -y install timelimit
</code></pre>

<p>You can find other ways to kill a process using bash commands only:</p>

<ul>
<li><a href="https://superuser.com/questions/153735/kill-process-after-its-been-allowed-to-run-for-some-time">Kill process after it's been allowed to run for some time</a></li>
</ul>
