<p>We're using a >1.8 version of k8s on gcloud. Unfortunately EventStore stops pushing data until it is rebooted. Thus we'd like to run <code>kubectl --namespace=$NAMESPACE delete pod eventstore-0</code> every 6 hours. Thus we have a cron job like:</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: eventstore-restart
spec:
  # Run every full hour, 15 past, 30 past, 45 past every other time-unit.
  schedule: "0,15,30,45 * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 5
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: eventstore-restart
            image: eu.gcr.io/$PROJECT_ID/kubectl:latest
            imagePullPolicy: Always
            command: [ "/bin/sh", "-c" ]
            args:
            - 'set -x; kubectl --namespace=$NAMESPACE get pods
               | grep -ho "eventstore-\d+"
               | xargs -n 1 -I {} kubectl --namespace=$NAMESPACE delete pod {}'
            env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          restartPolicy: OnFailure
          serviceAccount: restart-eventstore
</code></pre>

<p>However, this seems to expand to <code>kubectl get pods ...</code>, piped with <code>| { ... }</code>, which causes <code>"/bin/sh: syntax error: unexpected end of file (expecting "}")</code> to fail the script.</p>

<p><strong>How do I write the command to delete a pod on a schedule</strong>?</p>

Henrik
<p>I would do this:</p>

<pre><code>kubectl delete po $(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep eventstore) -n $NAMESPACE
</code></pre>

<p>or (your way)</p>

<pre><code>kubectl get pods -n $NAMESPACE -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep eventstore | xargs -n 1 -I {} kubectl delete po {}
</code></pre>

<p>Now, if you know you want to delete pod "eventstore-0", why to not do directly <code>kubectl delete pod eventstore-0</code>?</p>
