<p>I've created a cluster on Google Kubernetes Engine :</p>
<pre><code>gcloud container clusters create training-cluster     --num-nodes=1     --zone=us-central1-a      --machine-type=&quot;n1-highmem-2&quot;     --scopes=&quot;gke-default,storage-rw&quot;
</code></pre>
<p>I get the credentials:</p>
<pre><code>gcloud container clusters get-credentials --zone us-central1-a training-cluster
</code></pre>
<p>and apply my yaml file:</p>
<pre><code>kubectl apply -f pod.yaml
</code></pre>
<p>The yaml file looks like:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: gke-training-pod
spec:
  containers:
  - name: my-custom-container
    image: gcr.io/xyz/object-classification:gpu
    args:
      {I put my container arguments here}
</code></pre>
<p>I can see in the logs that training starts and eventually reaches the end. Problem is that it restarts each time unless I delete my cluster. Is there an argument that I should add to avoid such a behavior?</p>

<p>If you are running the <strong>POD</strong> you set the <code>restartPolicy: Never</code> also</p>
<p>The spec of a Pod has a <code>restartPolicy</code> field with possible values <strong>Always</strong>, <strong>OnFailure</strong>, and <strong>Never</strong>. The default value is Always.</p>
<blockquote>
<p>The restartPolicy applies to all containers in the Pod. restartPolicy
only refers to restarts of the containers by the kubelet on the same
node. After containers in a Pod exit, the kubelet restarts them with
an exponential back-off delay (10s, 20s, 40s, …), that is capped at
five minutes. Once a container has executed for 10 minutes without any
problems, the kubelet resets the restart backoff timer for that
container.</p>
</blockquote>
<p><strong>OR else</strong></p>
<p>You can use the <strong>cronjobs</strong> or <strong>jobs</strong> in <strong>Kubernetes</strong> which will come and go once the job or container ends the <strong>process</strong>.</p>
<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/</a></p>
<p>If you can use the <strong>cronjob</strong> you can add <strong>successfulJobsHistoryLimit: 0</strong> so once your job finished it will remove that job and <strong>delete</strong> the pod from <strong>cluster</strong> also automatically :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: &quot;*/1 * * * *&quot;
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 0
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
</code></pre>
