<p>I wonder if there is a way to have a deployment stop recreating new pods, when those failed multiple times. In other, given that we can't for instance have a restartPolicy never in a pod template of a Deployment, i am wondering, how can i consider a service failed and have in a stopped state. </p>

<p>We have a use case, where imperatively need to have kubernetes interrupt a deployment that have all his pods constantly failing. </p>

<p>In my case I had a deployment that was in a fail and restart loop where the pod and its logs didn't stay around long enough for me to work out what had gone wrong.</p>
<p>As a workaround I temporarily changed the start up command so that even if the intended start up command failed the pod would be kept alive.  This allowed me to review the logs and remote into the container to work out what the issue was (I was using Kubernetes dashboard to view logs and remote into the machine).</p>
<p>Here is a simplistic example, imagine your deployment contains something like this (only key parts shown).</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
       containers:
        - name: ...
          image: ...
          imagePullPolicy: ...
          ports:
            - name: http
              containerPort: ...
              protocol: TCP
          command:     
            - '/bin/sh'
            - '-c'
            - &quot;(echo 'Starting up...' &amp;&amp; exit 1 &amp;&amp; tail -f /dev/null) || (echo 'Startup failed.' &amp;&amp; tail -f /dev/null)&quot;
          ....
</code></pre>
<p>I have bash shell installed in my docker container.  What happens here is it attempts to do everything in the brackets before the <strong>double pipe &quot;||&quot;</strong> and if that fails it will run everything after the double pipe.  So in the example case, &quot;<em>Starting up</em>&quot; will display, it will immediately &quot;exit 1&quot; which causes commands after the &quot;||&quot; to be run -  &quot;<em>Startup failed.</em>&quot; and a command to keep the container running.  I can then review the logs and remote in to run additional checks.</p>
