<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>

Patrick
<p>If you want to run the pod only once (stop the lifecycle as soon as the code/training is done), then you have to change the restartPolicy to Never or OnFailure in your pod yaml definition file.</p>
<pre><code>containers:
  - name: my-custom-container
    image: gcr.io/xyz/object-classification:gpu
    args:
      {I put my container arguments here}
  restartPolicy: Never
</code></pre>
<p><strong>Always</strong> means that the container will be restarted even if it exited with a zero exit code (i.e. successfully). This is useful when you don't care why the container exited, you just want to make sure that it is always running (e.g. a web server). This is the default.</p>
<p><strong>OnFailure</strong> means that the container will only be restarted if it exited with a non-zero exit code (i.e. something went wrong). This is useful when you want accomplish a certain task with the pod, and ensure that it completes successfully - if it doesn't it will be restarted until it does.</p>
<p><strong>Never</strong> means that the container will not be restarted regardless of why it exited.</p>
<p>Now, if you want to run the pod only once multiple times the best approach to go is with Kubernetes CronJobs/Jobs as mentioned by Harsh. That would be the best approach in this case.</p>
