<p>I have this kind of deployment</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-name
  labels:
    key: value
spec:
  replicas: 1
  selector:
    matchLabels:
      key: value
  template:
    metadata:
      key: value
    spec:
      serviceAccountName: air-run-sa
      containers:
        - name: deployment-main
          image: deployment-image-here
          imagePullPolicy: Always
          ports:
            - name: http
              containerPort: 5000
              protocol: TCP
        - name: deployment-poll
          image: alpine:3.9
          imagePullPolicy: IfNotPresent
          command: [ &quot;/bin/sh&quot; ]
          args:
            - /scripts/user-deployment-poll.sh
# --- snip ---
</code></pre>
<p>The pod contains two containers- <code>deployment-main</code> and <code>deployment-poll</code>. The <code>deployment-main</code> is a web server and <code>deployment-poll</code> container runs a bash script <code>user-deployment-poll.sh</code> provided to by a config map (not shown here and is irrelevant). The script runs to completion and exists successfully, so is the container <code>deployment-poll</code>. As soon as <code>deployment-poll</code> is terminated, the pod is restarted, and it happens multiple times. I don't want the pod to restart after <code>deployment-poll</code> is completed.</p>
<p>This is output of <code>kubectl describe pod &lt;pod-id&gt;</code>-</p>
<pre><code># --- snip ---
Containers:
  deployment-main:
    Container ID:   docker://ef230d6465c9bc70f07ed90822e573c27ff83ceaeb24439edba27838ce45b81e
    Image:          k8s-registry:31320/my-project-image:19
    Image ID:       docker-pullable://k8s-registry:31320/my-project-image@sha256:f767dce7f405c232e88b599a48bd1fe612db6c1465e805b04c08a093d4fd618e
    Port:           5000/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Thu, 08 Apr 2021 15:41:05 +0530
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from air-run-sa-token-zp8dk (ro)
  deployment-poll:
    Container ID:  docker://31aa899b6cdf83d45933bffca660564f93de6018af7d28fbdb55fe4c63c7b589
    Image:         alpine:3.9
    Image ID:      docker-pullable://alpine@sha256:414e0518bb9228d35e4cd5165567fb91d26c6a214e9c95899e1e056fcd349011
    Port:          &lt;none&gt;
    Host Port:     &lt;none&gt;
    Command:
      /bin/sh
    Args:
      /scripts/user-deployment-poll.sh
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 08 Apr 2021 15:43:47 +0530
      Finished:     Thu, 08 Apr 2021 15:44:04 +0530
    Ready:          False
    Restart Count:  4
    Environment:
      DEPLOYMENT_NAME:           my-project-19-deployment
      SERVICE_ACCOUNT_USERNAME:  &lt;set to the key 'username' in secret 'air-run-service-account-basic-auth'&gt;  Optional: false
      SERVICE_ACCOUNT_PASSWORD:  &lt;set to the key 'password' in secret 'air-run-service-account-basic-auth'&gt;  Optional: false
# --- snip ---
</code></pre>
<p>It cleary shows that <code>deployment-poll</code> is completed and terminated. It is currently in <code>Waiting</code> state due to <code>CrashLoopBackOff</code>.</p>
<h3>Edit</h3>
<p>The <code>deployment-poll</code> container checks the status of <code>deployment-main</code> container. As soon as <code>deployment-main</code> reaches a particular state, <code>deployment-poll</code> calls a service on the cluster notifying that the pod is ok and then it terminates. In other words, both the containers should start at the same time. In the case of init containers, the main container will be run after init container completes.</p>

<p>That is an expected behavior as the <code>Deployment</code> controller ensures that the <code>replicas</code> number of pods defined in its <code>spec</code> is always in the <code>Ready</code> state. Failing which, it will try to restart the
failing containers using the <code>Backoff</code> algorithm.</p>
<p>You could make use of <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer"><code>Init-containers</code></a> that does the job of setting up things before the main container starts.</p>
<hr />
<p>Based on the update, I am afraid the <code>Deployment</code> strategy will not work for your case. You should instead consider creating a separate <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer"><code>Job</code></a> resource with the logic of polling the application running in the <code>Deployment</code> and do the necessary one time job.</p>
